summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/google/NonConstReferences.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/google/NonConstReferences.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp b/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp
index 5667bd19502..d1bc1534c70 100644
--- a/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp
+++ b/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "NonConstReferences.h"
+#include "../utils/OptionsUtils.h"
#include "clang/AST/DeclBase.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -19,7 +20,21 @@ namespace tidy {
namespace google {
namespace runtime {
+NonConstReferences::NonConstReferences(StringRef Name,
+ ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context),
+ WhiteListTypes(
+ utils::options::parseStringList(Options.get("WhiteListTypes", ""))) {}
+
+void NonConstReferences::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "WhiteListTypes",
+ utils::options::serializeStringList(WhiteListTypes));
+}
+
void NonConstReferences::registerMatchers(MatchFinder *Finder) {
+ if (!getLangOpts().CPlusPlus)
+ return;
+
Finder->addMatcher(
parmVarDecl(
unless(isInstantiated()),
@@ -52,6 +67,15 @@ void NonConstReferences::check(const MatchFinder::MatchResult &Result) {
}
auto ReferencedType = *Result.Nodes.getNodeAs<QualType>("referenced_type");
+
+ if (std::find_if(WhiteListTypes.begin(), WhiteListTypes.end(),
+ [&](llvm::StringRef WhiteListType) {
+ return ReferencedType.getCanonicalType().getAsString(
+ Result.Context->getPrintingPolicy()) ==
+ WhiteListType;
+ }) != WhiteListTypes.end())
+ return;
+
// Don't warn on function references, they shouldn't be constant.
if (ReferencedType->isFunctionProtoType())
return;
OpenPOWER on IntegriCloud