From: John McCall Date: Mon, 21 Feb 2011 19:25:48 +0000 (+0000) Subject: Don't warn about static const integral data members with in-line constant X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=77efc680156bc28d3c0d2e70f156904f91328b21;p=clang Don't warn about static const integral data members with in-line constant initializers just because they don't have a proper out-of-line definition. Such code is technically ill-formed but is too common and too unlikely to be a problem to be seriously worth worrying about. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126137 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 84baa7d985..e7d167ed38 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -9336,9 +9336,12 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { } } - // Keep track of used but undefined variables. + // Keep track of used but undefined variables. We make a hole in + // the warning for static const data members with in-line + // initializers. if (Var->hasDefinition() == VarDecl::DeclarationOnly - && Var->getLinkage() != ExternalLinkage) { + && Var->getLinkage() != ExternalLinkage + && !(Var->isStaticDataMember() && Var->hasInit())) { SourceLocation &old = UndefinedInternals[Var->getCanonicalDecl()]; if (old.isInvalid()) old = Loc; } diff --git a/test/SemaCXX/undefined-internal.cpp b/test/SemaCXX/undefined-internal.cpp index bb87ce0f12..a7e9249965 100644 --- a/test/SemaCXX/undefined-internal.cpp +++ b/test/SemaCXX/undefined-internal.cpp @@ -84,3 +84,24 @@ namespace test5 { B::foo(); // expected-note {{used here}} } } + +namespace test6 { + template struct A { + static const int zero = 0; + static const int one = 1; + static const int two = 2; + + int value; + + A() : value(zero) { + value = one; + } + }; + + namespace { struct Internal; } + + void test() { + A a; + a.value = A::two; + } +}