[PATCH] D34449: [clang-tidy] Enable constexpr definitions in headers.

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 27 02:27:39 PDT 2017


xazax.hun updated this revision to Diff 104111.
xazax.hun marked 5 inline comments as done.
xazax.hun added a comment.
Herald added a subscriber: JDevlieghere.

- Updates according to the reviews.


https://reviews.llvm.org/D34449

Files:
  clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  test/clang-tidy/misc-definitions-in-headers-1z.hpp


Index: test/clang-tidy/misc-definitions-in-headers-1z.hpp
===================================================================
--- /dev/null
+++ test/clang-tidy/misc-definitions-in-headers-1z.hpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s misc-definitions-in-headers %t -- -- -std=c++1z
+
+// Inline variables should be ok.
+class CE {
+  constexpr static int i = 5;
+};
+
+inline int i = 5;
+
+constexpr int a = 1;
+
+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]
Index: clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===================================================================
--- clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -139,6 +139,9 @@
     // 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; "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34449.104111.patch
Type: text/x-patch
Size: 1135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170627/8291a33a/attachment-0001.bin>


More information about the cfe-commits mailing list