]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/87554 - ICE with extern template and reference member.
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Apr 2019 16:50:10 +0000 (16:50 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Apr 2019 16:50:10 +0000 (16:50 +0000)
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.

* decl.c (cp_finish_decl): Don't set DECL_INITIAL of external vars.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@270445 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp0x/extern_template-5.C [new file with mode: 0644]

index bfaf355ebb709b1f8e0ebbec9ec10a078f60ba5e..7bb464f8aa783f5423ead89aafe6884dc4f2305c 100644 (file)
@@ -1,3 +1,8 @@
+2019-04-18  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.
+
 2019-04-17  Jason Merrill  <jason@redhat.com>
 
        PR c++/90047 - ICE with enable_if alias template.
index 67d9244c450e3fb878064f243454461644c1ab4c..420d6d896ec005214e4de9a63f7faf14a0e5aa79 100644 (file)
@@ -7354,8 +7354,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 (file)
index 0000000..5d41248
--- /dev/null
@@ -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);
+}