Commit c1120b0c by Jason Merrill Committed by Jason Merrill

Core 898

	Core 898
	* parser.c (cp_parser_compound_statement): Add function_body parm.
	Complain about non-body compound-stmt in constexpr fn.
	(cp_parser_primary_expression, cp_parser_statement): Adjust.
	(cp_parser_implicitly_scoped_statement): Adjust.
	(cp_parser_function_body, cp_parser_try_block): Adjust.
	(cp_parser_handler, cp_parser_objc_synchronized_statement): Adjust.
	(cp_parser_objc_try_catch_finally_statement): Adjust.

From-SVN: r171612
parent 62add5e1
2011-03-28 Jason Merrill <jason@redhat.com> 2011-03-28 Jason Merrill <jason@redhat.com>
Core 898 Core 898
* parser.c (cp_parser_compound_statement): Add function_body parm.
Complain about non-body compound-stmt in constexpr fn.
(cp_parser_primary_expression, cp_parser_statement): Adjust.
(cp_parser_implicitly_scoped_statement): Adjust.
(cp_parser_function_body, cp_parser_try_block): Adjust.
(cp_parser_handler, cp_parser_objc_synchronized_statement): Adjust.
(cp_parser_objc_try_catch_finally_statement): Adjust.
Core 898
* semantics.c (constexpr_fn_retval): New. Allow using-declaration * semantics.c (constexpr_fn_retval): New. Allow using-declaration
and using-definition. and using-definition.
(register_constexpr_fundef): Call it. (register_constexpr_fundef): Call it.
......
...@@ -1590,7 +1590,7 @@ static void cp_parser_label_for_labeled_statement ...@@ -1590,7 +1590,7 @@ static void cp_parser_label_for_labeled_statement
static tree cp_parser_expression_statement static tree cp_parser_expression_statement
(cp_parser *, tree); (cp_parser *, tree);
static tree cp_parser_compound_statement static tree cp_parser_compound_statement
(cp_parser *, tree, bool); (cp_parser *, tree, bool, bool);
static void cp_parser_statement_seq_opt static void cp_parser_statement_seq_opt
(cp_parser *, tree); (cp_parser *, tree);
static tree cp_parser_selection_statement static tree cp_parser_selection_statement
...@@ -3417,7 +3417,7 @@ cp_parser_primary_expression (cp_parser *parser, ...@@ -3417,7 +3417,7 @@ cp_parser_primary_expression (cp_parser *parser,
/* Start the statement-expression. */ /* Start the statement-expression. */
expr = begin_stmt_expr (); expr = begin_stmt_expr ();
/* Parse the compound-statement. */ /* Parse the compound-statement. */
cp_parser_compound_statement (parser, expr, false); cp_parser_compound_statement (parser, expr, false, false);
/* Finish up. */ /* Finish up. */
expr = finish_stmt_expr (expr, false); expr = finish_stmt_expr (expr, false);
} }
...@@ -7873,7 +7873,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, ...@@ -7873,7 +7873,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
} }
/* Anything that starts with a `{' must be a compound-statement. */ /* Anything that starts with a `{' must be a compound-statement. */
else if (token->type == CPP_OPEN_BRACE) else if (token->type == CPP_OPEN_BRACE)
statement = cp_parser_compound_statement (parser, NULL, false); statement = cp_parser_compound_statement (parser, NULL, false, false);
/* CPP_PRAGMA is a #pragma inside a function body, which constitutes /* CPP_PRAGMA is a #pragma inside a function body, which constitutes
a statement all its own. */ a statement all its own. */
else if (token->type == CPP_PRAGMA) else if (token->type == CPP_PRAGMA)
...@@ -8105,13 +8105,17 @@ cp_parser_expression_statement (cp_parser* parser, tree in_statement_expr) ...@@ -8105,13 +8105,17 @@ cp_parser_expression_statement (cp_parser* parser, tree in_statement_expr)
static tree static tree
cp_parser_compound_statement (cp_parser *parser, tree in_statement_expr, cp_parser_compound_statement (cp_parser *parser, tree in_statement_expr,
bool in_try) bool in_try, bool function_body)
{ {
tree compound_stmt; tree compound_stmt;
/* Consume the `{'. */ /* Consume the `{'. */
if (!cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE)) if (!cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
return error_mark_node; return error_mark_node;
if (DECL_DECLARED_CONSTEXPR_P (current_function_decl)
&& !function_body)
pedwarn (input_location, OPT_pedantic,
"compound-statement in constexpr function");
/* Begin the compound-statement. */ /* Begin the compound-statement. */
compound_stmt = begin_compound_stmt (in_try ? BCS_TRY_BLOCK : 0); compound_stmt = begin_compound_stmt (in_try ? BCS_TRY_BLOCK : 0);
/* If the next keyword is `__label__' we have a label declaration. */ /* If the next keyword is `__label__' we have a label declaration. */
...@@ -9022,7 +9026,7 @@ cp_parser_implicitly_scoped_statement (cp_parser* parser, bool *if_p) ...@@ -9022,7 +9026,7 @@ cp_parser_implicitly_scoped_statement (cp_parser* parser, bool *if_p)
} }
/* if a compound is opened, we simply parse the statement directly. */ /* if a compound is opened, we simply parse the statement directly. */
else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)) else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
statement = cp_parser_compound_statement (parser, NULL, false); statement = cp_parser_compound_statement (parser, NULL, false, false);
/* If the token is not a `{', then we must take special action. */ /* If the token is not a `{', then we must take special action. */
else else
{ {
...@@ -16157,7 +16161,7 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p) ...@@ -16157,7 +16161,7 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p)
static void static void
cp_parser_function_body (cp_parser *parser) cp_parser_function_body (cp_parser *parser)
{ {
cp_parser_compound_statement (parser, NULL, false); cp_parser_compound_statement (parser, NULL, false, true);
} }
/* Parse a ctor-initializer-opt followed by a function-body. Return /* Parse a ctor-initializer-opt followed by a function-body. Return
...@@ -18255,7 +18259,7 @@ cp_parser_try_block (cp_parser* parser) ...@@ -18255,7 +18259,7 @@ cp_parser_try_block (cp_parser* parser)
cp_parser_require_keyword (parser, RID_TRY, RT_TRY); cp_parser_require_keyword (parser, RID_TRY, RT_TRY);
try_block = begin_try_block (); try_block = begin_try_block ();
cp_parser_compound_statement (parser, NULL, true); cp_parser_compound_statement (parser, NULL, true, false);
finish_try_block (try_block); finish_try_block (try_block);
cp_parser_handler_seq (parser); cp_parser_handler_seq (parser);
finish_handler_sequence (try_block); finish_handler_sequence (try_block);
...@@ -18332,7 +18336,7 @@ cp_parser_handler (cp_parser* parser) ...@@ -18332,7 +18336,7 @@ cp_parser_handler (cp_parser* parser)
declaration = cp_parser_exception_declaration (parser); declaration = cp_parser_exception_declaration (parser);
finish_handler_parms (declaration, handler); finish_handler_parms (declaration, handler);
cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN); cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
cp_parser_compound_statement (parser, NULL, false); cp_parser_compound_statement (parser, NULL, false, false);
finish_handler (handler); finish_handler (handler);
} }
...@@ -22533,7 +22537,7 @@ cp_parser_objc_try_catch_finally_statement (cp_parser *parser) ...@@ -22533,7 +22537,7 @@ cp_parser_objc_try_catch_finally_statement (cp_parser *parser)
/* NB: The @try block needs to be wrapped in its own STATEMENT_LIST /* NB: The @try block needs to be wrapped in its own STATEMENT_LIST
node, lest it get absorbed into the surrounding block. */ node, lest it get absorbed into the surrounding block. */
stmt = push_stmt_list (); stmt = push_stmt_list ();
cp_parser_compound_statement (parser, NULL, false); cp_parser_compound_statement (parser, NULL, false, false);
objc_begin_try_stmt (location, pop_stmt_list (stmt)); objc_begin_try_stmt (location, pop_stmt_list (stmt));
while (cp_lexer_next_token_is_keyword (parser->lexer, RID_AT_CATCH)) while (cp_lexer_next_token_is_keyword (parser->lexer, RID_AT_CATCH))
...@@ -22589,7 +22593,7 @@ cp_parser_objc_try_catch_finally_statement (cp_parser *parser) ...@@ -22589,7 +22593,7 @@ cp_parser_objc_try_catch_finally_statement (cp_parser *parser)
forget about the closing parenthesis and keep going. */ forget about the closing parenthesis and keep going. */
} }
objc_begin_catch_clause (parameter_declaration); objc_begin_catch_clause (parameter_declaration);
cp_parser_compound_statement (parser, NULL, false); cp_parser_compound_statement (parser, NULL, false, false);
objc_finish_catch_clause (); objc_finish_catch_clause ();
} }
if (cp_lexer_next_token_is_keyword (parser->lexer, RID_AT_FINALLY)) if (cp_lexer_next_token_is_keyword (parser->lexer, RID_AT_FINALLY))
...@@ -22599,7 +22603,7 @@ cp_parser_objc_try_catch_finally_statement (cp_parser *parser) ...@@ -22599,7 +22603,7 @@ cp_parser_objc_try_catch_finally_statement (cp_parser *parser)
/* NB: The @finally block needs to be wrapped in its own STATEMENT_LIST /* NB: The @finally block needs to be wrapped in its own STATEMENT_LIST
node, lest it get absorbed into the surrounding block. */ node, lest it get absorbed into the surrounding block. */
stmt = push_stmt_list (); stmt = push_stmt_list ();
cp_parser_compound_statement (parser, NULL, false); cp_parser_compound_statement (parser, NULL, false, false);
objc_build_finally_clause (location, pop_stmt_list (stmt)); objc_build_finally_clause (location, pop_stmt_list (stmt));
} }
...@@ -22630,7 +22634,7 @@ cp_parser_objc_synchronized_statement (cp_parser *parser) ...@@ -22630,7 +22634,7 @@ cp_parser_objc_synchronized_statement (cp_parser *parser)
/* NB: The @synchronized block needs to be wrapped in its own STATEMENT_LIST /* NB: The @synchronized block needs to be wrapped in its own STATEMENT_LIST
node, lest it get absorbed into the surrounding block. */ node, lest it get absorbed into the surrounding block. */
stmt = push_stmt_list (); stmt = push_stmt_list ();
cp_parser_compound_statement (parser, NULL, false); cp_parser_compound_statement (parser, NULL, false, false);
return objc_build_synchronized (location, lock, pop_stmt_list (stmt)); return objc_build_synchronized (location, lock, pop_stmt_list (stmt));
} }
......
2011-03-28 Jason Merrill <jason@redhat.com> 2011-03-28 Jason Merrill <jason@redhat.com>
* g++.dg/cpp0x/constexpr-compound.C: New.
* g++.dg/cpp0x/constexpr-using.C: New. * g++.dg/cpp0x/constexpr-using.C: New.
* g++.dg/cpp0x/constexpr-noexcept.C: New. * g++.dg/cpp0x/constexpr-noexcept.C: New.
......
// { dg-options "-std=c++0x -pedantic-errors" }
constexpr int f()
{
{ // { dg-error "" }
return 1;
}
{ } // { dg-error "" }
}
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