[PATCH] D15710: [clang-tidy] Add non-inline function definition and variable definition check in header files.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 7 03:07:33 PST 2016


hokein added inline comments.

================
Comment at: docs/clang-tidy/checks/misc-definitions-in-headers.rst:21
@@ +20,3 @@
+
+   // Warning.
+   int g() {
----------------
> For the static and const declarations I can see some benefit to ignoring for now, but the unnamed namespace in a header file is sufficiently nasty that many coding guidelines explicitly forbid it because of ODR violations (it really doesn't do what users think it will do). It's especially strange that we will warn about using a *named* namespace in a header file, but not an *unnamed* namespace, which is decidedly more behaviorally strange. I would prefer to see the check catch at least unnamed namespaces, if not static or const variable declarations.

Done.

> Also, I would be interested in hearing what "a lot of such usages in Google" means in more concrete terms for static or const definitions in header files, if you're able to share those numbers. I don't foresee that changing the requirements for this patch, but I'd still be curious to know for when I work on CERT's secure coding rules.

Yes, the const/static definitions are used widely in header files. The number is  ~200,000 including third-party projects.


http://reviews.llvm.org/D15710





More information about the cfe-commits mailing list