From: Ville Voutilainen Date: Fri, 23 Mar 2018 13:17:19 +0000 (+0200) Subject: Implement P0962 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=50531a2a1d82e41a39d0c85421b4e99802d6e349;p=gcc.git Implement P0962 * parser.c (cp_parser_perform_range_for_lookup): Change the condition for deciding whether to use members. From-SVN: r258803 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b7e2846c4b1..e04eae18a44 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-03-23 Ville Voutilainen + + Implement P0962 + * parser.c (cp_parser_perform_range_for_lookup): Change + the condition for deciding whether to use members. + 2018-03-23 Marek Polacek PR c++/85033 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 602cc991ff6..e946d0b7229 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -12048,7 +12048,7 @@ cp_parser_perform_range_for_lookup (tree range, tree *begin, tree *end) /*protect=*/2, /*want_type=*/false, tf_warning_or_error); - if (member_begin != NULL_TREE || member_end != NULL_TREE) + if (member_begin != NULL_TREE && member_end != NULL_TREE) { /* Use the member functions. */ if (member_begin != NULL_TREE) diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for13.C b/gcc/testsuite/g++.dg/cpp0x/range-for13.C index 9ed0458adcc..7babd713cfb 100644 --- a/gcc/testsuite/g++.dg/cpp0x/range-for13.C +++ b/gcc/testsuite/g++.dg/cpp0x/range-for13.C @@ -3,18 +3,6 @@ // { dg-do compile { target c++11 } } -//These should not be used -template int *begin(T &t) -{ - T::fail; - return 0; -} -template int *end(T &t) -{ - T::fail; - return 0; -} - struct container1 { int *begin(); @@ -89,10 +77,37 @@ struct container10 static function end; }; +namespace N +{ +template int *begin(T &t) +{ + return 0; +} +template int *end(T &t) +{ + return 0; +} +struct container11 +{ + int *begin(); + //no end +}; + +struct container12 +{ + int *end(); + //no begin +}; + +struct container13 +{ +}; +} + void test1() { - for (int x : container1()); // { dg-error "member but not" } - for (int x : container2()); // { dg-error "member but not" } + for (int x : container1()); // { dg-error "'begin' was not declared|'end' was not declared" } + for (int x : container2()); // { dg-error "'begin' was not declared|'end' was not declared" } for (int x : container3()); // { dg-error "within this context" } for (int x : container4()); // { dg-error "cannot be used as a function" } for (int x : container5()); // { dg-error "invalid use of" } @@ -101,4 +116,7 @@ void test1() for (int x : container8()); for (int x : container9()); // { dg-error "within this context" } for (int x : container10()); + for (int x : N::container11()); + for (int x : N::container12()); + for (int x : N::container13()); }