summaryrefslogtreecommitdiffstats
path: root/test/CXX
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2018-09-24 23:17:44 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2018-09-24 23:17:44 +0000
commit1a2d5c6f5a7fb4f5b88fbc821c39e7e4485464c7 (patch)
treea73805064fa4fa1e4ca415b18fd1cf4a5f1d2cd1 /test/CXX
parent252ecba16a1694e520ca44a2cb065e7899786fbf (diff)
P0962R1: only use the member form of 'begin' and 'end' in a range-based
for loop if both members exist. This resolves a DR whereby an errant 'begin' or 'end' member in a base class could result in a derived class not being usable as a range with non-member 'begin' and 'end'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342925 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX')
-rw-r--r--test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp59
1 files changed, 57 insertions, 2 deletions
diff --git a/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp b/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
index 473c8b62ba..f42fc9b6e5 100644
--- a/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
+++ b/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
@@ -150,9 +150,9 @@ void g() {
struct NoEnd {
null_t begin();
};
- for (auto u : NoBegin()) { // expected-error {{range type 'NoBegin' has 'end' member but no 'begin' member}}
+ for (auto u : NoBegin()) { // expected-error {{no viable 'begin' function available}}
}
- for (auto u : NoEnd()) { // expected-error {{range type 'NoEnd' has 'begin' member but no 'end' member}}
+ for (auto u : NoEnd()) { // expected-error {{no viable 'end' function available}}
}
struct NoIncr {
@@ -271,3 +271,58 @@ namespace rdar13712739 {
template void foo(const int&); // expected-note{{in instantiation of function template specialization}}
}
+
+namespace p0962r1 {
+ namespace NA {
+ struct A {
+ void begin();
+ };
+ int *begin(A);
+ int *end(A);
+ }
+
+ namespace NB {
+ struct B {
+ void end();
+ };
+ int *begin(B);
+ int *end(B);
+ }
+
+ namespace NC {
+ struct C {
+ void begin();
+ };
+ int *begin(C);
+ }
+
+ namespace ND {
+ struct D {
+ void end();
+ };
+ int *end(D);
+ }
+
+ namespace NE {
+ struct E {
+ void begin(); // expected-note {{member is not a candidate because range type 'p0962r1::NE::E' has no 'end' member}}
+ };
+ int *end(E);
+ }
+
+ namespace NF {
+ struct F {
+ void end(); // expected-note {{member is not a candidate because range type 'p0962r1::NF::F' has no 'begin' member}}
+ };
+ int *begin(F);
+ }
+
+ void use(NA::A a, NB::B b, NC::C c, ND::D d, NE::E e, NF::F f) {
+ for (auto x : a) {}
+ for (auto x : b) {}
+ for (auto x : c) {} // expected-error {{no viable 'end' function}}
+ for (auto x : d) {} // expected-error {{no viable 'begin' function}}
+ for (auto x : e) {} // expected-error {{no viable 'begin' function}}
+ for (auto x : f) {} // expected-error {{no viable 'end' function}}
+ }
+}