]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
/cp
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 17 Jul 2014 08:32:18 +0000 (08:32 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 17 Jul 2014 08:32:18 +0000 (08:32 +0000)
2014-07-17  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/61804
* parser.c (cp_parser_tokens_start_cast_expression): Return -1
for '++' and '--'.

/testsuite
2014-07-17  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/61804
* g++.dg/parse/pr61804.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@212743 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 4291bd08a31c44aef33f8ad0b39102d6c5e3b13d..e4b27f4112bdb431e7dff1bb4c0fb57b97893528 100644 (file)
@@ -1,3 +1,9 @@
+2014-07-17  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/61804
+       * parser.c (cp_parser_tokens_start_cast_expression): Return -1
+       for '++' and '--'.
+
 2014-07-15  Jason Merrill  <jason@redhat.com>
 
        PR c++/61811
index 55dd29f002c69e6e92458fdd29c3abdfc9caa3cb..178114d2c840880ec3648fcdb7225c52633f6947 100644 (file)
@@ -7700,8 +7700,9 @@ cp_parser_delete_expression (cp_parser* parser)
                        tf_warning_or_error);
 }
 
-/* Returns 1 if TOKEN may start a cast-expression and, in C++11,
-   isn't '[', -1 if TOKEN is '[' in C++11, 0 otherwise.  */
+/* Returns 1 if TOKEN may start a cast-expression and isn't '++', '--',
+   neither '[' in C++11; -1 if TOKEN is '++', '--', or '[' in C++11;
+   0 otherwise.  */
 
 static int
 cp_parser_tokens_start_cast_expression (cp_parser *parser)
@@ -7755,13 +7756,26 @@ cp_parser_tokens_start_cast_expression (cp_parser *parser)
       return cp_lexer_peek_nth_token (parser->lexer, 2)->type
             != CPP_CLOSE_PAREN;
 
+    case CPP_OPEN_SQUARE:
       /* '[' may start a primary-expression in obj-c++ and in C++11,
         as a lambda-expression, eg, '(void)[]{}'.  */
-    case CPP_OPEN_SQUARE:
       if (cxx_dialect >= cxx11)
        return -1;
       return c_dialect_objc ();
 
+    case CPP_PLUS_PLUS:
+    case CPP_MINUS_MINUS:
+      /* '++' and '--' may or may not start a cast-expression:
+
+        struct T { void operator++(int); };
+        void f() { (T())++; }
+
+        vs
+
+        int a;
+        (int)++a;  */
+      return -1;
+
     default:
       return 1;
     }
@@ -7874,8 +7888,8 @@ cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p,
         function returning T.  */
       if (!cp_parser_error_occurred (parser))
        {
-         /* Only commit if the cast-expression doesn't start with '[' in
-            C++11, which may or may not start a lambda-expression.  */
+         /* Only commit if the cast-expression doesn't start with
+            '++', '--', or '[' in C++11.  */
          if (cast_expression > 0)
            cp_parser_commit_to_topmost_tentative_parse (parser);
 
index c507c8b39404fa97d7339beb41159069b2777dfe..8e656fef2971f969f72649927717a2b698e261fc 100644 (file)
@@ -1,3 +1,8 @@
+2014-07-17  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/61804
+       * g++.dg/parse/pr61804.C: New.
+
 2014-07-16  Arnaud Charlet  <charlet@adacore.com>
 
        * gnat.db/specs/alignment2.ads, gnat.db/specs/size_clause1.ads,
diff --git a/gcc/testsuite/g++.dg/parse/pr61804.C b/gcc/testsuite/g++.dg/parse/pr61804.C
new file mode 100644 (file)
index 0000000..898dc09
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/61804
+
+struct T { void operator++(int); };
+void f() { (T())++; }
+
+struct U { void operator--(int); };
+void g() { (U())--; }
+
+void h() { int a; (int)++a; (int)--a; }