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

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).