Author: Piotr Zegar
Date: 2023-10-31T06:52:40+01:00
New Revision: a396fb247e0719f56a830a9e4aab0449be7f843a

URL: 
https://github.com/llvm/llvm-project/commit/a396fb247e0719f56a830a9e4aab0449be7f843a
DIFF: 
https://github.com/llvm/llvm-project/commit/a396fb247e0719f56a830a9e4aab0449be7f843a.diff

LOG: [clang-tidy] Fix crash in modernize-use-trailing-return-type (#70709)

Resolved the crash that occurred during the use of a user-defined
C-style string literal. The fix entails checking whether the identifier
is non-empty before attempting to read its name.

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
    
clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp

Removed: 
    


################################################################################
diff  --git 
a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index b81cfbcbfd16ccc..5a456c58fb5cc53 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -103,7 +103,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor<UnqualNameVisitor> {
 
   bool VisitDeclRefExpr(DeclRefExpr *S) {
     DeclarationName Name = S->getNameInfo().getName();
-    return S->getQualifierLoc() || !Name.isIdentifier() ||
+    return S->getQualifierLoc() || Name.isEmpty() || !Name.isIdentifier() ||
            !visitUnqualName(Name.getAsIdentifierInfo()->getName());
   }
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp
index 63fe7a95fdc94ac..72fdcc01779650e 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp
@@ -98,3 +98,21 @@ struct TestDefaultOperatorB {
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use a trailing return type for 
this function [modernize-use-trailing-return-type]
   // CHECK-FIXES: {{^}}  friend auto operator<(const TestDefaultOperatorB &, 
const TestDefaultOperatorB &) noexcept -> bool = default;{{$}}
 };
+
+namespace PR69863 {
+
+template <unsigned Len>
+struct CustomCompileTimeString {
+  constexpr CustomCompileTimeString(const char (&)[Len]) noexcept {}
+};
+
+template <CustomCompileTimeString Str>
+constexpr decltype(Str) operator""__csz() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use a trailing return type for 
this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}constexpr auto operator""__csz() noexcept -> 
decltype(Str) {
+  return Str;
+}
+
+inline constexpr CustomCompileTimeString SomeString = "This line will cause a 
crash"__csz;
+
+}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to