[gcc(refs/vendors/redhat/heads/gcc-8-branch)] PR c++/87554 - ICE with extern template and reference member.

Jakub Jelinek jakub@gcc.gnu.org
Thu Sep 17 16:46:59 GMT 2020


https://gcc.gnu.org/g:de6a5d9c3a319c42ab85f6b5e548a8054cceac87

commit de6a5d9c3a319c42ab85f6b5e548a8054cceac87
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Feb 25 13:37:18 2020 -0500

    PR c++/87554 - ICE with extern template and reference member.
    
    The removed code ended up setting DECL_INITIAL to the INIT_EXPR returned by
    split_nonconstant_init, which makes no sense.  This code was added back in
    1996, so any rationale is long lost.
    
    gcc/cp/ChangeLog
    2020-02-25  Jason Merrill  <jason@redhat.com>
    
            PR c++/87554 - ICE with extern template and reference member.
            * decl.c (cp_finish_decl): Don't set DECL_INITIAL of external vars.

Diff:
---
 gcc/cp/ChangeLog                               |  5 ++++
 gcc/cp/decl.c                                  |  3 +--
 gcc/testsuite/g++.dg/cpp0x/extern_template-5.C | 36 ++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f0708892c38..348040383f4 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-25  Jason Merrill  <jason@redhat.com>
+
+	PR c++/87554 - ICE with extern template and reference member.
+	* decl.c (cp_finish_decl): Don't set DECL_INITIAL of external vars.
+
 2020-02-25  Alexandre Oliva <aoliva@redhat.com>
 
 	PR c++/86747
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 6dc23ec3273..5642791446f 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7301,8 +7301,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 	       && ! (DECL_LANG_SPECIFIC (decl)
 		     && DECL_NOT_REALLY_EXTERN (decl)))
 	{
-	  if (init)
-	    DECL_INITIAL (decl) = init;
+	  /* check_initializer will have done any constant initialization.  */
 	}
       /* A variable definition.  */
       else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
diff --git a/gcc/testsuite/g++.dg/cpp0x/extern_template-5.C b/gcc/testsuite/g++.dg/cpp0x/extern_template-5.C
new file mode 100644
index 00000000000..5d412489fb2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/extern_template-5.C
@@ -0,0 +1,36 @@
+// PR c++/87554
+// { dg-options "-O" }
+
+template < class a > class b {
+  static void c(a);
+  static a &create() { c(instance); return mya; }
+
+  static a mya;
+
+public:
+  static a d() { create(); return a(); }
+  static a &instance;
+};
+template < class a > a &b< a >::instance = create();
+class e;
+class f {
+public:
+  void operator()(int g) { h(g); }
+  template < class a > void h(a i) { p(j, i); }
+  e *j;
+};
+class e : public f {
+public:
+  e(int);
+};
+struct k {
+  int l;
+};
+template < class m, class a > void p(m, a) { b< k >::d(); }
+extern template class b< k >;
+int n;
+int o;
+void test() {
+  e out(o);
+  out(n);
+}


More information about the Gcc-cvs mailing list