summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/cpp11-migrate
diff options
context:
space:
mode:
authorAriel J. Bernal <ariel.j.bernal@intel.com>2013-05-27 14:30:23 +0000
committerAriel J. Bernal <ariel.j.bernal@intel.com>2013-05-27 14:30:23 +0000
commit1d66e366e96d9622bfdbc9a78383033e89a808b4 (patch)
tree9b824706f102e8c9fcdb575c48a2a22442bdf9c9 /clang-tools-extra/test/cpp11-migrate
parentb97e89691d359457a5f25add6dc79229703c8296 (diff)
downloadbcm5719-llvm-1d66e366e96d9622bfdbc9a78383033e89a808b4.tar.gz
bcm5719-llvm-1d66e366e96d9622bfdbc9a78383033e89a808b4.zip
Fix UseAuto replacing declaration lists with new expressions
UseAuto used to replace declarion lists with new expressons where some variable were not initialized with new. This fix checks that every DeclStmt has a VarDecl with an initializer and it also ensures that all declarations have the same type. Added tests for multiple declarations and for typedefs. llvm-svn: 182736
Diffstat (limited to 'clang-tools-extra/test/cpp11-migrate')
-rw-r--r--clang-tools-extra/test/cpp11-migrate/UseAuto/new.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/clang-tools-extra/test/cpp11-migrate/UseAuto/new.cpp b/clang-tools-extra/test/cpp11-migrate/UseAuto/new.cpp
index 911c0cd76bd..3fca05df29b 100644
--- a/clang-tools-extra/test/cpp11-migrate/UseAuto/new.cpp
+++ b/clang-tools-extra/test/cpp11-migrate/UseAuto/new.cpp
@@ -49,4 +49,49 @@ int main(int argc, char **argv) {
MyType *g{new MyType};
// CHECK: MyType *g{new MyType};
+
+ // Test for declaration lists.
+ {
+ MyType *a = new MyType(), *b = new MyType(), *c = new MyType();
+ // CHECK: auto a = new MyType(), b = new MyType(), c = new MyType();
+
+ // Non-initialized declaration should not be transformed.
+ MyType *d = new MyType(), *e;
+ // CHECK: MyType *d = new MyType(), *e;
+
+ MyType **f = new MyType*(), **g = new MyType*();
+ // CHECK: auto f = new MyType*(), g = new MyType*();
+
+ // Mismatching types in declaration lists should not be transformed.
+ MyType *h = new MyType(), **i = new MyType*();
+ // CHECK: MyType *h = new MyType(), **i = new MyType*();
+
+ // '*' shouldn't be removed in case of mismatching types with multiple
+ // declarations.
+ MyType *j = new MyType(), *k = new MyType(), **l = new MyType*();
+ // CHECK: MyType *j = new MyType(), *k = new MyType(), **l = new MyType*();
+ }
+
+ // Test for typedefs.
+ {
+ typedef int * int_p;
+
+ int_p a = new int;
+ // CHECK: auto a = new int;
+ int_p *b = new int*;
+ // CHECK: auto b = new int*;
+
+ // Test for typedefs in declarations lists.
+ int_p c = new int, d = new int;
+ // CHECK: auto c = new int, d = new int;
+
+ // Different types should not be transformed.
+ int_p e = new int, *f = new int_p;
+ // CHECK: int_p e = new int, *f = new int_p;
+
+ int_p *g = new int*, *h = new int_p;
+ // CHECK: auto g = new int*, h = new int_p;
+ }
+
+ return 0;
}
OpenPOWER on IntegriCloud