diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2013-10-04 23:17:51 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2013-10-04 23:17:51 +0000 |
commit | 12f64ca5e16915c6d6b0079b0286cc8e6066975b (patch) | |
tree | 9138155ba25bbedcf3f2d32906fbb306d4014e3f /gcc | |
parent | e36fae42ad580a61208c8c9bb82cc0b5964577b4 (diff) | |
download | gcc-12f64ca5e16915c6d6b0079b0286cc8e6066975b.zip gcc-12f64ca5e16915c6d6b0079b0286cc8e6066975b.tar.gz gcc-12f64ca5e16915c6d6b0079b0286cc8e6066975b.tar.bz2 |
re PR c++/58503 ([c++11] ICE with invalid range in range-based for-loop)
/cp
2013-10-04 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/58503
* parser.c (cp_parser_perform_range_for_lookup): If eventually
either *begin or *end is type-dependent, return NULL_TREE.
(do_range_for_auto_deduction): If cp_parser_perform_range_for_lookup
returns NULL_TREE, don't actually do_auto_deduction.
/testsuite
2013-10-04 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/58503
* g++.dg/cpp0x/range-for26.C: New.
* g++.dg/cpp0x/range-for27.C: Likewise.
From-SVN: r203219
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/parser.c | 19 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/range-for26.C | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/range-for27.C | 15 |
5 files changed, 50 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 571d4ed..88e5078 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,13 @@ 2013-10-04 Paolo Carlini <paolo.carlini@oracle.com> + PR c++/58503 + * parser.c (cp_parser_perform_range_for_lookup): If eventually + either *begin or *end is type-dependent, return NULL_TREE. + (do_range_for_auto_deduction): If cp_parser_perform_range_for_lookup + returns NULL_TREE, don't actually do_auto_deduction. + +2013-10-04 Paolo Carlini <paolo.carlini@oracle.com> + PR c++/58448 * pt.c (tsubst): Use error_operand_p on parameter t. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 1a9d6b9..90c1775 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -9960,11 +9960,15 @@ do_range_for_auto_deduction (tree decl, tree range_expr) range_temp = convert_from_reference (build_range_temp (range_expr)); iter_type = (cp_parser_perform_range_for_lookup (range_temp, &begin_dummy, &end_dummy)); - iter_decl = build_decl (input_location, VAR_DECL, NULL_TREE, iter_type); - iter_decl = build_x_indirect_ref (input_location, iter_decl, RO_NULL, - tf_warning_or_error); - TREE_TYPE (decl) = do_auto_deduction (TREE_TYPE (decl), - iter_decl, auto_node); + if (iter_type) + { + iter_decl = build_decl (input_location, VAR_DECL, NULL_TREE, + iter_type); + iter_decl = build_x_indirect_ref (input_location, iter_decl, RO_NULL, + tf_warning_or_error); + TREE_TYPE (decl) = do_auto_deduction (TREE_TYPE (decl), + iter_decl, auto_node); + } } } @@ -10171,6 +10175,11 @@ cp_parser_perform_range_for_lookup (tree range, tree *begin, tree *end) *begin = *end = error_mark_node; return error_mark_node; } + else if (type_dependent_expression_p (*begin) + || type_dependent_expression_p (*end)) + /* Can happen, when, eg, in a template context, Koenig lookup + can't resolve begin/end (c++/58503). */ + return NULL_TREE; else { tree iter_type = cv_unqualified (TREE_TYPE (*begin)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dd34bc6..68d415e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2013-10-04 Paolo Carlini <paolo.carlini@oracle.com> + PR c++/58503 + * g++.dg/cpp0x/range-for26.C: New. + * g++.dg/cpp0x/range-for27.C: Likewise. + +2013-10-04 Paolo Carlini <paolo.carlini@oracle.com> + PR c++/58448 * g++.dg/template/crash117.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for26.C b/gcc/testsuite/g++.dg/cpp0x/range-for26.C new file mode 100644 index 0000000..71359cd --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/range-for26.C @@ -0,0 +1,7 @@ +// PR c++/58503 +// { dg-require-effective-target c++11 } + +template<int> void foo() +{ + for (auto i : 0) {} // { dg-error "there are no arguments" } +} diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for27.C b/gcc/testsuite/g++.dg/cpp0x/range-for27.C new file mode 100644 index 0000000..a9cfb8e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/range-for27.C @@ -0,0 +1,15 @@ +// PR c++/58503 +// { dg-require-effective-target c++11 } +// { dg-options "-fpermissive -w" } + +struct c { }; + +template<int> void foo() +{ + for (auto i : c()) { } +} + +c* begin(const c&); +c* end(const c&); + +template void foo<1>(); |