re PR c++/34269 (Incomplete __decltype/__typeof expressions accepted)
authorJakub Jelinek <jakub@redhat.com>
Wed, 12 Nov 2008 17:33:48 +0000 (18:33 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 12 Nov 2008 17:33:48 +0000 (18:33 +0100)
PR c++/34269
* parser.c (cp_parser_simple_declaration): Don't commit
to tentative parse if parse errors were seen.

* g++.dg/cpp0x/decltype13.C: New test.
* g++.dg/cpp0x/decltype-33837.C: Adjust dg-error pattern.
* g++.dg/cpp0x/pr33839.C: Likewise.

From-SVN: r141793

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/decltype-33837.C
gcc/testsuite/g++.dg/cpp0x/decltype13.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/pr33839.C

index 8cfdf61255e5c80935f90df8a42c26664f972d36..c19dc815467a4c60ada3ff5f0e40cf629b40245d 100644 (file)
@@ -1,5 +1,9 @@
 2008-11-12  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/34269
+       * parser.c (cp_parser_simple_declaration): Don't commit
+       to tentative parse if parse errors were seen.
+
        PR c++/35334
        * error.c (dump_expr): Handle COMPLEX_EXPR.
 
index c819082c781000c20b0e15ba61dd8508920c55c2..ec9624e69b28524421804fc9c439fa1e3680df2c 100644 (file)
@@ -8179,7 +8179,8 @@ cp_parser_simple_declaration (cp_parser* parser,
      (After "int (" we might be looking at a functional cast.)  */
   if (decl_specifiers.any_specifiers_p
       && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN)
-      && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE))
+      && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE)
+      && !cp_parser_error_occurred (parser))
     cp_parser_commit_to_tentative_parse (parser);
 
   /* Keep going until we hit the `;' at the end of the simple
index cd3752a741c3c12d48a581eaab58b2493ce56dd7..ab700dd9bb6c2c0b49df9c14d779d3f92316add5 100644 (file)
@@ -1,5 +1,10 @@
 2008-11-12  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/34269
+       * g++.dg/cpp0x/decltype13.C: New test.
+       * g++.dg/cpp0x/decltype-33837.C: Adjust dg-error pattern.
+       * g++.dg/cpp0x/pr33839.C: Likewise.
+
        PR target/35366
        PR fortran/33759
        * gfortran.dg/hollerith.f90: Don't assume a 32-bit value
index 35689fbc279352fcc15d2a5f435be2a2b645b64a..2c263dd0a97fc8f2c8ea70e9f15ea63b63c20c9a 100644 (file)
@@ -2,6 +2,6 @@
 // PR c++/33837
 void foo()
 {
-  __decltype (A::foo()); // { dg-error "was not declared|expected initializer" }
+  __decltype (A::foo()); // { dg-error "was not declared|expected" }
   __decltype (B); // { dg-error "was not declared" }
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype13.C b/gcc/testsuite/g++.dg/cpp0x/decltype13.C
new file mode 100644 (file)
index 0000000..8e6c6d2
--- /dev/null
@@ -0,0 +1,38 @@
+// PR c++/34269
+// { dg-do compile }
+
+void
+f1 ()
+{
+  __decltype;          // { dg-error "expected" }
+}
+
+void
+f2 ()
+{
+  __decltype (;                // { dg-error "expected" }
+}
+
+void
+f3 ()
+{
+  __decltype ();       // { dg-error "expected" }
+}
+
+void
+f4 ()
+{
+  __typeof__;          // { dg-error "expected" }
+}
+
+void
+f5 ()
+{
+  __typeof__ (;                // { dg-error "expected" }
+}
+
+void
+f6 ()
+{
+  __typeof__ ();       // { dg-error "expected" }
+}
index 4111d6ccfc06c3d232bc9583059d73ce8558df74..0a6610ac995335ec3a754313b3dd59a123954d6e 100644 (file)
@@ -3,6 +3,6 @@ template<int> struct A;
 
 void foo()
 {
-  __decltype A<0>; // { dg-error "invalid declarator" }
+  __decltype A<0>; // { dg-error "invalid declarator|expected" }
   __decltype (A<0>); // { dg-error "must be an expression" }
 }