]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/28606 (Destructor accepted as return-type of constructor)
authorVolker Reichelt <reichelt@igpm.rwth-aachen.de>
Thu, 17 Aug 2006 09:19:27 +0000 (09:19 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Thu, 17 Aug 2006 09:19:27 +0000 (09:19 +0000)
PR c++/28606
* parser.c (cp_parser_diagnose_invalid_type_name): Handle BIT_NOT_EXPR.
Fix formatting.
(cp_parser_parse_and_diagnose_invalid_type_name): Tighten condition
for valid type-names.
(cp_parser_unqualified_id): Fix error handling for destructors.

* g++.dg/parse/dtor11.C: New test.

From-SVN: r116219

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/dtor11.C [new file with mode: 0644]

index 1dcbc7736cf15e3bbf3538979fb2c40640126367..e2fada81d90588053c3800bfa617ce3fb46c79e8 100644 (file)
@@ -1,5 +1,12 @@
 2006-08-17  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
+       PR c++/28606
+       * parser.c (cp_parser_diagnose_invalid_type_name): Handle BIT_NOT_EXPR.
+       Fix formatting.
+       (cp_parser_parse_and_diagnose_invalid_type_name): Tighten condition
+       for valid type-names.
+       (cp_parser_unqualified_id): Fix error handling for destructors.
+
        PR c++/28710
        * decl.c (xref_tag): Improve error message.  Return early on error.
 
index 9e6fedfd639396f514a15eccf967e9269114e22a..13cf044cf0c8ab9f50ec168fb73258eea497cf55 100644 (file)
@@ -2049,8 +2049,9 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree scope, tree id)
   /* If the lookup found a template-name, it means that the user forgot
   to specify an argument list. Emit an useful error message.  */
   if (TREE_CODE (decl) == TEMPLATE_DECL)
-    error ("invalid use of template-name %qE without an argument list",
-      decl);
+    error ("invalid use of template-name %qE without an argument list", decl);
+  else if (TREE_CODE (id) == BIT_NOT_EXPR)
+    error ("invalid use of destructor %qD as a type", id);
   else if (!parser->scope || parser->scope == error_mark_node)
     {
       /* Issue an error message.  */
@@ -2143,8 +2144,7 @@ cp_parser_parse_and_diagnose_invalid_type_name (cp_parser *parser)
       cp_parser_abort_tentative_parse (parser);
       return false;
     }
-  if (!cp_parser_parse_definitely (parser)
-      || TREE_CODE (id) != IDENTIFIER_NODE)
+  if (!cp_parser_parse_definitely (parser) || TREE_CODE (id) == TYPE_DECL)
     return false;
 
   /* Emit a diagnostic for the invalid type.  */
@@ -3302,14 +3302,17 @@ cp_parser_unqualified_id (cp_parser* parser,
        /* Check for invalid scopes.  */
        if (scope == error_mark_node)
          {
-           cp_parser_skip_to_end_of_statement (parser);
+           if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+             cp_lexer_consume_token (parser->lexer);
            return error_mark_node;
          }
        if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
          {
            if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
              error ("scope %qT before %<~%> is not a class-name", scope);
-           cp_parser_skip_to_end_of_statement (parser);
+           cp_parser_simulate_error (parser);
+           if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+             cp_lexer_consume_token (parser->lexer);
            return error_mark_node;
          }
        gcc_assert (!scope || TYPE_P (scope));
@@ -3409,6 +3412,7 @@ cp_parser_unqualified_id (cp_parser* parser,
            if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
              error ("declaration of %<~%T%> as member of %qT",
                     type_decl, scope);
+           cp_parser_simulate_error (parser);
            return error_mark_node;
          }
 
index 291c55d68bfb126a3163daea0fec37945d16c4d2..9da2505713787fb502d80b01107fd1ccf68e713c 100644 (file)
@@ -1,5 +1,8 @@
 2006-08-17  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
+       PR c++/28606
+       * g++.dg/parse/dtor11.C: New test.
+
        PR c++/28710
        * g++.dg/template/redecl4.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/parse/dtor11.C b/gcc/testsuite/g++.dg/parse/dtor11.C
new file mode 100644 (file)
index 0000000..63ffb60
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/28606
+// { dg-do compile }
+
+struct A
+{
+  ~A A();     // { dg-error "destructor" }
+};
+
+struct B
+{
+  A::~B B();  // { dg-error "as member of" }
+};