]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/29022 (ICE using operator int in invalid class hierarchy)
authorLee Millward <lee.millward@codesourcery.com>
Sun, 3 Dec 2006 13:11:51 +0000 (13:11 +0000)
committerLee Millward <lmillward@gcc.gnu.org>
Sun, 3 Dec 2006 13:11:51 +0000 (13:11 +0000)
PR c++/29022
PR c++/27316
PR c++/28740
* parser.c (cp_parser_class_head): Move processing
of any base classes to...
(cp_parser_class_specifier) ...here. Take an extra
tree* parameter for the base classes. Only process
them if the opening brace was found.

PR c++/29022
* g++.dg/inherit/virtual1.C: New test.
* g++.dg/inherit/virtual2.C: Likewise.

PR c++/27316
* g++.dg/inherit/error3.C: New test.

PR c++/28740
* g++.dg/inherit/error4.C: New test.

From-SVN: r119463

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/inherit/error2.C
gcc/testsuite/g++.dg/inherit/error3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/inherit/error4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/inherit/virtual1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/inherit/virtual2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/instantiate1.C
gcc/testsuite/g++.old-deja/g++.bugs/900121_05.C

index 25363ad048d458c95bfafceebef92798b7594cec..22ca0608540ffac1cd16ba82cfca2047c247fd3d 100644 (file)
@@ -1,3 +1,14 @@
+2006-11-18 Lee Millward <lee.millward@codesourcery.com>
+
+       PR c++/29022
+       PR c++/27316
+       PR c++/28740
+       * parser.c (cp_parser_class_head): Move processing
+       of any base classes to...
+       (cp_parser_class_specifier) ...here. Take an extra
+       tree* parameter for the base classes. Only process
+       them if the opening brace was found.
+       
 2006-12-01  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/30022
index 0d840e7d375e104e0dae9aa20ca5b0f65e301648..bdef8483231c7f6c45f08792a8aee2f4b0c04564 100644 (file)
@@ -1550,7 +1550,7 @@ static tree cp_parser_class_name
 static tree cp_parser_class_specifier
   (cp_parser *);
 static tree cp_parser_class_head
-  (cp_parser *, bool *, tree *);
+  (cp_parser *, bool *, tree *, tree *);
 static enum tag_types cp_parser_class_key
   (cp_parser *);
 static void cp_parser_member_specification_opt
@@ -12606,13 +12606,15 @@ cp_parser_class_specifier (cp_parser* parser)
   unsigned saved_num_template_parameter_lists;
   tree old_scope = NULL_TREE;
   tree scope = NULL_TREE;
+  tree bases;
 
   push_deferring_access_checks (dk_no_deferred);
 
   /* Parse the class-head.  */
   type = cp_parser_class_head (parser,
                               &nested_name_specifier_p,
-                              &attributes);
+                              &attributes,
+                               &bases);
   /* If the class-head was a semantic disaster, skip the entire body
      of the class.  */
   if (!type)
@@ -12629,6 +12631,9 @@ cp_parser_class_specifier (cp_parser* parser)
       return error_mark_node;
     }
 
+  /* Process the base classes.  */
+  xref_basetypes (type, bases);
+
   /* Issue an error message if type-definitions are forbidden here.  */
   cp_parser_check_type_definition (parser);
   /* Remember that we are defining one more class.  */
@@ -12783,7 +12788,8 @@ cp_parser_class_specifier (cp_parser* parser)
 static tree
 cp_parser_class_head (cp_parser* parser,
                      bool* nested_name_specifier_p,
-                     tree *attributes_p)
+                     tree *attributes_p,
+                      tree *bases)
 {
   tree nested_name_specifier;
   enum tag_types class_key;
@@ -12796,7 +12802,6 @@ cp_parser_class_head (cp_parser* parser,
   bool invalid_explicit_specialization_p = false;
   tree pushed_scope = NULL_TREE;
   unsigned num_templates;
-  tree bases;
 
   /* Assume no nested-name-specifier will be present.  */
   *nested_name_specifier_p = false;
@@ -13092,14 +13097,11 @@ cp_parser_class_head (cp_parser* parser,
        struct A::C : B {};
 
      is valid.  */
-  bases = NULL_TREE;
+  *bases = NULL_TREE;
 
   /* Get the list of base-classes, if there is one.  */
   if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
-    bases = cp_parser_base_clause (parser);
-
-  /* Process the base classes.  */
-  xref_basetypes (type, bases);
+    *bases = cp_parser_base_clause (parser);
 
  done:
   /* Leave the scope given by the nested-name-specifier.  We will
index d18693da0703187a7d71b63963a61eb896be8345..c7c18d125895299b982e6fccc4c7b1174d8446b8 100644 (file)
@@ -1,3 +1,15 @@
+2006-12-03  Lee Millward  <lee.millward@codesourcery.com>
+
+       PR c++/29022
+       * g++.dg/inherit/virtual1.C: New test.
+       * g++.dg/inherit/virtual2.C: Likewise.
+
+       PR c++/27316
+       * g++.dg/inherit/error3.C: New test.
+
+       PR c++/28740
+       * g++.dg/inherit/error4.C: New test.
+       
 2006-12-01  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/30022
index 5a7c2940d272a8d8739b47de876aef719e3a723b..7d5e2e5d689fe940d4e4dc6e40d8b2005344d295 100644 (file)
@@ -3,14 +3,14 @@
 
 struct A
 {
-  virtual A* foo();
+  virtual A* foo();    // { dg-error "overriding" }
 };
 
 struct B : virtual A;  // { dg-error "before" }
 
 struct C : A
 {
-  virtual B* foo();
+  virtual B* foo();    // { dg-error "invalid covariant" }
 };
 
 B* C::foo() { return 0; }
diff --git a/gcc/testsuite/g++.dg/inherit/error3.C b/gcc/testsuite/g++.dg/inherit/error3.C
new file mode 100644 (file)
index 0000000..0b75b9d
--- /dev/null
@@ -0,0 +1,11 @@
+//PR c++/27316
+
+struct A {};
+
+struct B : A
+!               // { dg-error "token" }
+{};
+
+struct B : A
+!               // { dg-error "token" }
+{};
diff --git a/gcc/testsuite/g++.dg/inherit/error4.C b/gcc/testsuite/g++.dg/inherit/error4.C
new file mode 100644 (file)
index 0000000..3593cc8
--- /dev/null
@@ -0,0 +1,8 @@
+struct A { virtual ~A(); };
+
+struct B : A A {};            // { dg-error "'A'|function|extra" }
+
+A foo(const B &b)
+{
+  return b;                   // { dg-error "conversion" }
+}
diff --git a/gcc/testsuite/g++.dg/inherit/virtual1.C b/gcc/testsuite/g++.dg/inherit/virtual1.C
new file mode 100644 (file)
index 0000000..9769d4a
--- /dev/null
@@ -0,0 +1,13 @@
+//PR c++/29022
+
+struct A
+{
+  operator int();
+};
+
+struct B : virtual A, A<0> {};  // { dg-error "token" }
+
+int foo(B &b)
+{
+  return b;                     // { dg-error "cannot convert" }
+}
diff --git a/gcc/testsuite/g++.dg/inherit/virtual2.C b/gcc/testsuite/g++.dg/inherit/virtual2.C
new file mode 100644 (file)
index 0000000..65ae76c
--- /dev/null
@@ -0,0 +1,13 @@
+//PR c++/29022
+
+struct A
+{
+  operator int();
+};
+
+struct B : virtual A;  // { dg-error "token" }
+
+int foo(B &b)
+{
+  return b;            // { dg-error "cannot convert" }
+}
index 311344d9451dacee895dc63ae0deb6099f1df560..0c739d0f61550a5724bbebc8e434af679dc6ad13 100644 (file)
@@ -16,6 +16,6 @@ template <class T> struct Z { // { dg-error "declaration" }
   Y<Z<T> > y;                  // { dg-error "instantiated" }
 };
 
-struct ZZ : Z<int>             // { dg-error "instantiated" }
+struct ZZ : Z<int>
 {
 };
index 8dbae5df5b64ca39702babf7d66e18d78f5a95f2..62db5b343afed32430aaae18e27b75861ab894ec 100644 (file)
@@ -24,7 +24,7 @@ union u1 {
   int u1_member_1;
 };
 
-struct s1 : public u1 {                        /* { dg-error "" } base class is a union */
+struct s1 : public u1 {                        /* { dg-error "base type" } */
   int s1_member_0;
 };