diff --git a/build/clang-plugin/CustomMatchers.h b/build/clang-plugin/CustomMatchers.h index 54bb0d02dd2e..5a4f8474ec2f 100644 --- a/build/clang-plugin/CustomMatchers.h +++ b/build/clang-plugin/CustomMatchers.h @@ -142,6 +142,18 @@ AST_MATCHER(CallExpr, isInWhitelistForFopenUsage) { return llvm::sys::path::rbegin(FileName)->equals(Whitelist); } +// This matcher will match any node in "gtest-port.h". This file is third-party +// code (and thus exempt from our rules prohibiting ), but it's +// linked into $OBJDIR, so inThirdPartyPath() misclassifies it. +AST_MATCHER(Stmt, isAllowedToUseLocaleSpecificFunctions) { + static const char AllowedFile[] = "gtest-port.h"; + SourceLocation Loc = Node.getBeginLoc(); + StringRef FileName = + getFilename(Finder->getASTContext().getSourceManager(), Loc); + + return llvm::sys::path::rbegin(FileName)->equals(AllowedFile); +} + /// This matcher will match a list of files. These files contain /// known NaN-testing expressions which we would like to whitelist. AST_MATCHER(BinaryOperator, isInWhitelistForNaNExpr) { diff --git a/build/clang-plugin/NoLocaleSpecificChecker.cpp b/build/clang-plugin/NoLocaleSpecificChecker.cpp index 06d534f9ca55..a3543602eb22 100644 --- a/build/clang-plugin/NoLocaleSpecificChecker.cpp +++ b/build/clang-plugin/NoLocaleSpecificChecker.cpp @@ -57,11 +57,9 @@ void NoLocaleSpecificChecker::registerMatchers(MatchFinder *AstMatcher) { hasConstCharPtrParam(1), hasIntegerParam(2)), hasNameAndIntegerParam("tolower"), - hasNameAndIntegerParam("toupper") - ) - ))) - ) - ).bind("id"), + hasNameAndIntegerParam("toupper"))))), + unless(isAllowedToUseLocaleSpecificFunctions()))) + .bind("id"), this); }