[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


git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266992 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexander Kornienko 2016-04-21 14:39:12 +00:00
Родитель 0543069a94
Коммит d1f3b6cd34
2 изменённых файлов: 6 добавлений и 1 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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);