summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/cpp11-migrate
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-04-01 18:15:06 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-04-01 18:15:06 +0000
commit61af48ce4ed83cae9520c417eb22ef17a7c177b9 (patch)
tree98c52ada711f10d4e7eb9a292e4a59163fd92899 /clang-tools-extra/test/cpp11-migrate
parent6662fd0f1558988bec57a94158dd4d67f3d8e177 (diff)
downloadbcm5719-llvm-61af48ce4ed83cae9520c417eb22ef17a7c177b9.tar.gz
bcm5719-llvm-61af48ce4ed83cae9520c417eb22ef17a7c177b9.zip
Improve loop convert's variable aliasing
Loop convert's variable name aliasing may cause issues if the variable is declared as a value (copy). The converted loop will declare the variable as a reference which may inadvertently cause modifications to the container if it were used and modified as a temporary copy. This is fixed by preserving the reference or value qualifiers of the aliased variable. That is, if the variable was declared as a value the loop variable will also be declared as a value and similarly for references. Fixes: PR15600 Author: Jack Yang <jack.yang@intel.com> llvm-svn: 178485
Diffstat (limited to 'clang-tools-extra/test/cpp11-migrate')
-rw-r--r--clang-tools-extra/test/cpp11-migrate/LoopConvert/naming-alias.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/clang-tools-extra/test/cpp11-migrate/LoopConvert/naming-alias.cpp b/clang-tools-extra/test/cpp11-migrate/LoopConvert/naming-alias.cpp
index 89485059f76..0373d2b7473 100644
--- a/clang-tools-extra/test/cpp11-migrate/LoopConvert/naming-alias.cpp
+++ b/clang-tools-extra/test/cpp11-migrate/LoopConvert/naming-alias.cpp
@@ -57,3 +57,40 @@ void aliasing() {
// CHECK-NEXT: Val &t = func(elem);
// CHECK-NEXT: int y = t.x;
}
+
+void refs_and_vals() {
+ // The following tests check that the transform correctly preserves the
+ // reference or value qualifiers of the aliased variable. That is, if the
+ // variable was declared as a value, the loop variable will be declared as a
+ // value and vice versa for references.
+
+ S s;
+ const S s_const = s;
+
+ for (S::const_iterator it = s_const.begin(); it != s_const.end(); ++it) {
+ MutableVal alias = *it; { }
+ alias.x = 0;
+ }
+ // CHECK: for (auto alias : s_const)
+ // CHECK-NOT: MutableVal {{[a-z_]+}} =
+ // CHECK-NEXT: { }
+ // CHECK-NEXT: alias.x = 0;
+
+ for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) {
+ MutableVal alias = *it; { }
+ alias.x = 0;
+ }
+ // CHECK: for (auto alias : s)
+ // CHECK-NOT: MutableVal {{[a-z_]+}} =
+ // CHECK-NEXT: { }
+ // CHECK-NEXT: alias.x = 0;
+
+ for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) {
+ MutableVal &alias = *it; { }
+ alias.x = 0;
+ }
+ // CHECK: for (auto & alias : s)
+ // CHECK-NOT: MutableVal &{{[a-z_]+}} =
+ // CHECK-NEXT: { }
+ // CHECK-NEXT: alias.x = 0;
+}
OpenPOWER on IntegriCloud