diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-09-04 17:35:07 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-09-04 17:35:07 +0000 |
commit | d9063c46f59f4bec47bcbeddca8ca2f789348c03 (patch) | |
tree | 76505542df7a05016dc71ffe44ed3ba264fb54be /clang-tools-extra/test/cpp11-migrate/UseAuto | |
parent | 6a23d212897d5402035cfaea82260f6dae1c8f2a (diff) | |
download | bcm5719-llvm-d9063c46f59f4bec47bcbeddca8ca2f789348c03.tar.gz bcm5719-llvm-d9063c46f59f4bec47bcbeddca8ca2f789348c03.zip |
Rename cpp11-migrate to clang-modernize.
There is no reason to expect this tool to be limited to C++11, it seems
very likely to be of on-going interest. It seems likely to be useful for
modernizing even as new libraries come out in TSes and other formats
than a complete standard. Fundamentally, we need something a bit more
general. After some discussion on the list, going with
'clang-modernize'.
I've tried to do a reasonably comprehensive job of fixing up the names,
but I may still have missed some. Feel free to poke me if you spot any
fallout here. Things I've tried reasonably hard to find and fix:
- cpp11-migrate -> clang-modernize
- Migrator -> Modernizer
- Clean up the introductory documentation that was C++11 specific.
I'll also point out that this tool continues to delight me. =] Also,
a huge thanks to those who have so carefully, thoroughly documented the
tool. The docs here are simply phenomenal. Every tool should be this
well documented. I hope I have updated the documentation reasonably
well, but I'm not very good at documentation, so review much
appreciated.
llvm-svn: 189960
Diffstat (limited to 'clang-tools-extra/test/cpp11-migrate/UseAuto')
5 files changed, 0 insertions, 553 deletions
diff --git a/clang-tools-extra/test/cpp11-migrate/UseAuto/Inputs/test_std_container.h b/clang-tools-extra/test/cpp11-migrate/UseAuto/Inputs/test_std_container.h deleted file mode 100644 index 5c92f6e194f..00000000000 --- a/clang-tools-extra/test/cpp11-migrate/UseAuto/Inputs/test_std_container.h +++ /dev/null @@ -1,119 +0,0 @@ -//===-----------------------------------------------------------*- C++ -*--===// -// -// This file contains a shell implementation of a standard container with -// iterators. This shell is targeted at supporting the container interfaces -// recognized by cpp11-migrate's use-auto transformation. It requires the -// preprocessor to parameterize the name of the container, and allows the -// preprocessor to parameterize various mechanisms used in the implementation -// of the container / iterator. -// -// Variations for how iterator types are presented: -// * Typedef (array, deque, forward_list, list, vector) -// * Nested class (map, multimap, set, multiset) -// * Using declaration {unordered_} X {map, multimap, set, multiset} -// -// Variations for how container types are presented: -// * Defined directly in namespace std -// * Imported into namespace std with using declarations (a la libc++). -// -//===----------------------------------------------------------------------===// - -#ifndef CONTAINER -#error You must define CONTAINER to the name of the desired container. -#endif - -// If the test code needs multiple containers, only define our helpers once. -#ifndef TEST_STD_CONTAINER_HELPERS -#define TEST_STD_CONTAINER_HELPERS - -namespace internal { - -template <typename T, int i> -struct iterator_wrapper { - iterator_wrapper() {} - - // These are required for tests using iteration statements. - bool operator!=(const iterator_wrapper<T, i>&) { return false; } - iterator_wrapper& operator++() { return *this; } - typename T::value_type operator*() { return typename T::value_type(); } -}; - -template <typename T> -class iterator_provider { -public: - class iterator { - public: - iterator() {} - iterator(const iterator&) {} - }; - class const_iterator { - public: - const_iterator(int i=0) {} - const_iterator(const iterator &) {} - const_iterator(const const_iterator &) {} - operator iterator() { return iterator(); } - }; - class reverse_iterator {}; - class const_reverse_iterator {}; -}; - -} // namespace internal - -#endif // TEST_STD_CONTAINER_HELPERS - -namespace std { - -#if USE_INLINE_NAMESPACE -inline namespace _1 { -#endif - -template <typename T> -class CONTAINER -#if USE_BASE_CLASS_ITERATORS - : internal::iterator_provider<CONTAINER<T> > -#endif -{ -public: - -#if USE_BASE_CLASS_ITERATORS - using typename internal::iterator_provider<CONTAINER<T> >::iterator; - using typename internal::iterator_provider<CONTAINER<T> >::const_iterator; - using typename internal::iterator_provider<CONTAINER<T> >::reverse_iterator; - using typename internal::iterator_provider<CONTAINER<T> >::const_reverse_iterator; -#elif USE_INNER_CLASS_ITERATORS - class iterator {}; - class const_iterator {}; - class reverse_iterator {}; - class const_reverse_iterator {}; -#else - typedef T value_type; - typedef typename internal::iterator_wrapper<CONTAINER<T>, 0> iterator; - typedef typename internal::iterator_wrapper<CONTAINER<T>, 1> const_iterator; - typedef typename internal::iterator_wrapper<CONTAINER<T>, 3> reverse_iterator; - typedef typename internal::iterator_wrapper<CONTAINER<T>, 2> const_reverse_iterator; -#endif - - // Every class requires these functions. - CONTAINER() {} - - iterator begin() { return iterator(); } - iterator end() { return iterator(); } - - const_iterator begin() const { return const_iterator(); } - const_iterator end() const { return const_iterator(); } - - reverse_iterator rbegin() { return reverse_iterator(); } - reverse_iterator rend() { return reverse_iterator(); } - - const_reverse_iterator rbegin() const { return const_reverse_iterator(); } - const_reverse_iterator rend() const { return const_reverse_iterator(); } - - template <typename K> - iterator find(const K &Key) { return iterator(); } -}; - -#if USE_INLINE_NAMESPACE -} // namespace _1 -#endif - -} // namespace std diff --git a/clang-tools-extra/test/cpp11-migrate/UseAuto/basic_iterator_tests.cpp b/clang-tools-extra/test/cpp11-migrate/UseAuto/basic_iterator_tests.cpp deleted file mode 100644 index 30199e93f44..00000000000 --- a/clang-tools-extra/test/cpp11-migrate/UseAuto/basic_iterator_tests.cpp +++ /dev/null @@ -1,123 +0,0 @@ -// This file contains basic positive tests for the use-auto transform's ability -// to replace standard iterators. Variables considered: -// * All std container names -// * All std iterator names -// * Different patterns of defining iterators and containers -// -// // The most basic test. -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=array -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// -// Test variations on how the container and its iterators might be defined. -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=array \ -// RUN: -DUSE_INLINE_NAMESPACE=1 -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=array \ -// RUN: -DUSE_BASE_CLASS_ITERATORS=1 -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=array \ -// RUN: -DUSE_INNER_CLASS_ITERATORS=1 -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// -// Test all of the other container names in a basic configuration. -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=deque -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=forward_list -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=list -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=vector -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=map -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=multimap -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=set -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=multiset -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=unordered_map -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=unordered_multimap -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=unordered_set -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=unordered_multiset -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=queue -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=priority_queue -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=stack -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s - -#ifndef CONTAINER -#error You must define CONTAINER to the name of the container for testing. -#endif - -#include "test_std_container.h" - -int main(int argc, char **argv) { - { - std::CONTAINER<int> C; - std::CONTAINER<int>::iterator I = C.begin(); - // CHECK: auto I = C.begin(); - } - { - std::CONTAINER<int> C; - std::CONTAINER<int>::reverse_iterator I = C.rbegin(); - // CHECK: auto I = C.rbegin(); - } - { - const std::CONTAINER<int> C; - std::CONTAINER<int>::const_iterator I = C.begin(); - // CHECK: auto I = C.begin(); - } - { - const std::CONTAINER<int> C; - std::CONTAINER<int>::const_reverse_iterator I = C.rbegin(); - // CHECK: auto I = C.rbegin(); - } - - return 0; -} diff --git a/clang-tools-extra/test/cpp11-migrate/UseAuto/iterator.cpp b/clang-tools-extra/test/cpp11-migrate/UseAuto/iterator.cpp deleted file mode 100644 index 8871bc1eb36..00000000000 --- a/clang-tools-extra/test/cpp11-migrate/UseAuto/iterator.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- --std=c++11 -I %S/Inputs -// RUN: FileCheck -input-file=%t.cpp %s -// -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: cpp11-migrate -use-auto %t.cpp -- --std=c++11 -I %S/Inputs \ -// RUN: -DUSE_INLINE_NAMESPACE=1 -// RUN: FileCheck -input-file=%t.cpp %s - - -#define CONTAINER array -#include "test_std_container.h" -#undef CONTAINER - -#define CONTAINER vector -#include "test_std_container.h" -#undef CONTAINER - -#define CONTAINER unordered_map -#define USE_BASE_CLASS_ITERATORS 1 -#include "test_std_container.h" -#undef USE_BASE_CLASS_ITERATORS -#undef CONTAINER - -typedef std::vector<int>::iterator int_iterator; - -namespace foo { - template <typename T> - class vector { - public: - class iterator {}; - - iterator begin() { return iterator(); } - }; -} // namespace foo - -int main(int argc, char **argv) { - std::vector<int> Vec; - // CHECK: std::vector<int> Vec; - - std::unordered_map<int> Map; - // CHECK: std::unordered_map<int> Map; - - // Types with more sugar should work. Types with less should not. - { - int_iterator more_sugar = Vec.begin(); - // CHECK: auto more_sugar = Vec.begin(); - - internal::iterator_wrapper<std::vector<int>, 0> less_sugar = Vec.begin(); - // CHECK: internal::iterator_wrapper<std::vector<int>, 0> less_sugar = Vec.begin(); - } - - // Initialization from initializer lists isn't allowed. Using 'auto' - // would result in std::initializer_list being deduced for the type. - { - std::unordered_map<int>::iterator I{Map.begin()}; - // CHECK: std::unordered_map<int>::iterator I{Map.begin()}; - - std::unordered_map<int>::iterator I2 = {Map.begin()}; - // CHECK: std::unordered_map<int>::iterator I2 = {Map.begin()}; - } - - // Various forms of construction. Default constructors and constructors with - // all-default parameters shouldn't get transformed. Construction from other - // types is also not allowed. - { - std::unordered_map<int>::iterator copy(Map.begin()); - // CHECK: auto copy(Map.begin()); - - std::unordered_map<int>::iterator def; - // CHECK: std::unordered_map<int>::iterator def; - - // const_iterator has no default constructor, just one that has >0 params - // with defaults. - std::unordered_map<int>::const_iterator constI; - // CHECK: std::unordered_map<int>::const_iterator constI; - - // Uses iterator_provider::const_iterator's conversion constructor. - - std::unordered_map<int>::const_iterator constI2 = def; - // CHECK: std::unordered_map<int>::const_iterator constI2 = def; - - std::unordered_map<int>::const_iterator constI3(def); - // CHECK: std::unordered_map<int>::const_iterator constI3(def); - - // Explicit use of conversion constructor - - std::unordered_map<int>::const_iterator constI4 = std::unordered_map<int>::const_iterator(def); - // CHECK: auto constI4 = std::unordered_map<int>::const_iterator(def); - - // Uses iterator_provider::iterator's const_iterator conversion operator. - - std::unordered_map<int>::iterator I = constI; - // CHECK: std::unordered_map<int>::iterator I = constI; - - std::unordered_map<int>::iterator I2(constI); - // CHECK: std::unordered_map<int>::iterator I2(constI); - } - - // Weird cases of pointers and references to iterators are not transformed. - { - int_iterator I = Vec.begin(); - - int_iterator *IPtr = &I; - // CHECK: int_iterator *IPtr = &I; - - int_iterator &IRef = I; - // CHECK: int_iterator &IRef = I; - } - - { - // Variable declarations in iteration statements. - for (std::vector<int>::iterator I = Vec.begin(); I != Vec.end(); ++I) { - // CHECK: for (auto I = Vec.begin(); I != Vec.end(); ++I) { - } - - // Range-based for loops. - std::array<std::vector<int>::iterator> iter_arr; - for (std::vector<int>::iterator I: iter_arr) { - // CHECK: for (auto I: iter_arr) { - } - - // Test with init-declarator-list. - for (int_iterator I = Vec.begin(), - E = Vec.end(); I != E; ++I) { - // CHECK: for (auto I = Vec.begin(), - // CHECK-NEXT: E = Vec.end(); I != E; ++I) { - } - } - - // Only std containers should be changed. - { - using namespace foo; - vector<int> foo_vec; - vector<int>::iterator I = foo_vec.begin(); - // CHECK: vector<int>::iterator I = foo_vec.begin(); - } - - // Ensure using directives don't interfere with replacement. - { - using namespace std; - vector<int> std_vec; - vector<int>::iterator I = std_vec.begin(); - // CHECK: auto I = std_vec.begin(); - } - - // Make sure references and cv qualifiers don't get removed (i.e. replaced - // with just 'auto'). - { - const auto & I = Vec.begin(); - // CHECK: const auto & I = Vec.begin(); - - auto && I2 = Vec.begin(); - // CHECK: auto && I2 = Vec.begin(); - } - - // Passing a string as an argument to introduce a temporary object - // that will create an expression with cleanups. Bugzilla: 15550 - { - std::unordered_map<int> MapFind; - std::unordered_map<int>::iterator I = MapFind.find("foo"); - // CHECK: auto I = MapFind.find("foo"); - } - - // Test for declaration lists - { - // Ensusre declaration lists that matches the declaration type with written - // no-list initializer are transformed. - std::vector<int>::iterator I = Vec.begin(), E = Vec.end(); - // CHECK: auto I = Vec.begin(), E = Vec.end(); - - // Declaration lists with non-initialized variables should not be - // transformed. - std::vector<int>::iterator J = Vec.begin(), K; - // CHECK: std::vector<int>::iterator J = Vec.begin(), K; - } - return 0; -} diff --git a/clang-tools-extra/test/cpp11-migrate/UseAuto/new.cpp b/clang-tools-extra/test/cpp11-migrate/UseAuto/new.cpp deleted file mode 100644 index 3fca05df29b..00000000000 --- a/clang-tools-extra/test/cpp11-migrate/UseAuto/new.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// 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}; - - // 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; -} 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 deleted file mode 100644 index 8e21018ef90..00000000000 --- a/clang-tools-extra/test/cpp11-migrate/UseAuto/new_cv_failing.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// 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(); -} |