1 // RUN: %check_clang_tidy %s modernize-use-using %t -- -- -I %S/Inputs/modernize-use-using/ 2 3 typedef int Type; 4 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using] 5 // CHECK-FIXES: using Type = int; 6 7 typedef long LL; 8 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 9 // CHECK-FIXES: using LL = long; 10 11 typedef int Bla; 12 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 13 // CHECK-FIXES: using Bla = int; 14 15 typedef Bla Bla2; 16 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 17 // CHECK-FIXES: using Bla2 = Bla; 18 19 typedef void (*type)(int, int); 20 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 21 // CHECK-FIXES: using type = void (*)(int, int); 22 23 typedef void (*type2)(); 24 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 25 // CHECK-FIXES: using type2 = void (*)(); 26 27 class Class { 28 typedef long long Type; 29 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 30 // CHECK-FIXES: using Type = long long; 31 }; 32 33 typedef void (Class::*MyPtrType)(Bla) const; 34 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 35 // CHECK-FIXES: using MyPtrType = void (Class::*)(Bla)[[ATTR:( __attribute__\(\(thiscall\)\))?]] const; 36 37 class Iterable { 38 public: 39 class Iterator {}; 40 }; 41 42 template <typename T> 43 class Test { 44 typedef typename T::iterator Iter; 45 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 46 // CHECK-FIXES: using Iter = typename T::iterator; 47 }; 48 49 using balba = long long; 50 51 union A {}; 52 53 typedef void (A::*PtrType)(int, int) const; 54 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 55 // CHECK-FIXES: using PtrType = void (A::*)(int, int)[[ATTR]] const; 56 57 typedef Class some_class; 58 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 59 // CHECK-FIXES: using some_class = Class; 60 61 typedef Class Cclass; 62 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 63 // CHECK-FIXES: using Cclass = Class; 64 65 typedef Cclass cclass2; 66 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 67 // CHECK-FIXES: using cclass2 = Cclass; 68 69 class cclass {}; 70 71 typedef void (cclass::*MyPtrType3)(Bla); 72 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 73 // CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla)[[ATTR]]; 74 75 using my_class = int; 76 77 typedef Test<my_class *> another; 78 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 79 // CHECK-FIXES: using another = Test<my_class *>; 80 81 typedef int* PInt; 82 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 83 // CHECK-FIXES: using PInt = int *; 84 85 typedef int bla1, bla2, bla3; 86 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 87 // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: use 'using' instead of 'typedef' 88 // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use 'using' instead of 'typedef' 89 // CHECK-FIXES: using bla1 = int; 90 // CHECK-FIXES-NEXT: using bla2 = int; 91 // CHECK-FIXES-NEXT: using bla3 = int; 92 93 #define CODE typedef int INT 94 95 CODE; 96 // CHECK-FIXES: #define CODE typedef int INT 97 // CHECK-FIXES: CODE; 98 99 struct Foo; 100 #define Bar Baz 101 typedef Foo Bar; 102 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 103 // CHECK-FIXES: #define Bar Baz 104 // CHECK-FIXES: using Baz = Foo; 105 106 #define TYPEDEF typedef 107 TYPEDEF Foo Bak; 108 // CHECK-FIXES: #define TYPEDEF typedef 109 // CHECK-FIXES: TYPEDEF Foo Bak; 110 111 #define FOO Foo 112 typedef FOO Bam; 113 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 114 // CHECK-FIXES: #define FOO Foo 115 // CHECK-FIXES: using Bam = Foo; 116 117 typedef struct Foo Bap; 118 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 119 // CHECK-FIXES: using Bap = struct Foo; 120 121 struct Foo typedef Bap2; 122 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 123 // CHECK-FIXES: using Bap2 = struct Foo; 124 125 Foo typedef Bap3; 126 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 127 // CHECK-FIXES: using Bap3 = Foo; 128 129 typedef struct Unknown Baq; 130 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 131 // CHECK-FIXES: using Baq = struct Unknown; 132 133 struct Unknown2 typedef Baw; 134 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 135 // CHECK-FIXES: using Baw = struct Unknown2; 136 137 int typedef Bax; 138 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 139 // CHECK-FIXES: using Bax = int; 140 141 typedef struct Q1 { int a; } S1; 142 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 143 // CHECK-FIXES: using S1 = struct Q1 { int a; }; 144 typedef struct { int b; } S2; 145 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 146 // CHECK-FIXES: using S2 = struct { int b; }; 147 struct Q2 { int c; } typedef S3; 148 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 149 // CHECK-FIXES: using S3 = struct Q2 { int c; }; 150 struct { int d; } typedef S4; 151 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 152 // CHECK-FIXES: using S4 = struct { int d; }; 153 154 namespace my_space { 155 class my_cclass {}; 156 typedef my_cclass FuncType; 157 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 158 // CHECK-FIXES: using FuncType = my_cclass; 159 } 160 161 #define lol 4 162 typedef unsigned Map[lol]; 163 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 164 // CHECK-FIXES: typedef unsigned Map[lol]; 165 166 typedef void (*fun_type)(); 167 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 168 // CHECK-FIXES: using fun_type = void (*)(); 169 170 namespace template_instantiations { 171 template <typename T> 172 class C { 173 protected: 174 typedef C<T> super; 175 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 176 // CHECK-FIXES: using super = C<T>; 177 virtual void f(); 178 179 public: 180 virtual ~C(); 181 }; 182 183 class D : public C<D> { f()184 void f() override { super::f(); } 185 }; 186 class E : public C<E> { f()187 void f() override { super::f(); } 188 }; 189 } 190 191 template <typename T1, typename T2> 192 class TwoArgTemplate { 193 typedef TwoArgTemplate<T1, T2> self; 194 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 195 // CHECK-FIXES: using self = TwoArgTemplate<T1, T2>; 196 }; 197 198 template <bool B, typename T> 199 struct S {}; 200 201 typedef S<(0 > 0), int> S_t, *S_p; 202 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 203 // CHECK-MESSAGES: :[[@LINE-2]]:28: warning: use 'using' instead of 'typedef' 204 // CHECK-FIXES: using S_t = S<(0 > 0), int>; 205 // CHECK-FIXES-NEXT: using S_p = S_t*; 206 207 typedef S<(0 < 0), int> S2_t, *S2_p; 208 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 209 // CHECK-MESSAGES: :[[@LINE-2]]:29: warning: use 'using' instead of 'typedef' 210 // CHECK-FIXES: using S2_t = S<(0 < 0), int>; 211 // CHECK-FIXES-NEXT: using S2_p = S2_t*; 212 213 typedef S<(0 > 0 && (3 > 1) && (1 < 1)), int> S3_t; 214 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 215 // CHECK-FIXES: using S3_t = S<(0 > 0 && (3 > 1) && (1 < 1)), int>; 216 217 template <bool B> 218 struct Q {}; 219 220 constexpr bool b[1] = {true}; 221 222 typedef Q<b[0 < 0]> Q_t, *Q_p; 223 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 224 // CHECK-MESSAGES: :[[@LINE-2]]:24: warning: use 'using' instead of 'typedef' 225 // CHECK-FIXES: using Q_t = Q<b[0 < 0]>; 226 // CHECK-FIXES-NEXT: using Q_p = Q_t*; 227 228 typedef Q<b[0 < 0]> Q2_t; 229 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 230 // CHECK-FIXES: using Q2_t = Q<b[0 < 0]>; 231 232 struct T { TT233 constexpr T(bool) {} 234 235 static constexpr bool b = true; 236 }; 237 238 typedef Q<T{0 < 0}.b> Q3_t, *Q3_p; 239 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 240 // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: use 'using' instead of 'typedef' 241 // CHECK-FIXES: using Q3_t = Q<T{0 < 0}.b>; 242 // CHECK-FIXES-NEXT: using Q3_p = Q3_t*; 243 244 typedef Q<T{0 < 0}.b> Q3_t; 245 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 246 // CHECK-FIXES: using Q3_t = Q<T{0 < 0}.b>; 247 248 typedef TwoArgTemplate<TwoArgTemplate<int, Q<T{0 < 0}.b> >, S<(0 < 0), Q<b[0 < 0]> > > Nested_t; 249 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 250 // CHECK-FIXES: using Nested_t = TwoArgTemplate<TwoArgTemplate<int, Q<T{0 < 0}.b>>, S<(0 < 0), Q<b[0 < 0]>>>; 251 252 template <typename a> 253 class TemplateKeyword { 254 typedef typename a::template b<> d; 255 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 256 // CHECK-FIXES: using d = typename a::template b<>; 257 258 typedef typename a::template b<>::c d2; 259 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 260 // CHECK-FIXES: using d2 = typename a::template b<>::c; 261 }; 262 263 template <typename... Args> 264 class Variadic {}; 265 266 typedef Variadic<Variadic<int, bool, Q<T{0 < 0}.b> >, S<(0 < 0), Variadic<Q<b[0 < 0]> > > > Variadic_t; 267 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 268 // CHECK-FIXES: using Variadic_t = Variadic<Variadic<int, bool, Q<T{0 < 0}.b>>, S<(0 < 0), Variadic<Q<b[0 < 0]>>>> 269 270 typedef Variadic<Variadic<int, bool, Q<T{0 < 0}.b> >, S<(0 < 0), Variadic<Q<b[0 < 0]> > > > Variadic_t, *Variadic_p; 271 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 272 // CHECK-MESSAGES: :[[@LINE-2]]:103: warning: use 'using' instead of 'typedef' 273 // CHECK-FIXES: using Variadic_t = Variadic<Variadic<int, bool, Q<T{0 < 0}.b>>, S<(0 < 0), Variadic<Q<b[0 < 0]>>>>; 274 // CHECK-FIXES-NEXT: using Variadic_p = Variadic_t*; 275 276 typedef struct { int a; } R_t, *R_p; 277 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 278 // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: use 'using' instead of 'typedef' 279 // CHECK-FIXES: using R_t = struct { int a; }; 280 // CHECK-FIXES-NEXT: using R_p = R_t*; 281 282 typedef enum { ea1, eb1 } EnumT1; 283 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 284 // CHECK-FIXES: using EnumT1 = enum { ea1, eb1 }; 285 286 #include "modernize-use-using.h" 287 288 typedef enum { ea2, eb2 } EnumT2_CheckTypedefImpactFromAnotherFile; 289 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 290 // CHECK-FIXES: using EnumT2_CheckTypedefImpactFromAnotherFile = enum { ea2, eb2 }; 291 292 template <int A> 293 struct InjectedClassName { 294 typedef InjectedClassName b; 295 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 296 // CHECK-FIXES: using b = InjectedClassName; 297 }; 298 299 template <int> 300 struct InjectedClassNameWithUnnamedArgument { 301 typedef InjectedClassNameWithUnnamedArgument b; 302 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 303 // CHECK-FIXES: using b = InjectedClassNameWithUnnamedArgument; 304 }; 305