re PR c++/35158 (g++ does not compile valid C++ for loops with -fopenmp)

2008-08-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR c++/35158
cp/   
	* parser.c (cp_parser_omp_for_loop): Handle parenthesized
	initializers.
testsuite/
	* g++.dg/gomp/pr35158.C: New.

From-SVN: r139335
parent 9299a27c
2008-08-20 Manuel Lopez-Ibanez <manu@gcc.gnu.org> 2008-08-20 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/35158
* parser.c (cp_parser_omp_for_loop): Handle parenthesized
initializers.
2008-08-20 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* parser.c: Update all calls to inform. * parser.c: Update all calls to inform.
* typeck.c: Likewise. * typeck.c: Likewise.
* init.c: Likewise. * init.c: Likewise.
......
...@@ -20859,6 +20859,14 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses) ...@@ -20859,6 +20859,14 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
this_pre_body = push_stmt_list (); this_pre_body = push_stmt_list ();
if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON)) if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
{ {
/* See 2.5.1 (in OpenMP 3.0, similar wording is in 2.5 standard too):
init-expr:
var = lb
integer-type var = lb
random-access-iterator-type var = lb
pointer-type var = lb
*/
cp_decl_specifier_seq type_specifiers; cp_decl_specifier_seq type_specifiers;
/* First, try to parse as an initialized declaration. See /* First, try to parse as an initialized declaration. See
...@@ -20867,8 +20875,10 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses) ...@@ -20867,8 +20875,10 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
cp_parser_parse_tentatively (parser); cp_parser_parse_tentatively (parser);
cp_parser_type_specifier_seq (parser, /*is_condition=*/false, cp_parser_type_specifier_seq (parser, /*is_condition=*/false,
&type_specifiers); &type_specifiers);
if (!cp_parser_error_occurred (parser)) if (cp_parser_parse_definitely (parser))
{ {
/* If parsing a type specifier seq succeeded, then this
MUST be a initialized declaration. */
tree asm_specification, attributes; tree asm_specification, attributes;
cp_declarator *declarator; cp_declarator *declarator;
...@@ -20880,9 +20890,10 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses) ...@@ -20880,9 +20890,10 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
attributes = cp_parser_attributes_opt (parser); attributes = cp_parser_attributes_opt (parser);
asm_specification = cp_parser_asm_specification_opt (parser); asm_specification = cp_parser_asm_specification_opt (parser);
if (cp_lexer_next_token_is_not (parser->lexer, CPP_EQ)) if (declarator == cp_error_declarator)
cp_parser_require (parser, CPP_EQ, "%<=%>"); cp_parser_skip_to_end_of_statement (parser);
if (cp_parser_parse_definitely (parser))
else
{ {
tree pushed_scope; tree pushed_scope;
...@@ -20891,8 +20902,21 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses) ...@@ -20891,8 +20902,21 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
/*prefix_attributes=*/NULL_TREE, /*prefix_attributes=*/NULL_TREE,
&pushed_scope); &pushed_scope);
if (CLASS_TYPE_P (TREE_TYPE (decl)) if (cp_lexer_next_token_is_not (parser->lexer, CPP_EQ))
|| type_dependent_expression_p (decl)) {
if (cp_lexer_next_token_is (parser->lexer,
CPP_OPEN_PAREN))
error ("parenthesized initialization is not allowed in "
"OpenMP %<for%> loop");
else
/* Trigger an error. */
cp_parser_require (parser, CPP_EQ, "%<=%>");
init = error_mark_node;
cp_parser_skip_to_end_of_statement (parser);
}
else if (CLASS_TYPE_P (TREE_TYPE (decl))
|| type_dependent_expression_p (decl))
{ {
bool is_direct_init, is_non_constant_init; bool is_direct_init, is_non_constant_init;
...@@ -20915,7 +20939,8 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses) ...@@ -20915,7 +20939,8 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
} }
else else
{ {
cp_parser_require (parser, CPP_EQ, "%<=%>"); /* Consume '='. */
cp_lexer_consume_token (parser->lexer);
init = cp_parser_assignment_expression (parser, false); init = cp_parser_assignment_expression (parser, false);
if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE) if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE)
...@@ -20931,14 +20956,11 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses) ...@@ -20931,14 +20956,11 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
pop_scope (pushed_scope); pop_scope (pushed_scope);
} }
} }
else else
cp_parser_abort_tentative_parse (parser);
/* If parsing as an initialized declaration failed, try again as
a simple expression. */
if (decl == NULL)
{ {
cp_id_kind idk; cp_id_kind idk;
/* If parsing a type specifier sequence failed, then
this MUST be a simple expression. */
cp_parser_parse_tentatively (parser); cp_parser_parse_tentatively (parser);
decl = cp_parser_primary_expression (parser, false, false, decl = cp_parser_primary_expression (parser, false, false,
false, &idk); false, &idk);
......
2008-08-20 Manuel Lopez-Ibanez <manu@gcc.gnu.org> 2008-08-20 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/35158
* g++.dg/gomp/pr35158.C: New.
2008-08-20 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 35701 PR 35701
* gcc.dg/pr35701.c: New. * gcc.dg/pr35701.c: New.
* gcc.dg/Wconversion-real-integer.c: Add more tests. * gcc.dg/Wconversion-real-integer.c: Add more tests.
......
// PR c++/35158
// { dg-do compile }
// { dg-options "-fopenmp" }
int main(int argc, char *argv[])
{
#pragma omp parallel for
for (int i(0) ; // { dg-error "error: parenthesized initialization is not allowed in OpenMP 'for' loop" }
i < 10 ;
i++)
;
return 0;
}
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