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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 4 05:39:58 PDT 2016

aaron.ballman added inline comments.

Comment at: clang-tidy/misc/GlobalNamespaceCheck.cpp:72
@@ +71,3 @@
+                                   "move it into a namespace or give it "
+                                   "internal linkage to avoid ODR conflicts")
+      << MatchedDecl;
ODR violations instead of ODR conflicts?

Comment at: docs/clang-tidy/checks/misc-global-namespace.rst:7
@@ +6,2 @@
+Finds definitions in the global namespace. Those definitions are prone to ODR
violations instead of conflicts. Also, expanding the documentation a bit more would be useful -- not everyone understands what an ODR violation is, why it would be bad, etc. It can even be as simple as adding in an external link for more info.

Comment at: test/clang-tidy/misc-global-namespace.cpp:13
@@ +12,3 @@
+extern "C" void h() {}
Add a case for `extern "C" int i;`?

Also, isn't this a definition with external linkage in C++ (or is it only in C)? `extern int i = 30;` Assuming it's a definition, should this also trigger the diagnostic?



More information about the cfe-commits mailing list