Adding failing LoopConvert testcase
authorEdwin Vane <edwin.vane@intel.com>
Mon, 4 Mar 2013 16:56:04 +0000 (16:56 +0000)
committerEdwin Vane <edwin.vane@intel.com>
Mon, 4 Mar 2013 16:56:04 +0000 (16:56 +0000)
LoopConvert isn't properly handling iterators whose dereference operator
returns by value. This test case demonstrates the failure.

See PR15437.

llvm-svn: 176437

clang-tools-extra/test/cpp11-migrate/LoopConvert/Inputs/structures.h
clang-tools-extra/test/cpp11-migrate/LoopConvert/iterator_failing.cpp [new file with mode: 0644]

index 2507b34..3379b05 100644 (file)
@@ -137,4 +137,17 @@ struct Nested {
   iterator end();
 };
 
+// Like llvm::SmallPtrSet, the iterator has a dereference operator that returns
+// by value instead of by reference.
+template <typename T>
+struct PtrSet {
+  struct iterator {
+    bool operator!=(const iterator &other) const;
+    const T operator*();
+    iterator &operator++();
+  };
+  iterator begin() const;
+  iterator end() const;
+};
+
 #endif  // STRUCTURES_H
diff --git a/clang-tools-extra/test/cpp11-migrate/LoopConvert/iterator_failing.cpp b/clang-tools-extra/test/cpp11-migrate/LoopConvert/iterator_failing.cpp
new file mode 100644 (file)
index 0000000..5684497
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -loop-convert %t.cpp -- -I %S/Inputs
+// RUN: FileCheck -input-file=%t.cpp %s
+// XFAIL: *
+#include "structures.h"
+
+void f() {
+  // See PR15437 for details.
+  PtrSet<int*> int_ptrs;
+  for (PtrSet<int*>::iterator I = int_ptrs.begin(),
+       E = int_ptrs.end(); I != E; ++I) {
+    // CHECK: for (const auto & int_ptr : int_ptrs) {
+  }
+}