1b4d9ac8bSUtkarsh Saxena // RUN: %check_clang_tidy -std=c++17-or-later %s readability-isolate-declaration %t
289a1d03eSRichard 
389a1d03eSRichard template <typename T1, typename T2>
489a1d03eSRichard struct pair {
589a1d03eSRichard   T1 first;
689a1d03eSRichard   T2 second;
pairpair789a1d03eSRichard   pair(T1 v1, T2 v2) : first(v1), second(v2) {}
889a1d03eSRichard 
989a1d03eSRichard   template <int N>
getpair1089a1d03eSRichard   decltype(auto) get() const {
1189a1d03eSRichard     if constexpr (N == 0)
1289a1d03eSRichard       return first;
1389a1d03eSRichard     else if constexpr (N == 1)
1489a1d03eSRichard       return second;
1589a1d03eSRichard   }
1689a1d03eSRichard };
1789a1d03eSRichard 
forbidden_transformations()1889a1d03eSRichard void forbidden_transformations() {
1989a1d03eSRichard   if (int i = 42, j = i; i == j)
2089a1d03eSRichard     ;
2189a1d03eSRichard   switch (int i = 12, j = 14; i)
2289a1d03eSRichard     ;
2389a1d03eSRichard 
2489a1d03eSRichard   auto [i, j] = pair<int, int>(42, 42);
2589a1d03eSRichard }
2689a1d03eSRichard 
2789a1d03eSRichard struct SomeClass {
2889a1d03eSRichard   SomeClass() = default;
2989a1d03eSRichard   SomeClass(int value);
3089a1d03eSRichard };
3189a1d03eSRichard 
3289a1d03eSRichard namespace std {
3389a1d03eSRichard template <typename T>
34*482c41e9SMital Ashok class initializer_list { const T *a, *b; };
3589a1d03eSRichard 
3689a1d03eSRichard template <typename T>
3789a1d03eSRichard class vector {
3889a1d03eSRichard public:
3989a1d03eSRichard   vector() = default;
vector(initializer_list<T> init)4089a1d03eSRichard   vector(initializer_list<T> init) {}
4189a1d03eSRichard };
4289a1d03eSRichard 
4389a1d03eSRichard class string {
4489a1d03eSRichard public:
4589a1d03eSRichard   string() = default;
string(const char *)4689a1d03eSRichard   string(const char *) {}
4789a1d03eSRichard };
4889a1d03eSRichard 
4989a1d03eSRichard namespace string_literals {
operator ""s(const char *,decltype(sizeof (int)) )5089a1d03eSRichard string operator""s(const char *, decltype(sizeof(int))) {
5189a1d03eSRichard   return string();
5289a1d03eSRichard }
5389a1d03eSRichard } // namespace string_literals
5489a1d03eSRichard } // namespace std
5589a1d03eSRichard 
5689a1d03eSRichard namespace Types {
5789a1d03eSRichard typedef int MyType;
5889a1d03eSRichard } // namespace Types
5989a1d03eSRichard 
6089a1d03eSRichard int touch1, touch2;
6189a1d03eSRichard 
modern()6289a1d03eSRichard void modern() {
6389a1d03eSRichard   auto autoInt1 = 3, autoInt2 = 4;
6489a1d03eSRichard   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
6589a1d03eSRichard   // CHECK-FIXES: auto autoInt1 = 3;
6689a1d03eSRichard   // CHECK-FIXES: {{^  }}auto autoInt2 = 4;
6789a1d03eSRichard 
6889a1d03eSRichard   decltype(int()) declnottouch = 4;
6989a1d03eSRichard   decltype(int()) declint1 = 5, declint2 = 3;
7089a1d03eSRichard   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
7189a1d03eSRichard   // CHECK-FIXES: decltype(int()) declint1 = 5;
7289a1d03eSRichard   // CHECK-FIXES: {{^  }}decltype(int()) declint2 = 3;
7389a1d03eSRichard 
7489a1d03eSRichard   std::vector<int> vectorA = {1, 2}, vectorB = {1, 2, 3}, vectorC({1, 1, 1});
7589a1d03eSRichard   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
7689a1d03eSRichard   // CHECK-FIXES: std::vector<int> vectorA = {1, 2};
7789a1d03eSRichard   // CHECK-FIXES: {{^  }}std::vector<int> vectorB = {1, 2, 3};
7889a1d03eSRichard   // CHECK-FIXES: {{^  }}std::vector<int> vectorC({1, 1, 1});
7989a1d03eSRichard 
8089a1d03eSRichard   using uType = int;
8189a1d03eSRichard   uType utype1, utype2;
8289a1d03eSRichard   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
8389a1d03eSRichard   // CHECK-FIXES: uType utype1;
8489a1d03eSRichard   // CHECK-FIXES: {{^  }}uType utype2;
8589a1d03eSRichard 
8689a1d03eSRichard   Types::MyType mytype1, mytype2, mytype3 = 3;
8789a1d03eSRichard   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
8889a1d03eSRichard   // CHECK-FIXES: Types::MyType mytype1;
8989a1d03eSRichard   // CHECK-FIXES: {{^  }}Types::MyType mytype2;
9089a1d03eSRichard   // CHECK-FIXES: {{^  }}Types::MyType mytype3 = 3;
9189a1d03eSRichard 
9289a1d03eSRichard   {
9389a1d03eSRichard     using namespace std::string_literals;
9489a1d03eSRichard 
9589a1d03eSRichard     std::vector<std::string> s{"foo"s, "bar"s}, t{"foo"s}, u, a({"hey", "you"}), bb = {"h", "a"};
9689a1d03eSRichard     // CHECK-MESSAGES: [[@LINE-1]]:5: warning: multiple declarations in a single statement reduces readability
9789a1d03eSRichard     // CHECK-FIXES: std::vector<std::string> s{"foo"s, "bar"s};
9889a1d03eSRichard     // CHECK-FIXES: {{^    }}std::vector<std::string> t{"foo"s};
9989a1d03eSRichard     // CHECK-FIXES: {{^    }}std::vector<std::string> u;
10089a1d03eSRichard     // CHECK-FIXES: {{^    }}std::vector<std::string> a({"hey", "you"});
10189a1d03eSRichard     // CHECK-FIXES: {{^    }}std::vector<std::string> bb = {"h", "a"};
10289a1d03eSRichard   }
10389a1d03eSRichard }
104