Skip to content

Commit d61fac4

Browse files
author
ville
committed
Implement P0962
* parser.c (cp_parser_perform_range_for_lookup): Change the condition for deciding whether to use members. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@258803 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 465749f commit d61fac4

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

gcc/cp/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2018-03-23 Ville Voutilainen <[email protected]>
2+
3+
Implement P0962
4+
* parser.c (cp_parser_perform_range_for_lookup): Change
5+
the condition for deciding whether to use members.
6+
17
2018-03-23 Marek Polacek <[email protected]>
28

39
PR c++/85033

gcc/cp/parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12048,7 +12048,7 @@ cp_parser_perform_range_for_lookup (tree range, tree *begin, tree *end)
1204812048
/*protect=*/2, /*want_type=*/false,
1204912049
tf_warning_or_error);
1205012050

12051-
if (member_begin != NULL_TREE || member_end != NULL_TREE)
12051+
if (member_begin != NULL_TREE && member_end != NULL_TREE)
1205212052
{
1205312053
/* Use the member functions. */
1205412054
if (member_begin != NULL_TREE)

gcc/testsuite/g++.dg/cpp0x/range-for13.C

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33

44
// { dg-do compile { target c++11 } }
55

6-
//These should not be used
7-
template<typename T> int *begin(T &t)
8-
{
9-
T::fail;
10-
return 0;
11-
}
12-
template<typename T> int *end(T &t)
13-
{
14-
T::fail;
15-
return 0;
16-
}
17-
186
struct container1
197
{
208
int *begin();
@@ -89,10 +77,37 @@ struct container10
8977
static function end;
9078
};
9179

80+
namespace N
81+
{
82+
template<typename T> int *begin(T &t)
83+
{
84+
return 0;
85+
}
86+
template<typename T> int *end(T &t)
87+
{
88+
return 0;
89+
}
90+
struct container11
91+
{
92+
int *begin();
93+
//no end
94+
};
95+
96+
struct container12
97+
{
98+
int *end();
99+
//no begin
100+
};
101+
102+
struct container13
103+
{
104+
};
105+
}
106+
92107
void test1()
93108
{
94-
for (int x : container1()); // { dg-error "member but not" }
95-
for (int x : container2()); // { dg-error "member but not" }
109+
for (int x : container1()); // { dg-error "'begin' was not declared|'end' was not declared" }
110+
for (int x : container2()); // { dg-error "'begin' was not declared|'end' was not declared" }
96111
for (int x : container3()); // { dg-error "within this context" }
97112
for (int x : container4()); // { dg-error "cannot be used as a function" }
98113
for (int x : container5()); // { dg-error "invalid use of" }
@@ -101,4 +116,7 @@ void test1()
101116
for (int x : container8());
102117
for (int x : container9()); // { dg-error "within this context" }
103118
for (int x : container10());
119+
for (int x : N::container11());
120+
for (int x : N::container12());
121+
for (int x : N::container13());
104122
}

0 commit comments

Comments
 (0)