summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2014-05-05 18:49:31 +0000
committerAlexander Kornienko <alexfh@google.com>2014-05-05 18:49:31 +0000
commit4aab579d0758c16b8293aa5960c0d33a38b648ae (patch)
treeaff53447f2769fe7b10656f4a556f6f32d4af6be
parent75f34c1386f6ee8e3d28f6c3f30b83d2bb7f6584 (diff)
downloadbcm5719-llvm-4aab579d0758c16b8293aa5960c0d33a38b648ae.tar.gz
bcm5719-llvm-4aab579d0758c16b8293aa5960c0d33a38b648ae.zip
Fix assertion in google-explicit-constructor check when the constructor is
defined in a macro. Summary: We shouldn't suggest replacements in macros anyway, as we can't see all usages of the macro and ensure the replacement is safe for all of them. Reviewers: klimek Reviewed By: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D3611 llvm-svn: 207987
-rw-r--r--clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp8
-rw-r--r--clang-tools-extra/unittests/clang-tidy/GoogleModuleTest.cpp9
2 files changed, 14 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index a732242f778..7119ef0d3cb 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -34,6 +34,8 @@ void ExplicitConstructorCheck::registerMatchers(MatchFinder *Finder) {
SourceRange FindToken(const SourceManager &Sources, LangOptions LangOpts,
SourceLocation StartLoc, SourceLocation EndLoc,
bool (*Pred)(const Token &)) {
+ if (StartLoc.isMacroID() || EndLoc.isMacroID())
+ return SourceRange();
FileID File = Sources.getFileID(Sources.getSpellingLoc(StartLoc));
StringRef Buf = Sources.getBufferData(File);
const char *StartChar = Sources.getCharacterData(StartLoc);
@@ -69,10 +71,10 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
SourceRange ExplicitTokenRange =
FindToken(*Result.SourceManager, Result.Context->getLangOpts(),
Ctor->getOuterLocStart(), Ctor->getLocEnd(), isKWExplicit);
+ DiagnosticBuilder Diag =
+ diag(Ctor->getLocation(), "%0 constructor declared explicit.")
+ << (Ctor->isMoveConstructor() ? "Move" : "Copy");
if (ExplicitTokenRange.isValid()) {
- DiagnosticBuilder Diag = diag(ExplicitTokenRange.getBegin(),
- "%0 constructor declared explicit.")
- << (Ctor->isMoveConstructor() ? "Move" : "Copy");
Diag << FixItHint::CreateRemoval(
CharSourceRange::getCharRange(ExplicitTokenRange));
}
diff --git a/clang-tools-extra/unittests/clang-tidy/GoogleModuleTest.cpp b/clang-tools-extra/unittests/clang-tidy/GoogleModuleTest.cpp
index d986d3bcb04..89e47407c98 100644
--- a/clang-tools-extra/unittests/clang-tidy/GoogleModuleTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/GoogleModuleTest.cpp
@@ -47,6 +47,15 @@ TEST(ExplicitConstructorCheckTest, RemoveExplicit) {
"class C { explicit/*asdf*/ C(const C&, int i = 0); };"));
}
+TEST(ExplicitConstructorCheckTest, RemoveExplicitWithMacros) {
+ EXPECT_EQ(
+ "#define A(T) class T##Bar { explicit T##Bar(const T##Bar &b) {} };\n"
+ "A(Foo);",
+ runCheckOnCode<ExplicitConstructorCheck>(
+ "#define A(T) class T##Bar { explicit T##Bar(const T##Bar &b) {} };\n"
+ "A(Foo);"));
+}
+
} // namespace test
} // namespace tidy
} // namespace clang
OpenPOWER on IntegriCloud