re PR c++/54416 (ICE (segv) in codegen)
authorJason Merrill <jason@redhat.com>
Tue, 11 Dec 2012 18:16:50 +0000 (13:16 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 11 Dec 2012 18:16:50 +0000 (13:16 -0500)
PR c++/54416
* pt.c (maybe_process_partial_specialization): Don't accept
definition of a specialization without the appropriate header.

From-SVN: r194408

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/template/crash105.C
gcc/testsuite/g++.dg/template/error48.C [new file with mode: 0644]

index 02c0bfe20b2f709ef2800557c1d99401830bb665..2c3efe82556ad80c8141ccfff7805ce919f8fbdd 100644 (file)
@@ -1,5 +1,9 @@
 2012-12-11  Jason Merrill  <jason@redhat.com>
 
+       PR c++/54416
+       * pt.c (maybe_process_partial_specialization): Don't accept
+       definition of a specialization without the appropriate header.
+
        * pt.c (maybe_process_partial_specialization): Handle aliases first.
 
 2012-12-11  Jakub Jelinek  <jakub@redhat.com>
index f30a1e170ebf3fd8b0e730270df0700172145303..91450d8540702fa7118c09d33737d6e9f1da3dea 100644 (file)
@@ -850,7 +850,13 @@ maybe_process_partial_specialization (tree type)
        }
       else if (CLASSTYPE_TEMPLATE_INSTANTIATION (type))
        error ("specialization of %qT after instantiation", type);
-
+      else if (errorcount && !processing_specialization
+               && CLASSTYPE_TEMPLATE_SPECIALIZATION (type)
+              && !uses_template_parms (CLASSTYPE_TI_ARGS (type)))
+       /* Trying to define a specialization either without a template<> header
+          or in an inappropriate place.  We've already given an error, so just
+          bail now so we don't actually define the specialization.  */
+       return error_mark_node;
     }
   else if (CLASS_TYPE_P (type)
           && !CLASSTYPE_USE_TEMPLATE (type)
index 649bf8b77e12b149ee88da50f11032c24ef6b4e3..8cfff6a367d245dfb02befccd078f875111237c8 100644 (file)
@@ -10,5 +10,8 @@ template < typename > struct S < int >
 void
 f ()
 {
-  S < int >::f (); // { dg-error "cannot call" }
+  S < int >::f ();
 }
+
+// Don't be picky about error-recovery.
+// { dg-prune-output "." }
diff --git a/gcc/testsuite/g++.dg/template/error48.C b/gcc/testsuite/g++.dg/template/error48.C
new file mode 100644 (file)
index 0000000..483f7b5
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/54416
+
+template < typename T > struct foo;
+template <> struct foo < int >;
+template < typename T > struct bar
+{
+  template <> struct foo < int > // { dg-error "non-namespace scope" }
+  {
+    void baz ();
+  };
+};
+void foo < int >::baz () { }
+
+// Don't be picky about error-recovery.
+// { dg-prune-output "." }