public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary
@ 2013-02-07 10:37 ed at catmur dot co.uk
  2013-02-07 11:47 ` [Bug c++/56239] [4.6/4.7/4.8 Regression] " jakub at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ed at catmur dot co.uk @ 2013-02-07 10:37 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56239

             Bug #: 56239
           Summary: parse error calling operator() on parenthesized
                    value-initialized temporary
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ed@catmur.co.uk


From
http://stackoverflow.com/questions/14732132/global-initialization-with-temporary-function-object

Under gcc 4.8.0 (20130127):

struct S { int operator()(); };
int main() { (S())(); }

source.cpp:2:20: error: expected primary-expression before ')' token
 int main() { (S())(); }
                    ^

Motivation for parenthesizing the temporary is to use it in a constructor call:

struct S { int operator()(); };
struct T { T(int); };
int main() { T t((S())()); }

source.cpp:3:24: error: expected primary-expression before ')' token
 int main() { T t((S())()); }
                        ^

It appears that gcc is parsing the expression (S())() using production 5.4p2:

cast-expression:
    unary-expression
    ( type-id ) cast-expression

Since an empty pair of parentheses is not a cast-expression, this should
instead be parsed using 5.2p1:

postfix-expression:
    [...]
    postfix-expression ( expression-list[opt] )
    [...]
where the postfix-expression is (S()) and the expression-list is omitted.

Same error occurs in both C++03 and C++11 mode.

icc 13.0.1 has the same issue; clang 3.2 compiles it successfully.

Two workarounds are available: enclose (S()) in an extra pair of parentheses,
or use C++11 universal initialization syntax.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/56239] [4.6/4.7/4.8 Regression] parse error calling operator() on parenthesized value-initialized temporary
  2013-02-07 10:37 [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary ed at catmur dot co.uk
@ 2013-02-07 11:47 ` jakub at gcc dot gnu.org
  2013-02-07 12:00 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-07 11:47 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56239

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-02-07
                 CC|                            |jakub at gcc dot gnu.org
   Target Milestone|---                         |4.6.4
            Summary|parse error calling         |[4.6/4.7/4.8 Regression]
                   |operator() on parenthesized |parse error calling
                   |value-initialized temporary |operator() on parenthesized
                   |                            |value-initialized temporary
     Ever Confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-07 11:46:37 UTC ---
Started with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141429


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/56239] [4.6/4.7/4.8 Regression] parse error calling operator() on parenthesized value-initialized temporary
  2013-02-07 10:37 [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary ed at catmur dot co.uk
  2013-02-07 11:47 ` [Bug c++/56239] [4.6/4.7/4.8 Regression] " jakub at gcc dot gnu.org
@ 2013-02-07 12:00 ` paolo.carlini at oracle dot com
  2013-02-07 13:15 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-07 12:00 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56239

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-07 11:59:32 UTC ---
Let's add Manuel in CC.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/56239] [4.6/4.7/4.8 Regression] parse error calling operator() on parenthesized value-initialized temporary
  2013-02-07 10:37 [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary ed at catmur dot co.uk
  2013-02-07 11:47 ` [Bug c++/56239] [4.6/4.7/4.8 Regression] " jakub at gcc dot gnu.org
  2013-02-07 12:00 ` paolo.carlini at oracle dot com
@ 2013-02-07 13:15 ` jakub at gcc dot gnu.org
  2013-02-07 15:03 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-07 13:15 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56239

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-07 13:14:12 UTC ---
Created attachment 29384
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29384
gcc48-pr56239.patch

If () is the only problem, then it can be fixed e.g. by the following patch
(untested so far, except for make -C gcc check-g++).

BTW, I wonder where the standard resolves the ambiguity between parsing it as a
function call with parenthesized ctor and between a cast.  For zero operands it
is not ambiguous, but if there is one or more operands, apparently it should be
parsed as cast, but I haven't found where the standard says so.
struct S { int operator()(int, int); };
int main() { (S())(1, 2); }
//int main() { S s; s(1, 2); }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/56239] [4.6/4.7/4.8 Regression] parse error calling operator() on parenthesized value-initialized temporary
  2013-02-07 10:37 [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary ed at catmur dot co.uk
                   ` (2 preceding siblings ...)
  2013-02-07 13:15 ` jakub at gcc dot gnu.org
@ 2013-02-07 15:03 ` jason at gcc dot gnu.org
  2013-02-07 17:51 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2013-02-07 15:03 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56239

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2013-02-07 15:02:53 UTC ---
(In reply to comment #3)
> gcc48-pr56239.patch

OK.

> BTW, I wonder where the standard resolves the ambiguity between parsing it as a
> function call with parenthesized ctor and between a cast.

8.2/2:

The ambiguity arising from the similarity between a function-style cast and a
type-id can occur in different contexts. The ambiguity appears as a choice
between a function-style cast expression and a declaration of a type. The
resolution is that any construct that could possibly be a type-id in its
syntactic context shall be considered a type-id.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/56239] [4.6/4.7/4.8 Regression] parse error calling operator() on parenthesized value-initialized temporary
  2013-02-07 10:37 [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary ed at catmur dot co.uk
                   ` (3 preceding siblings ...)
  2013-02-07 15:03 ` jason at gcc dot gnu.org
@ 2013-02-07 17:51 ` jakub at gcc dot gnu.org
  2013-02-07 17:55 ` [Bug c++/56239] [4.6/4.7 " jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-07 17:51 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56239

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-07 17:50:15 UTC ---
Author: jakub
Date: Thu Feb  7 17:49:59 2013
New Revision: 195859

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195859
Log:
    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.

Added:
    trunk/gcc/testsuite/g++.dg/parse/pr56239.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/56239] [4.6/4.7 Regression] parse error calling operator() on parenthesized value-initialized temporary
  2013-02-07 10:37 [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary ed at catmur dot co.uk
                   ` (4 preceding siblings ...)
  2013-02-07 17:51 ` jakub at gcc dot gnu.org
@ 2013-02-07 17:55 ` jakub at gcc dot gnu.org
  2013-02-19 17:23 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-07 17:55 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56239

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
      Known to work|                            |4.8.0
         AssignedTo|unassigned at gcc dot       |jakub at gcc dot gnu.org
                   |gnu.org                     |
            Summary|[4.6/4.7/4.8 Regression]    |[4.6/4.7 Regression] parse
                   |parse error calling         |error calling operator() on
                   |operator() on parenthesized |parenthesized
                   |value-initialized temporary |value-initialized temporary

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-07 17:54:11 UTC ---
Fixed on the trunk so far.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/56239] [4.6/4.7 Regression] parse error calling operator() on parenthesized value-initialized temporary
  2013-02-07 10:37 [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary ed at catmur dot co.uk
                   ` (5 preceding siblings ...)
  2013-02-07 17:55 ` [Bug c++/56239] [4.6/4.7 " jakub at gcc dot gnu.org
@ 2013-02-19 17:23 ` jakub at gcc dot gnu.org
  2013-02-19 17:40 ` [Bug c++/56239] [4.6 " jakub at gcc dot gnu.org
  2013-04-03 18:21 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-19 17:23 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56239

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-19 17:22:51 UTC ---
Author: jakub
Date: Tue Feb 19 17:22:43 2013
New Revision: 196145

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196145
Log:
    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.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/parse/pr56239.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/parser.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/56239] [4.6 Regression] parse error calling operator() on parenthesized value-initialized temporary
  2013-02-07 10:37 [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary ed at catmur dot co.uk
                   ` (6 preceding siblings ...)
  2013-02-19 17:23 ` jakub at gcc dot gnu.org
@ 2013-02-19 17:40 ` jakub at gcc dot gnu.org
  2013-04-03 18:21 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-19 17:40 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56239

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[4.6/4.7 Regression] parse  |[4.6 Regression] parse
                   |error calling operator() on |error calling operator() on
                   |parenthesized               |parenthesized
                   |value-initialized temporary |value-initialized temporary

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-19 17:39:42 UTC ---
Fixed for 4.7.3+.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/56239] [4.6 Regression] parse error calling operator() on parenthesized value-initialized temporary
  2013-02-07 10:37 [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary ed at catmur dot co.uk
                   ` (7 preceding siblings ...)
  2013-02-19 17:40 ` [Bug c++/56239] [4.6 " jakub at gcc dot gnu.org
@ 2013-04-03 18:21 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-04-03 18:21 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56239

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-03 18:21:16 UTC ---
Author: jakub
Date: Wed Apr  3 18:04:07 2013
New Revision: 197450

URL: http://gcc.gnu.org/viewcvs?rev=197450&root=gcc&view=rev
Log:
    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.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/parse/pr56239.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/parser.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-04-03 18:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-07 10:37 [Bug c++/56239] New: parse error calling operator() on parenthesized value-initialized temporary ed at catmur dot co.uk
2013-02-07 11:47 ` [Bug c++/56239] [4.6/4.7/4.8 Regression] " jakub at gcc dot gnu.org
2013-02-07 12:00 ` paolo.carlini at oracle dot com
2013-02-07 13:15 ` jakub at gcc dot gnu.org
2013-02-07 15:03 ` jason at gcc dot gnu.org
2013-02-07 17:51 ` jakub at gcc dot gnu.org
2013-02-07 17:55 ` [Bug c++/56239] [4.6/4.7 " jakub at gcc dot gnu.org
2013-02-19 17:23 ` jakub at gcc dot gnu.org
2013-02-19 17:40 ` [Bug c++/56239] [4.6 " jakub at gcc dot gnu.org
2013-04-03 18:21 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).