Commit 3f43ac31 by Rodrigo Rivas Costa Committed by Jason Merrill

cp-tree.h (begin_for_scope): New prototype.

	* cp-tree.h (begin_for_scope): New prototype.
	(begin_for_stmt): Update prototype.
	(begin_range_for_stmt): Update prototype.
	* init.c (build_vec_init): Update call to begin_for_stmt.
	* parser.c (cp_parser_for): New.
	(cp_parser_c_for): Add three new parameters.
	(cp_parser_range_for): Likewise. Most parsing code removed.
	(cp_parser_iteration_statement): Call cp_parser_for instead of
	cp_parser_c_for and cp_parser_range_for.
	(cp_parser_for_init_statement): Add new parameter and return type.
	(cp_parser_block_declaration): Update call to
	cp_parser_simple_declaration.
	(cp_parser_simple_declaration): Add new parameter.
	Update call to cp_parser_init_declarator.
	(cp_parser_init_declarator): Add new parameter.
	* pt.c (tsubst_expr): Update call to begin_for_stmt.
	* semantics.c (begin_for_scope): New.
	(begin_for_stmt): Add two new parameters.
	(begin_range_for_stmt): Likewise.

From-SVN: r168731
parent c7aca2ff
2011-01-12 Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>
* cp-tree.h (begin_for_scope): New prototype.
(begin_for_stmt): Update prototype.
(begin_range_for_stmt): Update prototype.
* init.c (build_vec_init): Update call to begin_for_stmt.
* parser.c (cp_parser_for): New.
(cp_parser_c_for): Add three new parameters.
(cp_parser_range_for): Likewise. Most parsing code removed.
(cp_parser_iteration_statement): Call cp_parser_for instead of
cp_parser_c_for and cp_parser_range_for.
(cp_parser_for_init_statement): Add new parameter and return type.
(cp_parser_block_declaration): Update call to
cp_parser_simple_declaration.
(cp_parser_simple_declaration): Add new parameter.
Update call to cp_parser_init_declarator.
(cp_parser_init_declarator): Add new parameter.
* pt.c (tsubst_expr): Update call to begin_for_stmt.
* semantics.c (begin_for_scope): New.
(begin_for_stmt): Add two new parameters.
(begin_range_for_stmt): Likewise.
2011-01-12 Nicola Pero <nicola.pero@meta-innovation.com>
* parser.c (cp_parser_objc_at_property_declaration): Improved
......
......@@ -5214,12 +5214,13 @@ extern tree begin_do_stmt (void);
extern void finish_do_body (tree);
extern void finish_do_stmt (tree, tree);
extern tree finish_return_stmt (tree);
extern tree begin_for_stmt (void);
extern tree begin_for_scope (tree *);
extern tree begin_for_stmt (tree, tree);
extern void finish_for_init_stmt (tree);
extern void finish_for_cond (tree, tree);
extern void finish_for_expr (tree, tree);
extern void finish_for_stmt (tree);
extern tree begin_range_for_stmt (void);
extern tree begin_range_for_stmt (tree, tree);
extern void finish_range_for_decl (tree, tree, tree);
extern void finish_range_for_stmt (tree);
extern tree finish_break_stmt (void);
......
......@@ -3125,7 +3125,7 @@ build_vec_init (tree base, tree maxindex, tree init,
tree elt_init;
tree to;
for_stmt = begin_for_stmt ();
for_stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
finish_for_init_stmt (for_stmt);
finish_for_cond (build2 (NE_EXPR, boolean_type_node, iterator,
build_int_cst (TREE_TYPE (iterator), -1)),
......
......@@ -12052,7 +12052,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
}
case FOR_STMT:
stmt = begin_for_stmt ();
stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
RECUR (FOR_INIT_STMT (t));
finish_for_init_stmt (stmt);
tmp = RECUR (FOR_COND (t));
......@@ -12066,7 +12066,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
case RANGE_FOR_STMT:
{
tree decl, expr;
stmt = begin_for_stmt ();
stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
decl = RANGE_FOR_DECL (t);
decl = tsubst (decl, args, complain, in_decl);
maybe_push_decl (decl);
......
......@@ -827,21 +827,44 @@ finish_return_stmt (tree expr)
return r;
}
/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
/* Begin the scope of a for-statement or a range-for-statement.
Both the returned trees are to be used in a call to
begin_for_stmt or begin_range_for_stmt. */
tree
begin_for_stmt (void)
begin_for_scope (tree *init)
{
tree scope = NULL_TREE;
if (flag_new_for_scope > 0)
scope = do_pushlevel (sk_for);
if (processing_template_decl)
*init = push_stmt_list ();
else
*init = NULL_TREE;
return scope;
}
/* Begin a for-statement. Returns a new FOR_STMT.
SCOPE and INIT should be the return of begin_for_scope,
or both NULL_TREE */
tree
begin_for_stmt (tree scope, tree init)
{
tree r;
r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
NULL_TREE, NULL_TREE);
if (flag_new_for_scope > 0)
TREE_CHAIN (r) = do_pushlevel (sk_for);
if (processing_template_decl)
FOR_INIT_STMT (r) = push_stmt_list ();
if (scope == NULL_TREE)
{
gcc_assert (!init);
scope = begin_for_scope (&init);
}
FOR_INIT_STMT (r) = init;
TREE_CHAIN (r) = scope;
return r;
}
......@@ -925,18 +948,29 @@ finish_for_stmt (tree for_stmt)
}
/* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
SCOPE and INIT should be the return of begin_for_scope,
or both NULL_TREE .
To finish it call finish_for_stmt(). */
tree
begin_range_for_stmt (void)
begin_range_for_stmt (tree scope, tree init)
{
tree r;
r = build_stmt (input_location, RANGE_FOR_STMT,
NULL_TREE, NULL_TREE, NULL_TREE);
if (flag_new_for_scope > 0)
TREE_CHAIN (r) = do_pushlevel (sk_for);
if (scope == NULL_TREE)
{
gcc_assert (!init);
scope = begin_for_scope (&init);
}
/* RANGE_FOR_STMTs do not use nor save the init tree, so we
pop it now. */
if (init)
pop_stmt_list (init);
TREE_CHAIN (r) = scope;
return r;
}
......
2011-01-12 Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>
* g++.dg/cpp0x/range-for4.C: Delete useless include and duplicated
comment.
* g++.dg/cpp0x/range-for8.C: New.
* g++.dg/cpp0x/range-for9.C: New.
2011-01-12 Kai Tietz <kai.tietz@onevision.com>
PR debug/47209
......
......@@ -3,8 +3,6 @@
// { dg-do run }
// { dg-options "-std=c++0x" }
#include <cstdio>
/* Preliminary declarations */
namespace pre
{
......@@ -48,7 +46,6 @@ container run_me_just_once()
}
/* Template with dependent expression. */
/* Template with dependent expression. */
template<typename T> int test1(const T &r)
{
int t = 0;
......
// Test for range-based for loop when the declarator declares
// a new type
// { dg-do compile }
// { dg-options "-std=c++0x" }
#include <initializer_list>
void test()
{
for (struct S { } *x : { (S*)0, (S*)0 } )
;
for (struct S { } x : { S(), S() } )
;
}
// Test for range-based for loop error in C++98 mode
// { dg-do compile }
// { dg-options "-std=c++98" }
void test()
{
int a[] = {0,1,2};
for (int x : a) // { dg-error "range-based-for" }
;
}
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