[modules] Do not report missing definitions of demoted constexpr variable templates.

This is a followup to regression introduced in r284284.

This should fix our libstdc++ modules builds.

https://reviews.llvm.org/D25678

Reviewed by Richard Smith!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284577 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 82b4b71..cae1c19 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -10064,7 +10064,11 @@
     // 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 0000000..6b414b3
--- /dev/null
+++ b/test/Modules/Inputs/merge-var-template-def/a.h
@@ -0,0 +1,8 @@
+#ifndef A_H
+#define A_H
+template<typename T, T v>
+struct S { static constexpr T value = v; };
+template<typename T, T v>
+constexpr T S<T, v>::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 0000000..35cab9d
--- /dev/null
+++ b/test/Modules/Inputs/merge-var-template-def/b1.h
@@ -0,0 +1,9 @@
+#ifndef B1_H
+#define B1_H
+template<typename T, T v>
+struct S { static constexpr T value = v; };
+template<typename T, T v>
+constexpr T S<T, v>::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 0000000..6ab87c2
--- /dev/null
+++ b/test/Modules/Inputs/merge-var-template-def/b2.h
@@ -0,0 +1,9 @@
+#ifndef B2_H
+#define B2_H
+
+template<typename T, T v>
+struct S { static constexpr T value = v; };
+template<typename T, T v>
+constexpr T S<T, v>::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 0000000..b2c96bd
--- /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 0000000..97a72a1
--- /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<bool, false>::value;