[clang-tools-extra] r306538 - [clang-tidy] Enable inline variable definitions in headers
Gabor Horvath via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 28 05:47:35 PDT 2017
Author: xazax
Date: Wed Jun 28 05:47:35 2017
New Revision: 306538
URL: http://llvm.org/viewvc/llvm-project?rev=306538&view=rev
Log:
[clang-tidy] Enable inline variable definitions in headers
Differential Revision: https://reviews.llvm.org/D34449
Added:
clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers-1z.hpp
Modified:
clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst
clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp?rev=306538&r1=306537&r2=306538&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp Wed Jun 28 05:47:35 2017
@@ -139,6 +139,9 @@ void DefinitionsInHeadersCheck::check(co
// Ignore variable definition within function scope.
if (VD->hasLocalStorage() || VD->isStaticLocal())
return;
+ // Ignore inline variables.
+ if (VD->isInline())
+ return;
diag(VD->getLocation(),
"variable %0 defined in a header file; "
Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst?rev=306538&r1=306537&r2=306538&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst Wed Jun 28 05:47:35 2017
@@ -74,6 +74,14 @@ from multiple translation units.
template <typename T>
void B<T>::f1() {}
+ class CE {
+ constexpr static int i = 5; // OK: inline variable definition.
+ };
+
+ inline int i = 5; // OK: inline variable definition.
+
+ constexpr int k = 1; // OK: constexpr variable has internal linkage.
+
Options
-------
Added: clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers-1z.hpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers-1z.hpp?rev=306538&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers-1z.hpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers-1z.hpp Wed Jun 28 05:47:35 2017
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s misc-definitions-in-headers %t -- -- -std=c++1z
+
+class CE {
+ constexpr static int i = 5; // OK: inline variable definition.
+};
+
+inline int i = 5; // OK: inline variable definition.
+
+int b = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'b' defined in a header file; variable definitions in header files can lead to ODR violations [misc-definitions-in-headers]
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp?rev=306538&r1=306537&r2=306538&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp Wed Jun 28 05:47:35 2017
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-definitions-in-headers %t
+// RUN: %check_clang_tidy %s misc-definitions-in-headers %t -- -- -std=c++11
int f() {
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
@@ -175,3 +175,5 @@ template <typename T>
int CD<T, int>::f() { // OK: partial template specialization.
return 0;
}
+
+constexpr int k = 1; // OK: constexpr variable has internal linkage.
More information about the cfe-commits
mailing list