]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/56239 (parse error calling operator() on parenthesized value...
authorJakub Jelinek <jakub@redhat.com>
Wed, 3 Apr 2013 18:04:07 +0000 (20:04 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 3 Apr 2013 18:04:07 +0000 (20:04 +0200)
Backported from mainline
2013-02-07  Jakub Jelinek  <jakub@redhat.com>

PR c++/56239
* parser.c (cp_parser_token_starts_cast_expression): Renamed to...
(cp_parser_tokens_start_cast_expression): ... this.  Change parameter
to cp_parser *, call cp_lexer_peek_token first.  For CPP_OPEN_PAREN,
return true only if 2nd token isn't CPP_CLOSE_PAREN.
(cp_parser_cast_expression): Adjust caller.

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

From-SVN: r197450

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

index 1808b9d09cc39093f957d76908d45c6bf77d9215..aa358f0806b827ecf36dfc6479da30b4302bdecd 100644 (file)
@@ -1,6 +1,15 @@
 2013-04-03  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2013-02-07  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/56239
+       * parser.c (cp_parser_token_starts_cast_expression): Renamed to...
+       (cp_parser_tokens_start_cast_expression): ... this.  Change parameter
+       to cp_parser *, call cp_lexer_peek_token first.  For CPP_OPEN_PAREN,
+       return true only if 2nd token isn't CPP_CLOSE_PAREN.
+       (cp_parser_cast_expression): Adjust caller.
+
        2012-10-08  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/54858
index da09e425f7c98d3b8a9efb90c43bd80d992c416b..8e8e834899591b0039b1e0ff843032c3a27219fd 100644 (file)
@@ -6566,8 +6566,9 @@ cp_parser_delete_expression (cp_parser* parser)
    otherwise.  */
 
 static bool
-cp_parser_token_starts_cast_expression (cp_token *token)
+cp_parser_tokens_start_cast_expression (cp_parser *parser)
 {
+  cp_token *token = cp_lexer_peek_token (parser->lexer);
   switch (token->type)
     {
     case CPP_COMMA:
@@ -6608,6 +6609,12 @@ cp_parser_token_starts_cast_expression (cp_token *token)
     case CPP_EOF:
       return false;
 
+    case CPP_OPEN_PAREN:
+      /* In ((type ()) () the last () isn't a valid cast-expression,
+        so the whole must be parsed as postfix-expression.  */
+      return cp_lexer_peek_nth_token (parser->lexer, 2)->type
+            != CPP_CLOSE_PAREN;
+
       /* '[' may start a primary-expression in obj-c++.  */
     case CPP_OPEN_SQUARE:
       return c_dialect_objc ();
@@ -6700,8 +6707,7 @@ cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p,
         parenthesized ctor such as `(T ())' that looks like a cast to
         function returning T.  */
       if (!cp_parser_error_occurred (parser)
-         && cp_parser_token_starts_cast_expression (cp_lexer_peek_token
-                                                    (parser->lexer)))
+         && cp_parser_tokens_start_cast_expression (parser))
        {
          cp_parser_parse_definitely (parser);
          expr = cp_parser_cast_expression (parser,
index c227cc1e2d17a201c353ac9d6c26c59b5fa7ff8b..6b83c2732463b026cb560d8ddbed2eebe1db5058 100644 (file)
@@ -1,6 +1,11 @@
 2013-04-03  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2013-02-07  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/56239
+       * g++.dg/parse/pr56239.C: New test.
+
        2013-01-25  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/56098
diff --git a/gcc/testsuite/g++.dg/parse/pr56239.C b/gcc/testsuite/g++.dg/parse/pr56239.C
new file mode 100644 (file)
index 0000000..08f7f68
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/56239
+// { dg-do compile }
+
+struct S
+{
+  int operator () () { return 0; }
+};
+
+int
+main ()
+{
+  return (S ()) ();
+}