<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 8, 2016 at 6:26 PM, Alexander Kornienko <span dir="ltr"><<a href="mailto:alexfh@google.com" target="_blank">alexfh@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">I don't see how -Wmissing-declarations relates to this check. None of the warnings in the MissingDeclarations group in DiagnosticSemaKinds.td seem to be anywhere close to what this check does. Am I missing something?</div></blockquote><div><br>Ah, sorry - wrong diagnostic name. Apparently it's missing-prototypes and missing-variable-declarations (close... )<br><br>If you put a function or variable definition in a header, chances are you were intending to declare it (or make it inline) & it has no prior declaration, and thus the missing-declaration warning(s) would catch it:<br><br><pre style="color:rgb(0,0,0)">func.cpp:1:6: warning: no previous prototype for function 'func' [-Wmissing-prototypes]
void func() {
^</pre> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div class="h5"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 8, 2016 at 7:53 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">This sounds sort of like the missing-declaration warning in Clang, no? (granted, it's a bit more direct & thus perhaps easier to use, but fulfills a similar purpose)</div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 8, 2016 at 8:37 AM, Alexander Kornienko via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: alexfh<br>
Date: Fri Jan 8 10:37:11 2016<br>
New Revision: 257178<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=257178&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=257178&view=rev</a><br>
Log:<br>
[clang-tidy] Add non-inline function definition and variable definition check in header files.<br>
<br>
Summary: The new check will find all functionand variable definitions which may violate cpp one definition rule in header file.<br>
<br>
Reviewers: aaron.ballman, alexfh<br>
<br>
Subscribers: aaron.ballman, cfe-commits<br>
<br>
Patch by Haojian Wu!<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D15710" rel="noreferrer" target="_blank">http://reviews.llvm.org/D15710</a><br>
<br>
Added:<br>
clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp<br>
clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.h<br>
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst<br>
clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp<br>
Modified:<br>
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt<br>
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp<br>
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst<br>
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py<br>
clang-tools-extra/trunk/test/lit.cfg<br>
<br>
Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=257178&r1=257177&r2=257178&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=257178&r1=257177&r2=257178&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)<br>
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Fri Jan 8 10:37:11 2016<br>
@@ -5,6 +5,7 @@ add_clang_library(clangTidyMiscModule<br>
AssertSideEffectCheck.cpp<br>
AssignOperatorSignatureCheck.cpp<br>
BoolPointerImplicitConversionCheck.cpp<br>
+ DefinitionsInHeadersCheck.cpp<br>
InaccurateEraseCheck.cpp<br>
InefficientAlgorithmCheck.cpp<br>
MacroParenthesesCheck.cpp<br>
<br>
Added: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp?rev=257178&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp?rev=257178&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp (added)<br>
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp Fri Jan 8 10:37:11 2016<br>
@@ -0,0 +1,126 @@<br>
+//===--- DefinitionsInHeadersCheck.cpp - clang-tidy------------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "DefinitionsInHeadersCheck.h"<br>
+#include "clang/AST/ASTContext.h"<br>
+#include "clang/ASTMatchers/ASTMatchFinder.h"<br>
+<br>
+using namespace clang::ast_matchers;<br>
+<br>
+namespace clang {<br>
+namespace tidy {<br>
+namespace misc {<br>
+<br>
+namespace {<br>
+<br>
+AST_MATCHER(NamedDecl, isHeaderFileExtension) {<br>
+ SourceManager& SM = Finder->getASTContext().getSourceManager();<br>
+ SourceLocation ExpansionLoc = SM.getExpansionLoc(Node.getLocStart());<br>
+ StringRef Filename = SM.getFilename(ExpansionLoc);<br>
+ return Filename.endswith(".h") || Filename.endswith(".hh") ||<br>
+ Filename.endswith(".hpp") || Filename.endswith(".hxx") ||<br>
+ llvm::sys::path::extension(Filename).empty();<br>
+}<br>
+<br>
+} // namespace<br>
+<br>
+DefinitionsInHeadersCheck::DefinitionsInHeadersCheck(<br>
+ StringRef Name, ClangTidyContext *Context)<br>
+ : ClangTidyCheck(Name, Context),<br>
+ UseHeaderFileExtension(Options.get("UseHeaderFileExtension", true)) {}<br>
+<br>
+void DefinitionsInHeadersCheck::storeOptions(<br>
+ ClangTidyOptions::OptionMap &Opts) {<br>
+ Options.store(Opts, "UseHeaderFileExtension", UseHeaderFileExtension);<br>
+}<br>
+<br>
+void DefinitionsInHeadersCheck::registerMatchers(MatchFinder *Finder) {<br>
+ if (UseHeaderFileExtension) {<br>
+ Finder->addMatcher(<br>
+ namedDecl(anyOf(functionDecl(isDefinition()), varDecl(isDefinition())),<br>
+ isHeaderFileExtension()).bind("name-decl"),<br>
+ this);<br>
+ } else {<br>
+ Finder->addMatcher(<br>
+ namedDecl(anyOf(functionDecl(isDefinition()), varDecl(isDefinition())),<br>
+ anyOf(isHeaderFileExtension(),<br>
+ unless(isExpansionInMainFile()))).bind("name-decl"),<br>
+ this);<br>
+ }<br>
+}<br>
+<br>
+void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {<br>
+ // C++ [basic.def.odr] p6:<br>
+ // There can be more than one definition of a class type, enumeration type,<br>
+ // inline function with external linkage, class template, non-static function<br>
+ // template, static data member of a class template, member function of a<br>
+ // class template, or template specialization for which some template<br>
+ // parameters are not specifiedin a program provided that each definition<br>
+ // appears in a different translation unit, and provided the definitions<br>
+ // satisfy the following requirements.<br>
+ const auto *ND = Result.Nodes.getNodeAs<NamedDecl>("name-decl");<br>
+ assert(ND);<br>
+<br>
+ // Internal linkage variable definitions are ignored for now:<br>
+ // const int a = 1;<br>
+ // static int b = 1;<br>
+ //<br>
+ // Although these might also cause ODR violations, we can be less certain and<br>
+ // should try to keep the false-positive rate down.<br>
+ if (ND->getLinkageInternal() == InternalLinkage)<br>
+ return;<br>
+<br>
+ if (const auto *FD = dyn_cast<FunctionDecl>(ND)) {<br>
+ // Inline functions are allowed.<br>
+ if (FD->isInlined())<br>
+ return;<br>
+ // Function templates are allowed.<br>
+ if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)<br>
+ return;<br>
+ // Function template full specialization is prohibited in header file.<br>
+ if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)<br>
+ return;<br>
+ // Member function of a class template and member function of a nested class<br>
+ // in a class template are allowed.<br>
+ if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {<br>
+ const auto *DC = MD->getDeclContext();<br>
+ while (DC->isRecord()) {<br>
+ if (const auto *RD = dyn_cast<CXXRecordDecl>(DC))<br>
+ if (RD->getDescribedClassTemplate())<br>
+ return;<br>
+ DC = DC->getParent();<br>
+ }<br>
+ }<br>
+<br>
+ diag(FD->getLocation(),<br>
+ "function '%0' defined in a header file; "<br>
+ "function definitions in header files can lead to ODR violations")<br>
+ << FD->getNameInfo().getName().getAsString()<br>
+ << FixItHint::CreateInsertion(FD->getSourceRange().getBegin(),<br>
+ "inline ");<br>
+ } else if (const auto *VD = dyn_cast<VarDecl>(ND)) {<br>
+ // Static data members of a class template are allowed.<br>
+ if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember())<br>
+ return;<br>
+ if (VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)<br>
+ return;<br>
+ // Ignore variable definition within function scope.<br>
+ if (VD->hasLocalStorage() || VD->isStaticLocal())<br>
+ return;<br>
+<br>
+ diag(VD->getLocation(),<br>
+ "variable '%0' defined in a header file; "<br>
+ "variable definitions in header files can lead to ODR violations")<br>
+ << VD->getName();<br>
+ }<br>
+}<br>
+<br>
+} // namespace misc<br>
+} // namespace tidy<br>
+} // namespace clang<br>
<br>
Added: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.h?rev=257178&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.h?rev=257178&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.h (added)<br>
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.h Fri Jan 8 10:37:11 2016<br>
@@ -0,0 +1,43 @@<br>
+//===--- DefinitionsInHeadersCheck.h - clang-tidy----------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H<br>
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H<br>
+<br>
+#include "../ClangTidy.h"<br>
+<br>
+namespace clang {<br>
+namespace tidy {<br>
+namespace misc {<br>
+<br>
+// Finds non-extern non-inline function and variable definitions in header<br>
+// files, which can lead to potential ODR violations.<br>
+//<br>
+// There is one option:<br>
+// - `UseHeaderFileExtension`: Whether to use file extension (h, hh, hpp, hxx)<br>
+// to distinguish header files. True by default.<br>
+//<br>
+// For the user-facing documentation see:<br>
+// <a href="http://clang.llvm.org/extra/clang-tidy/checks/misc-definitions-in-headers.html" rel="noreferrer" target="_blank">http://clang.llvm.org/extra/clang-tidy/checks/misc-definitions-in-headers.html</a><br>
+class DefinitionsInHeadersCheck : public ClangTidyCheck {<br>
+public:<br>
+ DefinitionsInHeadersCheck(StringRef Name, ClangTidyContext *Context);<br>
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;<br>
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;<br>
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;<br>
+<br>
+private:<br>
+ const bool UseHeaderFileExtension;<br>
+};<br>
+<br>
+} // namespace misc<br>
+} // namespace tidy<br>
+} // namespace clang<br>
+<br>
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H<br>
<br>
Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=257178&r1=257177&r2=257178&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=257178&r1=257177&r2=257178&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Fri Jan 8 10:37:11 2016<br>
@@ -14,6 +14,7 @@<br>
#include "AssertSideEffectCheck.h"<br>
#include "AssignOperatorSignatureCheck.h"<br>
#include "BoolPointerImplicitConversionCheck.h"<br>
+#include "DefinitionsInHeadersCheck.h"<br>
#include "InaccurateEraseCheck.h"<br>
#include "InefficientAlgorithmCheck.h"<br>
#include "MacroParenthesesCheck.h"<br>
@@ -48,6 +49,8 @@ public:<br>
"misc-assign-operator-signature");<br>
CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(<br>
"misc-bool-pointer-implicit-conversion");<br>
+ CheckFactories.registerCheck<DefinitionsInHeadersCheck>(<br>
+ "misc-definitions-in-headers");<br>
CheckFactories.registerCheck<InaccurateEraseCheck>(<br>
"misc-inaccurate-erase");<br>
CheckFactories.registerCheck<InefficientAlgorithmCheck>(<br>
<br>
Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=257178&r1=257177&r2=257178&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=257178&r1=257177&r2=257178&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)<br>
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Fri Jan 8 10:37:11 2016<br>
@@ -40,6 +40,7 @@ Clang-Tidy Checks<br>
misc-assert-side-effect<br>
misc-assign-operator-signature<br>
misc-bool-pointer-implicit-conversion<br>
+ misc-definitions-in-headers<br>
misc-inaccurate-erase<br>
misc-inefficient-algorithm<br>
misc-macro-parentheses<br>
<br>
Added: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst?rev=257178&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst?rev=257178&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst (added)<br>
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst Fri Jan 8 10:37:11 2016<br>
@@ -0,0 +1,37 @@<br>
+misc-definitions-in-headers<br>
+===========================<br>
+<br>
+Finds non-extern non-inline function and variable definitions in header files, which can lead to potential ODR violations.<br>
+<br>
+.. code:: c++<br>
+ // Foo.h<br>
+ int a = 1; // Warning.<br>
+ extern int d; // OK: extern variable.<br>
+<br>
+ namespace N {<br>
+ int e = 2; // Warning.<br>
+ }<br>
+<br>
+ // Internal linkage variable definitions are ignored for now.<br>
+ // Although these might also cause ODR violations, we can be less certain and<br>
+ // should try to keep the false-positive rate down.<br>
+ static int b = 1;<br>
+ const int c = 1;<br>
+<br>
+ // Warning.<br>
+ int g() {<br>
+ return 1;<br>
+ }<br>
+<br>
+ // OK: inline function definition.<br>
+ inline int e() {<br>
+ return 1;<br>
+ }<br>
+<br>
+ class A {<br>
+ public:<br>
+ int f1() { return 1; } // OK: inline member function definition.<br>
+ int f2();<br>
+ };<br>
+<br>
+ int A::f2() { return 1; } // Warning.<br>
<br>
Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=257178&r1=257177&r2=257178&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=257178&r1=257177&r2=257178&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py (original)<br>
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py Fri Jan 8 10:37:11 2016<br>
@@ -52,6 +52,8 @@ def main():<br>
extension = '.cpp'<br>
if (input_file_name.endswith('.c')):<br>
extension = '.c'<br>
+ if (input_file_name.endswith('.hpp')):<br>
+ extension = '.hpp'<br>
temp_file_name = temp_file_name + extension<br>
<br>
clang_tidy_extra_args = extra_args<br>
<br>
Added: clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp?rev=257178&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp?rev=257178&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp (added)<br>
+++ clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp Fri Jan 8 10:37:11 2016<br>
@@ -0,0 +1,135 @@<br>
+// RUN: %check_clang_tidy %s misc-definitions-in-headers %t<br>
+<br>
+int f() {<br>
+// 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]<br>
+// CHECK-FIXES: inline int f() {<br>
+ return 1;<br>
+}<br>
+<br>
+class CA {<br>
+ void f1() {} // OK: inline class member function definition.<br>
+ void f2();<br>
+ template<typename T><br>
+ T f3() {<br>
+ T a = 1;<br>
+ return a;<br>
+ }<br>
+ template<typename T><br>
+ struct CAA {<br>
+ struct CAB {<br>
+ void f4();<br>
+ };<br>
+ };<br>
+};<br>
+<br>
+void CA::f2() { }<br>
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: function 'f2' defined in a header file;<br>
+// CHECK-FIXES: inline void CA::f2() {<br>
+<br>
+template <><br>
+int CA::f3() {<br>
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: function 'f3' defined in a header file;<br>
+ int a = 1;<br>
+ return a;<br>
+}<br>
+<br>
+template <typename T><br>
+void CA::CAA<T>::CAB::f4() {<br>
+// OK: member function definition of a nested template class in a class.<br>
+}<br>
+<br>
+template <typename T><br>
+struct CB {<br>
+ void f1();<br>
+ struct CCA {<br>
+ void f2(T a);<br>
+ };<br>
+ struct CCB; // OK: forward declaration.<br>
+ static int a; // OK: class static data member declaration.<br>
+};<br>
+<br>
+template <typename T><br>
+void CB<T>::f1() { // OK: Member function definition of a class template.<br>
+}<br>
+<br>
+template <typename T><br>
+void CB<T>::CCA::f2(T a) {<br>
+// OK: member function definition of a nested class in a class template.<br>
+}<br>
+<br>
+template <typename T><br>
+struct CB<T>::CCB {<br>
+ void f3();<br>
+};<br>
+<br>
+template <typename T><br>
+void CB<T>::CCB::f3() {<br>
+// OK: member function definition of a nested class in a class template.<br>
+}<br>
+<br>
+template <typename T><br>
+int CB<T>::a = 2; // OK: static data member definition of a class template.<br>
+<br>
+template <typename T><br>
+T tf() { // OK: template function definition.<br>
+ T a;<br>
+ return a;<br>
+}<br>
+<br>
+<br>
+namespace NA {<br>
+ int f() { return 1; }<br>
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: function 'f' defined in a header file;<br>
+// CHECK-FIXES: inline int f() { return 1; }<br>
+}<br>
+<br>
+template <typename T><br>
+T f3() {<br>
+ T a = 1;<br>
+ return a;<br>
+}<br>
+<br>
+template <><br>
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: function 'f3' defined in a header file;<br>
+int f3() {<br>
+ int a = 1;<br>
+ return a;<br>
+}<br>
+<br>
+int f5(); // OK: function declaration.<br>
+inline int f6() { return 1; } // OK: inline function definition.<br>
+namespace {<br>
+ int f7() { return 1; }<br>
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: function 'f7' defined in a header file;<br>
+}<br>
+<br>
+int a = 1;<br>
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'a' defined in a header file; variable definitions in header files can lead to ODR violations [misc-definitions-in-headers]<br>
+CA a1;<br>
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: variable 'a1' defined in a header file;<br>
+<br>
+namespace NB {<br>
+ int b = 1;<br>
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'b' defined in a header file;<br>
+ const int c = 1; // OK: internal linkage variable definition.<br>
+}<br>
+<br>
+class CC {<br>
+ static int d; // OK: class static data member declaration.<br>
+};<br>
+<br>
+int CC::d = 1;<br>
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'd' defined in a header file;<br>
+<br>
+const char* ca = "foo";<br>
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'ca' defined in a header file;<br>
+<br>
+namespace {<br>
+ int e = 2;<br>
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'e' defined in a header file;<br>
+}<br>
+<br>
+const char* const g = "foo"; // OK: internal linkage variable definition.<br>
+static int h = 1; // OK: internal linkage variable definition.<br>
+const int i = 1; // OK: internal linkage variable definition.<br>
+extern int j; // OK: internal linkage variable definition.<br>
<br>
Modified: clang-tools-extra/trunk/test/lit.cfg<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/lit.cfg?rev=257178&r1=257177&r2=257178&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/lit.cfg?rev=257178&r1=257177&r2=257178&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/test/lit.cfg (original)<br>
+++ clang-tools-extra/trunk/test/lit.cfg Fri Jan 8 10:37:11 2016<br>
@@ -43,7 +43,8 @@ else:<br>
config.test_format = lit.formats.ShTest(execute_external)<br>
<br>
# suffixes: A list of file extensions to treat as test files.<br>
-config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.modularize', '.module-map-checker']<br>
+config.suffixes = ['.c', '.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s',<br>
+ '.modularize', '.module-map-checker']<br>
<br>
# Test-time dependencies located in directories called 'Inputs' are excluded<br>
# from test suites; there won't be any lit tests within them.<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div>