We should call complete_type before deciding that a type can't be completed.
Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
commit a0f9f1db9cb900ac3ab2aa1e61bc51616b4d2be4 Author: Jason Merrill <ja...@redhat.com> Date: Tue May 14 11:50:26 2013 -0400 PR c++/57243 * parser.c (cp_parser_range_for): Call complete_type. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index f65ec97..0a075b2 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -9735,7 +9735,7 @@ cp_parser_range_for (cp_parser *parser, tree scope, tree init, tree range_decl) if (range_expr != error_mark_node && !type_dependent_expression_p (range_expr) /* The length of an array might be dependent. */ - && COMPLETE_TYPE_P (TREE_TYPE (range_expr)) + && COMPLETE_TYPE_P (complete_type (TREE_TYPE (range_expr))) /* do_auto_deduction doesn't mess with template init-lists. */ && !BRACE_ENCLOSED_INITIALIZER_P (range_expr)) do_range_for_auto_deduction (range_decl, range_expr); diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for25.C b/gcc/testsuite/g++.dg/cpp0x/range-for25.C new file mode 100644 index 0000000..8ba9f65 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/range-for25.C @@ -0,0 +1,30 @@ +// PR c++/57243 +// { dg-require-effective-target c++11 } + +struct snarf +{ + template <class T> + void get() {} +}; + +template <class T> +struct container +{ + snarf * begin() { return nullptr; } + snarf * end() { return nullptr; } +}; + +template <class T> +void foo() +{ + container<int> arr; + + for( auto i : arr ) + i.get<int>(); +} + +int main() +{ + return 0; +} +