Commit 2052ce24 by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/56239 (parse error calling operator() on parenthesized value-initialized temporary)

	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: r195859
parent e6d7b956
2013-02-07 Jakub Jelinek <jakub@redhat.com> 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.
PR c++/56237 PR c++/56237
* decl.c (push_local_name): Look at DECL_DISCRIMINATOR (t) * decl.c (push_local_name): Look at DECL_DISCRIMINATOR (t)
only if DECL_DISCRIMINATOR_SET_P (t) rather than just only if DECL_DISCRIMINATOR_SET_P (t) rather than just
......
...@@ -7091,8 +7091,9 @@ cp_parser_delete_expression (cp_parser* parser) ...@@ -7091,8 +7091,9 @@ cp_parser_delete_expression (cp_parser* parser)
otherwise. */ otherwise. */
static bool 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) switch (token->type)
{ {
case CPP_COMMA: case CPP_COMMA:
...@@ -7133,6 +7134,12 @@ cp_parser_token_starts_cast_expression (cp_token *token) ...@@ -7133,6 +7134,12 @@ cp_parser_token_starts_cast_expression (cp_token *token)
case CPP_EOF: case CPP_EOF:
return false; 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++. */ /* '[' may start a primary-expression in obj-c++. */
case CPP_OPEN_SQUARE: case CPP_OPEN_SQUARE:
return c_dialect_objc (); return c_dialect_objc ();
...@@ -7225,8 +7232,7 @@ cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p, ...@@ -7225,8 +7232,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 parenthesized ctor such as `(T ())' that looks like a cast to
function returning T. */ function returning T. */
if (!cp_parser_error_occurred (parser) if (!cp_parser_error_occurred (parser)
&& cp_parser_token_starts_cast_expression (cp_lexer_peek_token && cp_parser_tokens_start_cast_expression (parser))
(parser->lexer)))
{ {
cp_parser_parse_definitely (parser); cp_parser_parse_definitely (parser);
expr = cp_parser_cast_expression (parser, expr = cp_parser_cast_expression (parser,
......
2013-02-07 Jakub Jelinek <jakub@redhat.com> 2013-02-07 Jakub Jelinek <jakub@redhat.com>
PR c++/56239
* g++.dg/parse/pr56239.C: New test.
PR c++/56237 PR c++/56237
* g++.dg/abi/mangle61.C: New test. * g++.dg/abi/mangle61.C: New test.
......
// PR c++/56239
// { dg-do compile }
struct S
{
int operator () () { return 0; }
};
int
main ()
{
return (S ()) ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment