commit 735ad45cb16c7703e1f5ec427c24b6809adb8ebb Author: Jason Merrill Date: Thu Jul 21 17:06:42 2016 -0400 PR c++/71630 - extern variable template * pt.c (instantiate_decl): Fix pattern_defined for namespace scope variable templates. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d7f3808..5e29d99 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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 index 0000000..3e30d67 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ53.C @@ -0,0 +1,10 @@ +// PR c++/71630 +// { dg-do compile { target c++14 } } + +template +extern T pi; + +int main() +{ + return pi; +}