This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fix c++/16012


When processing templates, we don't expand cleanups yet, and so
don't have the kinds of problems that we do later.  Also, putting
the decl in the FOR_INIT_STMT is necessary so that when expanding
the template later, the decl gets put into the proper scope.


r~


        PR c++/16012
        * semantics.c (begin_for_stmt, begin_for_stmt): Do put the init
        statement in FOR_INIT_STMT for templates.

Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.397
diff -c -p -d -r1.397 semantics.c
*** cp/semantics.c	16 Jun 2004 01:21:35 -0000	1.397
--- cp/semantics.c	16 Jun 2004 17:54:57 -0000
*************** begin_for_stmt (void)
*** 652,657 ****
--- 652,660 ----
    if (flag_new_for_scope > 0)
      TREE_CHAIN (r) = do_pushlevel (sk_for);
  
+   if (processing_template_decl)
+     FOR_INIT_STMT (r) = push_stmt_list ();
+ 
    return r;
  }
  
*************** begin_for_stmt (void)
*** 661,666 ****
--- 664,671 ----
  void
  finish_for_init_stmt (tree for_stmt)
  {
+   if (processing_template_decl)
+     FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
    add_stmt (for_stmt);
    FOR_BODY (for_stmt) = do_pushlevel (sk_block);
    FOR_COND (for_stmt) = push_stmt_list ();
Index: testsuite/g++.dg/init/for2.C
===================================================================
RCS file: testsuite/g++.dg/init/for2.C
diff -N testsuite/g++.dg/init/for2.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/for2.C	16 Jun 2004 17:54:57 -0000
***************
*** 0 ****
--- 1,13 ----
+ // { dg-do compile }
+ // PR 16012: Got the scope of I incorrect in templates only.
+ 
+ template<int> void foo()
+ {
+    for (int i=0 ;;) ;
+    int i;
+ }
+ 
+ void bar()
+ {
+   foo<0>();
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]