PR c++/71630 - extern variable template
authorJason Merrill <jason@redhat.com>
Fri, 22 Jul 2016 03:45:43 +0000 (23:45 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 22 Jul 2016 03:45:43 +0000 (23:45 -0400)
* pt.c (instantiate_decl): Fix pattern_defined for namespace scope
variable templates.

From-SVN: r238622

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1y/var-templ53.C [new file with mode: 0644]

index b196d54937d8cc17eac5db55a5e9cdf6683ee1ce..8cf538b22a5fd1478bb17db71fbbc18ce789c276 100644 (file)
@@ -1,5 +1,9 @@
 2016-07-21  Jason Merrill  <jason@redhat.com>
 
+       PR c++/71630
+       * pt.c (instantiate_decl): Fix pattern_defined for namespace scope
+       variable templates.
+
        PR c++/71913
        * call.c (unsafe_copy_elision_p): It's OK to elide when
        initializing an unknown object.
index d7f380857bdc0e4f22b0921e9d0f192d8c4ab1fb..5e29d998287fad5026e89171d77cb533712d07cb 100644 (file)
@@ -21853,7 +21853,10 @@ instantiate_decl (tree d, int defer_ok,
   else
     {
       deleted_p = false;
-      pattern_defined = ! DECL_IN_AGGR_P (code_pattern);
+      if (DECL_CLASS_SCOPE_P (code_pattern))
+       pattern_defined = ! DECL_IN_AGGR_P (code_pattern);
+      else
+       pattern_defined = ! DECL_EXTERNAL (code_pattern);
     }
 
   /* We may be in the middle of deferred access check.  Disable it now.  */
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ53.C b/gcc/testsuite/g++.dg/cpp1y/var-templ53.C
new file mode 100644 (file)
index 0000000..3e30d67
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/71630
+// { dg-do compile { target c++14 } }
+
+template <class T>
+extern T pi;
+
+int main()
+{
+  return pi<int>;
+}