diff options
author | Edwin Vane <edwin.vane@intel.com> | 2013-04-02 20:43:57 +0000 |
---|---|---|
committer | Edwin Vane <edwin.vane@intel.com> | 2013-04-02 20:43:57 +0000 |
commit | eeed39a58372135639c0b5918efb13ca552daec5 (patch) | |
tree | 320828cd2dfd70e37e60973c788deec4ccda2f39 /clang-tools-extra/test | |
parent | 1afa68ed14ad9636dda390add3bf74e32b5c0303 (diff) | |
download | bcm5719-llvm-eeed39a58372135639c0b5918efb13ca552daec5.tar.gz bcm5719-llvm-eeed39a58372135639c0b5918efb13ca552daec5.zip |
Use 'auto' with 'new' expressions
For variable declarations initialized with new expressions, use 'auto' for the
type specifier.
The 'auto' replacement happens only when the type of the VarDecl exactly
matches the type of the initializer and the VarDecl is *not* CV-qualified. The
only case that is currently handled is if the pointer type of the VarDecl is
itself CV qualified.
Some improvements need to be made to Clang's TypeLoc information in order for
other CV qualifier cases to be successfully handled. See the new test suite
new_cv_failing.cpp for examples of usages that could be handled with such an
improvement.
Function pointers are, for now, not transformed until the identifier info can
be extracted.
Reviewer: klimek
llvm-svn: 178575
Diffstat (limited to 'clang-tools-extra/test')
-rw-r--r-- | clang-tools-extra/test/cpp11-migrate/UseAuto/new.cpp | 52 | ||||
-rw-r--r-- | clang-tools-extra/test/cpp11-migrate/UseAuto/new_cv_failing.cpp | 36 |
2 files changed, 88 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 new file mode 100644 index 00000000000..911c0cd76bd --- /dev/null +++ b/clang-tools-extra/test/cpp11-migrate/UseAuto/new.cpp @@ -0,0 +1,52 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp +// RUN: cpp11-migrate -use-auto %t.cpp -- -std=c++11 +// RUN: FileCheck -input-file=%t.cpp %s + +class MyType { +}; + +class MyDerivedType : public MyType { +}; + +int main(int argc, char **argv) { + MyType *a = new MyType(); + // CHECK: auto a = new MyType(); + + static MyType *a_static = new MyType(); + // CHECK: static auto a_static = new MyType(); + + MyType *b = new MyDerivedType(); + // CHECK: MyType *b = new MyDerivedType(); + + void *c = new MyType(); + // CHECK: void *c = new MyType(); + + // CV-qualifier tests. + // + // NOTE : the form "type const" is expected here because of a deficiency in + // TypeLoc where CV qualifiers are not considered part of the type location + // info. That is, all that is being replaced in each case is "MyType *" and + // not "MyType * const". + { + static MyType * const d_static = new MyType(); + // CHECK: static auto const d_static = new MyType(); + + MyType * const d3 = new MyType(); + // CHECK: auto const d3 = new MyType(); + + MyType * volatile d4 = new MyType(); + // CHECK: auto volatile d4 = new MyType(); + } + + int (**func)(int, int) = new (int(*[5])(int,int)); + // CHECK: int (**func)(int, int) = new (int(*[5])(int,int)); + + int *e = new int[5]; + // CHECK: auto e = new int[5]; + + MyType *f(new MyType); + // CHECK: auto f(new MyType); + + MyType *g{new MyType}; + // CHECK: MyType *g{new MyType}; +} diff --git a/clang-tools-extra/test/cpp11-migrate/UseAuto/new_cv_failing.cpp b/clang-tools-extra/test/cpp11-migrate/UseAuto/new_cv_failing.cpp new file mode 100644 index 00000000000..8e21018ef90 --- /dev/null +++ b/clang-tools-extra/test/cpp11-migrate/UseAuto/new_cv_failing.cpp @@ -0,0 +1,36 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp +// RUN: cpp11-migrate -use-auto %t.cpp -- -std=c++11 +// RUN: FileCheck -input-file=%t.cpp %s +// XFAIL: * + +// None of these tests can pass right now because TypeLoc information where CV +// qualifiers are concerned is not reliable/available. + +class MyType { +}; + +int main (int argc, char **argv) { + const MyType *d = new MyType(); + // CHECK: const auto *d = new MyType(); + + volatile MyType *d2 = new MyType(); + // CHECK: volatile auto *d2 = new MyType(); + + const MyType * volatile e = new MyType(); + // CHECK: const auto * volatile d = new MyType(); + + volatile MyType * const f = new MyType(); + // CHECK: volatile auto * const d2 = new MyType(); + + const MyType *d5 = new const MyType(); + // CHECK: auto d5 = new const MyType(); + + volatile MyType *d6 = new volatile MyType(); + // CHECK: auto d6 = new volatile MyType(); + + const MyType * const d7 = new const MyType(); + // CHECK: const auto d7 = new const MyType(); + + volatile MyType * volatile d8 = new volatile MyType(); + // CHECK: volatile auto d8 = new volatile MyType(); +} |