Skip to content

Commit 5864814

Browse files
PiotrZSLtru
authored andcommitted
[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. (cherry picked from commit a396fb2)
1 parent 9d0ca25 commit 5864814

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct UnqualNameVisitor : public RecursiveASTVisitor<UnqualNameVisitor> {
103103

104104
bool VisitDeclRefExpr(DeclRefExpr *S) {
105105
DeclarationName Name = S->getNameInfo().getName();
106-
return S->getQualifierLoc() || !Name.isIdentifier() ||
106+
return S->getQualifierLoc() || Name.isEmpty() || !Name.isIdentifier() ||
107107
!visitUnqualName(Name.getAsIdentifierInfo()->getName());
108108
}
109109

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,21 @@ struct TestDefaultOperatorB {
9898
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
9999
// CHECK-FIXES: {{^}} friend auto operator<(const TestDefaultOperatorB &, const TestDefaultOperatorB &) noexcept -> bool = default;{{$}}
100100
};
101+
102+
namespace PR69863 {
103+
104+
template <unsigned Len>
105+
struct CustomCompileTimeString {
106+
constexpr CustomCompileTimeString(const char (&)[Len]) noexcept {}
107+
};
108+
109+
template <CustomCompileTimeString Str>
110+
constexpr decltype(Str) operator""__csz() noexcept {
111+
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
112+
// CHECK-FIXES: {{^}}constexpr auto operator""__csz() noexcept -> decltype(Str) {
113+
return Str;
114+
}
115+
116+
inline constexpr CustomCompileTimeString SomeString = "This line will cause a crash"__csz;
117+
118+
}

0 commit comments

Comments
 (0)