[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
This commit is contained in:
Alexander Kornienko 2016-04-21 14:39:12 +00:00
parent 586d93bd8b
commit bfb43b7298
2 changed files with 6 additions and 1 deletions

View File

@ -108,7 +108,8 @@ void RawStringLiteralCheck::storeOptions(ClangTidyOptions::OptionMap &Options) {
}
void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(stringLiteral().bind("lit"), this);
Finder->addMatcher(
stringLiteral(unless(hasParent(predefinedExpr()))).bind("lit"), this);
}
void RawStringLiteralCheck::check(const MatchFinder::MatchResult &Result) {

View File

@ -91,6 +91,10 @@ char const *const HexPrintable("\x40\\");
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}}char const *const HexPrintable(R"(@\)");{{$}}
char const *const prettyFunction(__PRETTY_FUNCTION__);
char const *const function(__FUNCTION__);
char const *const func(__func__);
#define TRICK(arg_) #arg_
char const *const MacroBody = TRICK(foo\\bar);