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; "
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; "
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits