Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -10124,7 +10124,8 @@ // C++11 [dcl.constexpr]p1: The constexpr specifier shall be applied only to // the definition of a variable [...] or the declaration of a static data // member. - if (Var->isConstexpr() && !Var->isThisDeclarationADefinition()) { + if (Var->isConstexpr() && !Var->isThisDeclarationADefinition() && + !Var->isThisDeclarationADemotedDefinition()) { if (Var->isStaticDataMember()) { // C++1z removes the relevant rule; the in-class declaration is always // a definition there. Index: test/Modules/Inputs/merge-var-template-def/a.h =================================================================== --- test/Modules/Inputs/merge-var-template-def/a.h +++ test/Modules/Inputs/merge-var-template-def/a.h @@ -3,4 +3,10 @@ template struct A { static bool b; }; template bool A::b = false; template void *get() { return &(A::b); } + +template +struct S { static constexpr T value = v; }; +template +constexpr T S::value; + #endif Index: test/Modules/Inputs/merge-var-template-def/b1.h =================================================================== --- test/Modules/Inputs/merge-var-template-def/b1.h +++ test/Modules/Inputs/merge-var-template-def/b1.h @@ -3,5 +3,11 @@ template struct A { static bool b; }; template bool A::b = false; template void *get() { return &(A::b); } + +template +struct S { static constexpr T value = v; }; +template +constexpr T S::value; + #include "a.h" #endif Index: test/Modules/Inputs/merge-var-template-def/b2.h =================================================================== --- test/Modules/Inputs/merge-var-template-def/b2.h +++ test/Modules/Inputs/merge-var-template-def/b2.h @@ -3,4 +3,10 @@ template struct A { static bool b; }; template bool A::b = false; template void *get() { return &(A::b); } + +template +struct S { static constexpr T value = v; }; +template +constexpr T S::value; + #endif Index: test/Modules/merge-var-template-def.cpp =================================================================== --- test/Modules/merge-var-template-def.cpp +++ test/Modules/merge-var-template-def.cpp @@ -1,7 +1,10 @@ // RUN: rm -rf %t -// RUN: %clang_cc1 -I%S/Inputs/merge-var-template-def -verify -fmodules -Werror=undefined-internal -fmodules-local-submodule-visibility -fmodules-cache-path=%t -fimplicit-module-maps %s +// RUN: %clang_cc1 -I%S/Inputs/merge-var-template-def -std=c++11 -verify %s +// RUN: %clang_cc1 -I%S/Inputs/merge-var-template-def -std=c++11 -verify -fmodules -Werror=undefined-internal -fmodules-local-submodule-visibility -fmodules-cache-path=%t -fimplicit-module-maps %s // expected-no-diagnostics #include "b2.h" namespace { struct X; } void *x = get(); + +const bool *y = &S::value;