Skip to content

Commit bfb43b7

Browse files
committedApr 21, 2016
[Clang-tidy] Fix for crash in modernize-raw-string-literal check
Summary: Clang-tidy modernize-raw-string-literal check crashes on run-time assert while it is evaluating compiler predefined identifiers such as - __FUNCTION__ - __func__ - __PRETTY_FUNCTION__ Check is asserting because it cannot find opening quote for such string literal. It occurs only on debug build config. I think that it would be good to prune such cases by crossing off predefined expressions - there is no need to evaluate such matches. Reviewers: LegalizeAdulthood, alexfh Subscribers: cfe-commits Patch by Marek Jenda! Differential Revision: http://reviews.llvm.org/D19331 llvm-svn: 266992
1 parent 586d93b commit bfb43b7

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
 

‎clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ void RawStringLiteralCheck::storeOptions(ClangTidyOptions::OptionMap &Options) {
108108
}
109109

110110
void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
111-
Finder->addMatcher(stringLiteral().bind("lit"), this);
111+
Finder->addMatcher(
112+
stringLiteral(unless(hasParent(predefinedExpr()))).bind("lit"), this);
112113
}
113114

114115
void RawStringLiteralCheck::check(const MatchFinder::MatchResult &Result) {

‎clang-tools-extra/test/clang-tidy/modernize-raw-string-literal.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ char const *const HexPrintable("\x40\\");
9191
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw string literal
9292
// CHECK-FIXES: {{^}}char const *const HexPrintable(R"(@\)");{{$}}
9393

94+
char const *const prettyFunction(__PRETTY_FUNCTION__);
95+
char const *const function(__FUNCTION__);
96+
char const *const func(__func__);
97+
9498
#define TRICK(arg_) #arg_
9599
char const *const MacroBody = TRICK(foo\\bar);
96100

0 commit comments

Comments
 (0)
Please sign in to comment.