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]

Re: [C++0x patch] implement range-based for loops


On 08/23/2010 07:22 AM, Rodrigo Rivas wrote:
With templates it crashes badly. I've been working on it without success (yet),
but I've added a temporary warning.
My problem was that the koenig lookup of the "begin" function does not
work if the argument is a template dependent name. It would be nice to be able to do:
     begin = create_temporary_var (make_auto ());
But that does not work.
Anyway, that would be wrong because the behavior should be different
if the range is an array, and we don't know that until instantiation.
I'd bet that I need to modify the "tsubst_expr()" function, but any
hint is welcome.

Right. In a template, rather than call cp_finish_range_based_for, you should just build up a RANGE_FOR_STMT with the decl and expr as operands; then in tsubst_expr you handle RANGE_FOR_STMT by substituting the template arguments into those operands as appropriate and calling cp_finish_range_based_for then.


You probably also want to refactor the code a bit so that for a range-based for you don't pass the FOR_STMT into cp_finish_range_based_for, you call begin_for_stmt inside that function.

Jason


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