Edwin Vane b40bf83eab Transform for loops over pseudo-arrays only if begin/end members exist
For loops using pseudo-arrays, classes that can be used like arrays from
the Loop Convert Transform's point of view, should only get transformed
if the pseudo-array class has begin()/end() members for the
range-based for-loop to call.

Free versions of begin()/end() should also be allowed but this is an
enhancement for another revision.

llvm-svn: 181539
2013-05-09 20:03:52 +00:00

33 lines
798 B
C++

// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
// RUN: cpp11-migrate -loop-convert %t.cpp -- -I %S/Inputs -std=c++11
// RUN: FileCheck -input-file=%t.cpp %s
// XFAIL: *
struct MyArray {
unsigned size();
};
template <typename T>
struct MyContainer {
};
int *begin(const MyArray &Arr);
int *end(const MyArray &Arr);
template <typename T>
T *begin(const MyContainer<T> &C);
template <typename T>
T *end(const MyContainer<T> &C);
// The Loop Convert Transform doesn't detect free functions begin()/end() and
// so fails to transform these cases which it should.
void f() {
MyArray Arr;
for (unsigned i = 0, e = Arr.size(); i < e; ++i) {}
// CHECK: for (auto & elem : Arr) {}
MyContainer<int> C;
for (int *I = begin(C), *E = end(C); I != E; ++I) {}
// CHECK: for (auto & elem : C) {}
}