[PATCH] D55409: [clang-tidy] check for using declarations not in an anonymous namespace when there exists one

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 11 10:06:48 PDT 2019


aaron.ballman added inline comments.


================
Comment at: clang-tidy/abseil/AnonymousEnclosedAliasesCheck.cpp:41
+    // to the vector containing all candidate using declarations.
+    if (AnonymousNamespaceDecl) {
+  		diag(MatchedUsingDecl->getLocation(),
----------------
Naysh wrote:
> aaron.ballman wrote:
> > I don't think this logic works in practice because there's no way to determine that the anonymous namespace is even a candidate for putting the using declaration into it. Consider a common scenario where there's an anonymous namespace declared in a header file (like an STL header outside of the user's control), and a using declaration inside of an implementation file. Just because the STL declared an anonymous namespace doesn't mean that the user could have put their using declaration in it.
> If we altered the check to only apply to anonymous namespaces and using declarations at namespace scope (that is, we only suggest aliases be moved to anonymous namespaces when the unnamed namespace and alias are themselves inside some other namespace), would this issue be resolved? 
If they're inside the same namespace, then I think that could work, but if the namespaces are different I don't know that you can be sure the alias can be moved into the anonymous namespace.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55409/new/

https://reviews.llvm.org/D55409





More information about the cfe-commits mailing list