[PATCH] D74468: [clang-tidy] No misc-definitions-in-headers warning on C++14 variable templates.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 12 01:02:20 PST 2020
hokein created this revision.
hokein added a reviewer: gribozavr2.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74468
Files:
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/misc-definitions-in-headers.rst
clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers-1z.hpp
Index: clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers-1z.hpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers-1z.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers-1z.hpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-definitions-in-headers %t -- -- -std=c++1z
+// RUN: %check_clang_tidy -std=c++17-or-later %s misc-definitions-in-headers %t
class CE {
constexpr static int i = 5; // OK: inline variable definition.
@@ -8,3 +8,7 @@
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]
+
+// OK: C++14 variable template.
+template<class T>
+constexpr T pi = T(3.1415926L);
Index: clang-tools-extra/docs/clang-tidy/checks/misc-definitions-in-headers.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/checks/misc-definitions-in-headers.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc-definitions-in-headers.rst
@@ -83,6 +83,10 @@
constexpr int f10() { return 0; } // OK: constexpr function implies inline.
+ // OK: C++14 variable template is allowed.
+ template <class T>
+ constexpr T pi = T(3.1415926L);
+
Options
-------
Index: clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -134,6 +134,9 @@
DiagnosticIDs::Note)
<< FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
} else if (const auto *VD = dyn_cast<VarDecl>(ND)) {
+ // C++14 variable templates are allowed.
+ if (VD->getDescribedVarTemplate())
+ return;
// Static data members of a class template are allowed.
if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember())
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74468.244091.patch
Type: text/x-patch
Size: 2115 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200212/834f1e61/attachment.bin>
More information about the cfe-commits
mailing list