forked from OSchip/llvm-project
Fix false positive on anonymous namespaces in headers.
Summary: Anynoumous namespaces inject a using directive into the AST to import the names into the containing namespace. We should not have them in headers, but there is another warning for that. Reviewers: djasper Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D8443 llvm-svn: 233087
This commit is contained in:
parent
c676f2a8bb
commit
3199b9a8b5
|
@ -45,6 +45,16 @@ void GlobalNamesInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (const auto* UsingDirective = dyn_cast<UsingDirectiveDecl>(D)) {
|
||||
if (UsingDirective->getNominatedNamespace()->isAnonymousNamespace()) {
|
||||
// Anynoumous namespaces inject a using directive into the AST to import
|
||||
// the names into the containing namespace.
|
||||
// We should not have them in headers, but there is another warning for
|
||||
// that.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
diag(D->getLocStart(),
|
||||
"using declarations in the global namespace in headers are prohibited");
|
||||
}
|
||||
|
|
|
@ -101,6 +101,10 @@ TEST_F(GlobalNamesInHeadersCheckTest, UsingDirectives) {
|
|||
EXPECT_FALSE(runCheckOnCode("SOME_MACRO(namespace std);", "foo.h"));
|
||||
}
|
||||
|
||||
TEST_F(GlobalNamesInHeadersCheckTest, RegressionAnonymousNamespace) {
|
||||
EXPECT_FALSE(runCheckOnCode("namespace {}", "foo.h"));
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
||||
|
|
Loading…
Reference in New Issue