diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index af1ac443ba..b483690a03 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -10124,7 +10124,11 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl, // 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()) { + assert((!Var->isThisDeclarationADemotedDefinition() || + getLangOpts().Modules) && + "Demoting decls is only in the contest of modules!"); if (Var->isStaticDataMember()) { // C++1z removes the relevant rule; the in-class declaration is always // a definition there. diff --git a/test/Modules/Inputs/merge-var-template-def/a.h b/test/Modules/Inputs/merge-var-template-def/a.h new file mode 100644 index 0000000000..6b414b3031 --- /dev/null +++ b/test/Modules/Inputs/merge-var-template-def/a.h @@ -0,0 +1,8 @@ +#ifndef A_H +#define A_H +template +struct S { static constexpr T value = v; }; +template +constexpr T S::value; + +#endif diff --git a/test/Modules/Inputs/merge-var-template-def/b1.h b/test/Modules/Inputs/merge-var-template-def/b1.h new file mode 100644 index 0000000000..35cab9d01c --- /dev/null +++ b/test/Modules/Inputs/merge-var-template-def/b1.h @@ -0,0 +1,9 @@ +#ifndef B1_H +#define B1_H +template +struct S { static constexpr T value = v; }; +template +constexpr T S::value; + +#include "a.h" +#endif diff --git a/test/Modules/Inputs/merge-var-template-def/b2.h b/test/Modules/Inputs/merge-var-template-def/b2.h new file mode 100644 index 0000000000..6ab87c2fa7 --- /dev/null +++ b/test/Modules/Inputs/merge-var-template-def/b2.h @@ -0,0 +1,9 @@ +#ifndef B2_H +#define B2_H + +template +struct S { static constexpr T value = v; }; +template +constexpr T S::value; + +#endif diff --git a/test/Modules/Inputs/merge-var-template-def/module.modulemap b/test/Modules/Inputs/merge-var-template-def/module.modulemap new file mode 100644 index 0000000000..b2c96bd821 --- /dev/null +++ b/test/Modules/Inputs/merge-var-template-def/module.modulemap @@ -0,0 +1,5 @@ +module a { header "a.h" export * } +module b { + module b1 { header "b1.h" export * } + module b2 { header "b2.h" export * } +} diff --git a/test/Modules/merge-var-template-def.cpp b/test/Modules/merge-var-template-def.cpp new file mode 100644 index 0000000000..97a72a194d --- /dev/null +++ b/test/Modules/merge-var-template-def.cpp @@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// 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" +const bool *y = &S::value;