[PATCH] D34449: [Clang-tidy] Enable constexpr definitions in headers.
Gábor Horváth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 21 07:03:12 PDT 2017
xazax.hun created this revision.
xazax.hun added a project: clang-tools-extra.
Herald added a subscriber: whisperity.
Constexpr variable definitions should be ok in headers.
https://stackoverflow.com/questions/34445336/constexpr-global-constants-in-a-header-file-and-odr
Repository:
rL LLVM
https://reviews.llvm.org/D34449
Files:
clang-tidy/misc/DefinitionsInHeadersCheck.cpp
test/clang-tidy/misc-definitions-in-headers.hpp
Index: test/clang-tidy/misc-definitions-in-headers.hpp
===================================================================
--- test/clang-tidy/misc-definitions-in-headers.hpp
+++ test/clang-tidy/misc-definitions-in-headers.hpp
@@ -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++1z
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,7 @@
int CD<T, int>::f() { // OK: partial template specialization.
return 0;
}
+
+class CE {
+ constexpr static int i = 5; // OK: constexpr definition.
+};
Index: clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===================================================================
--- clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -54,7 +54,7 @@
return;
auto DefinitionMatcher =
anyOf(functionDecl(isDefinition(), unless(isDeleted())),
- varDecl(isDefinition()));
+ varDecl(isDefinition(), unless(isConstexpr())));
if (UseHeaderFileExtension) {
Finder->addMatcher(namedDecl(DefinitionMatcher,
usesHeaderFileExtension(HeaderFileExtensions))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34449.103371.patch
Type: text/x-patch
Size: 1362 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170621/37c5d1bd/attachment.bin>
More information about the cfe-commits
mailing list