Skip to content

Commit

Permalink
[clang-tidy] Fix crash in modernize-use-trailing-return-type (#70709)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
PiotrZSL committed Oct 31, 2023
1 parent 6258da1 commit a396fb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

0 comments on commit a396fb2

Please sign in to comment.