]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
parser.c (cp_parser_check_for_invalid_template_id): tag_type parm.
authorJason Merrill <jason@redhat.com>
Wed, 27 Jun 2012 19:19:18 +0000 (15:19 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 27 Jun 2012 19:19:18 +0000 (15:19 -0400)
* parser.c (cp_parser_check_for_invalid_template_id): tag_type parm.
(cp_parser_simple_type_specifier, cp_parser_class_head): Adjust.
(cp_parser_elaborated_type_specifier): Adjust.
* decl.c (duplicate_decls): Return error_mark_node on template
mismatch.

From-SVN: r189025

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/override2.C
gcc/testsuite/g++.dg/parse/crash28.C
gcc/testsuite/g++.dg/template/error5.C

index 425bf7c7f23dafb9454f9955aa80ddafdf880c04..00e9ca07cf81536d5a1ac39c1f6c97657f6f8b67 100644 (file)
@@ -1,5 +1,11 @@
 2012-06-27  Jason Merrill  <jason@redhat.com>
 
+       * parser.c (cp_parser_check_for_invalid_template_id): tag_type parm.
+       (cp_parser_simple_type_specifier, cp_parser_class_head): Adjust.
+       (cp_parser_elaborated_type_specifier): Adjust.
+       * decl.c (duplicate_decls): Return error_mark_node on template
+       mismatch.
+
        PR c++/53563
        * parser.c (cp_parser_template_id): Add tag_type parm.
        (cp_parser_template_name): Likewise.
index 1346f924c2bb74eb0a255bef83dbc72d3c314d3f..ab560199cedd41ad59c105f05079cf0b326fd0fc 100644 (file)
@@ -1463,6 +1463,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
            {
              error ("declaration of template %q#D", newdecl);
              error ("conflicts with previous declaration %q+#D", olddecl);
+             return error_mark_node;
            }
          else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
                   && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
index 7012caa2e6ae78637519aa22ede3c3810d17b745..027a7b9d07afcdb7de006561d5d3a4a2ef830e9a 100644 (file)
@@ -2278,7 +2278,7 @@ static bool cp_parser_check_type_definition
 static void cp_parser_check_for_definition_in_return_type
   (cp_declarator *, tree, location_t type_location);
 static void cp_parser_check_for_invalid_template_id
-  (cp_parser *, tree, location_t location);
+  (cp_parser *, tree, enum tag_types, location_t location);
 static bool cp_parser_non_integral_constant_expression
   (cp_parser *, non_integral_constant);
 static void cp_parser_diagnose_invalid_type_name
@@ -2551,7 +2551,9 @@ cp_parser_check_for_definition_in_return_type (cp_declarator *declarator,
 
 static void
 cp_parser_check_for_invalid_template_id (cp_parser* parser,
-                                        tree type, location_t location)
+                                        tree type,
+                                        enum tag_types tag_type,
+                                        location_t location)
 {
   cp_token_position start = 0;
 
@@ -2560,7 +2562,12 @@ cp_parser_check_for_invalid_template_id (cp_parser* parser,
       if (TYPE_P (type))
        error_at (location, "%qT is not a template", type);
       else if (TREE_CODE (type) == IDENTIFIER_NODE)
-       error_at (location, "%qE is not a template", type);
+       {
+         if (tag_type != none_type)
+           error_at (location, "%qE is not a class template", type);
+         else
+           error_at (location, "%qE is not a template", type);
+       }
       else
        error_at (location, "invalid template-id");
       /* Remember the location of the invalid "<".  */
@@ -13668,7 +13675,8 @@ cp_parser_simple_type_specifier (cp_parser* parser,
       /* There is no valid C++ program where a non-template type is
         followed by a "<".  That usually indicates that the user thought
         that the type was a template.  */
-      cp_parser_check_for_invalid_template_id (parser, type, token->location);
+      cp_parser_check_for_invalid_template_id (parser, type, none_type,
+                                              token->location);
 
       return TYPE_NAME (type);
     }
@@ -13770,6 +13778,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
         followed by a "<".  That usually indicates that the user
         thought that the type was a template.  */
       cp_parser_check_for_invalid_template_id (parser, TREE_TYPE (type),
+                                              none_type,
                                               token->location);
     }
 
@@ -14273,7 +14282,8 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
 
   /* A "<" cannot follow an elaborated type specifier.  If that
      happens, the user was probably trying to form a template-id.  */
-  cp_parser_check_for_invalid_template_id (parser, type, token->location);
+  cp_parser_check_for_invalid_template_id (parser, type, tag_type,
+                                          token->location);
 
   return type;
 }
@@ -18429,6 +18439,7 @@ cp_parser_class_head (cp_parser* parser,
   if (id)
     {
       cp_parser_check_for_invalid_template_id (parser, id,
+                                              class_key,
                                                type_start_token->location);
     }
   virt_specifiers = cp_parser_virt_specifier_seq_opt (parser);
index ebba545cf3ab1417961c71f0865d4ae73af17dd4..4217e6a6675f240158e8de11b1f67aa071039d06 100644 (file)
@@ -1,5 +1,9 @@
 2012-06-27  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/cpp0x/override2.C: Adjust.
+       * g++.dg/template/error5.C: Adjust.
+       * g++.dg/parse/crash28.C: Adjust.
+
        PR c++/53563
        * g++.dg/parse/template27.C: New.
        * g++.dg/template/crash74.C: Adjust expected output.
index 0d8871d6ae29eccace6aae9fa03c8e79fea56003..4d5a412baf5e1375f1fa5905e1e0872196075f30 100644 (file)
@@ -18,7 +18,7 @@ template <class T> struct B4 final {};
 
 template <class T> struct B5 final {};
 
-struct undeclared<int> final { }; // { dg-error "not a template" }
+struct undeclared<int> final { }; // { dg-error "not a class template" }
 
 struct D5 : B3<D5> {};
 
index 67d78d6bb7f5c3d5dff8cbfd6294c5ce83d6739c..68a975915cbc96a139a43d53f343883e77c88241 100644 (file)
@@ -5,10 +5,10 @@
 // Origin:Andrew Pinski <pinskia@gcc.gnu.org>
 //        Volker Reichelt <reichelt@gcc.gnu.org>
 
-template <class _Tp> class insert_iterator<slist<_Tp> > {}; // { dg-error "not a template|not declared in this scope|expected unqualified-id|extra" }
+template <class _Tp> class insert_iterator<slist<_Tp> > {}; // { dg-error "not a class template|not declared in this scope|expected unqualified-id|extra" }
 template <class _Value> class insert_iterator<int > { // { dg-error "template" }
   hash_set<_Value>;
 };
 
-template<int> struct A<X<> > {}; // { dg-error "not a template|not declared in this scope|expected unqualified-id|extra" }
+template<int> struct A<X<> > {}; // { dg-error "not a class template|not declared in this scope|expected unqualified-id|extra" }
 struct A {};
index 0c793509da4031998adb3825a3d81451a65dfd78..72d3c29b8fd5c6a5048404491d63b48d0c96c0eb 100644 (file)
@@ -1,6 +1,6 @@
 template <typename T>
-struct X<T*> { // { dg-error "not a template" }
+struct X<T*> { // { dg-error "not a class template" }
    typedef int Y;
 };
 
-extern struct Z<int> s; // { dg-error "not a template" }
+extern struct Z<int> s; // { dg-error "not a class template" }