[PATCH] D23130: [Clang-tidy] Add a check for definitions in the global namespace.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 3 16:00:49 PDT 2016


alexfh added a comment.

In https://reviews.llvm.org/D23130#505242, @bkramer wrote:

> DefinitionsInHeaders is tackling a different problem. IMO DefinitionsInHeaders is something that should be on by default everywhere, while this check for definitions in the global namespace is more of a coding style issue.


Yes, DefinitionsInHeaders is a different beast.

> GlobalNamesInHeaders is a bit of a misnomer, it looks for using declarations in headers.


The `google-global-names-in-headers` check aims to "flag global namespace pollution in header files" including declarations of classes, functions and other entities. However, "right now it only triggers on using declarations and directives", so it's basically under-implemented. The only problem, I guess, is keeping false positives under control. The check you're proposing is somewhat close. It isn't specifically limited to headers (the `google-global-names-in-headers` check can run on all files if properly configured, and we can rename it to remove the -in-headers part). And the second difference is that it is limited to definitions, but I don't yet understand, why it is important, since declarations in the global namespace (except for using declarations, typedefs, etc.) will have a corresponding definition in the global namespace. I guess, these checks, if somewhat different, may be similar enough to share some implementation.


Repository:
  rL LLVM

https://reviews.llvm.org/D23130





More information about the cfe-commits mailing list