xref: /llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp (revision f77152d9a44b49ee38b15085034bbfe22b4b3992)
18ea94b61SFélix-Antoine Constantin // RUN: %check_clang_tidy %s modernize-use-using %t -- -- -fno-delayed-template-parsing -I %S/Inputs/use-using/
289a1d03eSRichard 
389a1d03eSRichard typedef int Type;
489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
589a1d03eSRichard // CHECK-FIXES: using Type = int;
689a1d03eSRichard 
789a1d03eSRichard typedef long LL;
889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
989a1d03eSRichard // CHECK-FIXES: using LL = long;
1089a1d03eSRichard 
1189a1d03eSRichard typedef int Bla;
1289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
1389a1d03eSRichard // CHECK-FIXES: using Bla = int;
1489a1d03eSRichard 
1589a1d03eSRichard typedef Bla Bla2;
1689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
1789a1d03eSRichard // CHECK-FIXES: using Bla2 = Bla;
1889a1d03eSRichard 
1989a1d03eSRichard typedef void (*type)(int, int);
2089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
2189a1d03eSRichard // CHECK-FIXES: using type = void (*)(int, int);
2289a1d03eSRichard 
2389a1d03eSRichard typedef void (*type2)();
2489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
2589a1d03eSRichard // CHECK-FIXES: using type2 = void (*)();
2689a1d03eSRichard 
2789a1d03eSRichard class Class {
2889a1d03eSRichard   typedef long long Type;
2989a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
3089a1d03eSRichard   // CHECK-FIXES: using Type = long long;
3189a1d03eSRichard };
3289a1d03eSRichard 
3389a1d03eSRichard typedef void (Class::*MyPtrType)(Bla) const;
3489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
3589a1d03eSRichard // CHECK-FIXES: using MyPtrType = void (Class::*)(Bla)[[ATTR:( __attribute__\(\(thiscall\)\))?]] const;
3689a1d03eSRichard 
3789a1d03eSRichard class Iterable {
3889a1d03eSRichard public:
3989a1d03eSRichard   class Iterator {};
4089a1d03eSRichard };
4189a1d03eSRichard 
4289a1d03eSRichard template <typename T>
4389a1d03eSRichard class Test {
4489a1d03eSRichard   typedef typename T::iterator Iter;
4589a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
4689a1d03eSRichard   // CHECK-FIXES: using Iter = typename T::iterator;
4789a1d03eSRichard };
4889a1d03eSRichard 
4989a1d03eSRichard using balba = long long;
5089a1d03eSRichard 
5189a1d03eSRichard union A {};
5289a1d03eSRichard 
5389a1d03eSRichard typedef void (A::*PtrType)(int, int) const;
5489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
5589a1d03eSRichard // CHECK-FIXES: using PtrType = void (A::*)(int, int)[[ATTR]] const;
5689a1d03eSRichard 
5789a1d03eSRichard typedef Class some_class;
5889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
5989a1d03eSRichard // CHECK-FIXES: using some_class = Class;
6089a1d03eSRichard 
6189a1d03eSRichard typedef Class Cclass;
6289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
6389a1d03eSRichard // CHECK-FIXES: using Cclass = Class;
6489a1d03eSRichard 
6589a1d03eSRichard typedef Cclass cclass2;
6689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
6789a1d03eSRichard // CHECK-FIXES: using cclass2 = Cclass;
6889a1d03eSRichard 
6989a1d03eSRichard class cclass {};
7089a1d03eSRichard 
7189a1d03eSRichard typedef void (cclass::*MyPtrType3)(Bla);
7289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
7389a1d03eSRichard // CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla)[[ATTR]];
7489a1d03eSRichard 
7589a1d03eSRichard using my_class = int;
7689a1d03eSRichard 
7789a1d03eSRichard typedef Test<my_class *> another;
7889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
7989a1d03eSRichard // CHECK-FIXES: using another = Test<my_class *>;
8089a1d03eSRichard 
8189a1d03eSRichard typedef int* PInt;
8289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
8389a1d03eSRichard // CHECK-FIXES: using PInt = int*;
8489a1d03eSRichard 
8589a1d03eSRichard typedef int bla1, bla2, bla3;
8689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
8789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: use 'using' instead of 'typedef'
8889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use 'using' instead of 'typedef'
8989a1d03eSRichard // CHECK-FIXES: using bla1 = int;
9089a1d03eSRichard // CHECK-FIXES-NEXT: using bla2 = int;
9189a1d03eSRichard // CHECK-FIXES-NEXT: using bla3 = int;
9289a1d03eSRichard 
9389a1d03eSRichard #define CODE typedef int INT
9489a1d03eSRichard 
9589a1d03eSRichard CODE;
9689a1d03eSRichard // CHECK-FIXES: #define CODE typedef int INT
9789a1d03eSRichard // CHECK-FIXES: CODE;
9889a1d03eSRichard 
9989a1d03eSRichard struct Foo;
10089a1d03eSRichard #define Bar Baz
10189a1d03eSRichard typedef Foo Bar;
10289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
10389a1d03eSRichard // CHECK-FIXES: #define Bar Baz
10489a1d03eSRichard // CHECK-FIXES: using Baz = Foo;
10589a1d03eSRichard 
10689a1d03eSRichard #define TYPEDEF typedef
10789a1d03eSRichard TYPEDEF Foo Bak;
10889a1d03eSRichard // CHECK-FIXES: #define TYPEDEF typedef
10989a1d03eSRichard // CHECK-FIXES: TYPEDEF Foo Bak;
11089a1d03eSRichard 
11189a1d03eSRichard #define FOO Foo
11289a1d03eSRichard typedef FOO Bam;
11389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
11489a1d03eSRichard // CHECK-FIXES: #define FOO Foo
115*f77152d9SJulian Schmidt // CHECK-FIXES: using Bam = FOO;
11689a1d03eSRichard 
11789a1d03eSRichard typedef struct Foo Bap;
11889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
11989a1d03eSRichard // CHECK-FIXES: using Bap = struct Foo;
12089a1d03eSRichard 
12189a1d03eSRichard struct Foo typedef Bap2;
12289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
12389a1d03eSRichard // CHECK-FIXES: using Bap2 = struct Foo;
12489a1d03eSRichard 
12589a1d03eSRichard Foo typedef Bap3;
12689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
12789a1d03eSRichard // CHECK-FIXES: using Bap3 = Foo;
12889a1d03eSRichard 
12989a1d03eSRichard typedef struct Unknown Baq;
13089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
13189a1d03eSRichard // CHECK-FIXES: using Baq = struct Unknown;
13289a1d03eSRichard 
13389a1d03eSRichard struct Unknown2 typedef Baw;
13489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
13589a1d03eSRichard // CHECK-FIXES: using Baw = struct Unknown2;
13689a1d03eSRichard 
13789a1d03eSRichard int typedef Bax;
13889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
13989a1d03eSRichard // CHECK-FIXES: using Bax = int;
14089a1d03eSRichard 
14189a1d03eSRichard typedef struct Q1 { int a; } S1;
14289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
14389a1d03eSRichard // CHECK-FIXES: using S1 = struct Q1 { int a; };
14489a1d03eSRichard typedef struct { int b; } S2;
14589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
14689a1d03eSRichard // CHECK-FIXES: using S2 = struct { int b; };
14789a1d03eSRichard struct Q2 { int c; } typedef S3;
14889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
14989a1d03eSRichard // CHECK-FIXES: using S3 = struct Q2 { int c; };
15089a1d03eSRichard struct { int d; } typedef S4;
15189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
15289a1d03eSRichard // CHECK-FIXES: using S4 = struct { int d; };
15389a1d03eSRichard 
15489a1d03eSRichard namespace my_space {
15589a1d03eSRichard   class my_cclass {};
15689a1d03eSRichard   typedef my_cclass FuncType;
15789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
15889a1d03eSRichard // CHECK-FIXES: using FuncType = my_cclass;
15989a1d03eSRichard }
16089a1d03eSRichard 
16189a1d03eSRichard #define lol 4
16289a1d03eSRichard typedef unsigned Map[lol];
16389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
16489a1d03eSRichard // CHECK-FIXES: typedef unsigned Map[lol];
16589a1d03eSRichard 
16689a1d03eSRichard typedef void (*fun_type)();
16789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
16889a1d03eSRichard // CHECK-FIXES: using fun_type = void (*)();
16989a1d03eSRichard 
17089a1d03eSRichard namespace template_instantiations {
17189a1d03eSRichard template <typename T>
17289a1d03eSRichard class C {
17389a1d03eSRichard  protected:
17489a1d03eSRichard   typedef C<T> super;
17589a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
17689a1d03eSRichard   // CHECK-FIXES: using super = C<T>;
17789a1d03eSRichard   virtual void f();
17889a1d03eSRichard 
17989a1d03eSRichard public:
18089a1d03eSRichard   virtual ~C();
18189a1d03eSRichard };
18289a1d03eSRichard 
18389a1d03eSRichard class D : public C<D> {
18489a1d03eSRichard   void f() override { super::f(); }
18589a1d03eSRichard };
18689a1d03eSRichard class E : public C<E> {
18789a1d03eSRichard   void f() override { super::f(); }
18889a1d03eSRichard };
18989a1d03eSRichard }
19089a1d03eSRichard 
19189a1d03eSRichard template <typename T1, typename T2>
19289a1d03eSRichard class TwoArgTemplate {
19389a1d03eSRichard   typedef TwoArgTemplate<T1, T2> self;
19489a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
19589a1d03eSRichard   // CHECK-FIXES: using self = TwoArgTemplate<T1, T2>;
19689a1d03eSRichard };
19789a1d03eSRichard 
19889a1d03eSRichard template <bool B, typename T>
19989a1d03eSRichard struct S {};
20089a1d03eSRichard 
20189a1d03eSRichard typedef S<(0 > 0), int> S_t, *S_p;
20289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
20389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:28: warning: use 'using' instead of 'typedef'
20489a1d03eSRichard // CHECK-FIXES: using S_t = S<(0 > 0), int>;
20589a1d03eSRichard // CHECK-FIXES-NEXT: using S_p = S_t*;
20689a1d03eSRichard 
20789a1d03eSRichard typedef S<(0 < 0), int> S2_t, *S2_p;
20889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
20989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:29: warning: use 'using' instead of 'typedef'
21089a1d03eSRichard // CHECK-FIXES: using S2_t = S<(0 < 0), int>;
21189a1d03eSRichard // CHECK-FIXES-NEXT: using S2_p = S2_t*;
21289a1d03eSRichard 
21389a1d03eSRichard typedef S<(0 > 0 && (3 > 1) && (1 < 1)), int> S3_t;
21489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
21589a1d03eSRichard // CHECK-FIXES: using S3_t = S<(0 > 0 && (3 > 1) && (1 < 1)), int>;
21689a1d03eSRichard 
21789a1d03eSRichard template <bool B>
21889a1d03eSRichard struct Q {};
21989a1d03eSRichard 
22089a1d03eSRichard constexpr bool b[1] = {true};
22189a1d03eSRichard 
22289a1d03eSRichard typedef Q<b[0 < 0]> Q_t, *Q_p;
22389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
22489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:24: warning: use 'using' instead of 'typedef'
22589a1d03eSRichard // CHECK-FIXES: using Q_t = Q<b[0 < 0]>;
22689a1d03eSRichard // CHECK-FIXES-NEXT: using Q_p = Q_t*;
22789a1d03eSRichard 
22889a1d03eSRichard typedef Q<b[0 < 0]> Q2_t;
22989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
23089a1d03eSRichard // CHECK-FIXES: using Q2_t = Q<b[0 < 0]>;
23189a1d03eSRichard 
23289a1d03eSRichard struct T {
23389a1d03eSRichard   constexpr T(bool) {}
23489a1d03eSRichard 
23589a1d03eSRichard   static constexpr bool b = true;
23689a1d03eSRichard };
23789a1d03eSRichard 
23889a1d03eSRichard typedef Q<T{0 < 0}.b> Q3_t, *Q3_p;
23989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
24089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: use 'using' instead of 'typedef'
24189a1d03eSRichard // CHECK-FIXES: using Q3_t = Q<T{0 < 0}.b>;
24289a1d03eSRichard // CHECK-FIXES-NEXT: using Q3_p = Q3_t*;
24389a1d03eSRichard 
24489a1d03eSRichard typedef Q<T{0 < 0}.b> Q3_t;
24589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
24689a1d03eSRichard // CHECK-FIXES: using Q3_t = Q<T{0 < 0}.b>;
24789a1d03eSRichard 
24889a1d03eSRichard typedef TwoArgTemplate<TwoArgTemplate<int, Q<T{0 < 0}.b> >, S<(0 < 0), Q<b[0 < 0]> > > Nested_t;
24989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
25089a1d03eSRichard // CHECK-FIXES: using Nested_t = TwoArgTemplate<TwoArgTemplate<int, Q<T{0 < 0}.b> >, S<(0 < 0), Q<b[0 < 0]> > >;
25189a1d03eSRichard 
25289a1d03eSRichard template <typename a>
25389a1d03eSRichard class TemplateKeyword {
25489a1d03eSRichard   typedef typename a::template b<> d;
25589a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
25689a1d03eSRichard   // CHECK-FIXES: using d = typename a::template b<>;
25789a1d03eSRichard 
25889a1d03eSRichard   typedef typename a::template b<>::c d2;
25989a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
26089a1d03eSRichard   // CHECK-FIXES: using d2 = typename a::template b<>::c;
26189a1d03eSRichard };
26289a1d03eSRichard 
26389a1d03eSRichard template <typename... Args>
26489a1d03eSRichard class Variadic {};
26589a1d03eSRichard 
26689a1d03eSRichard typedef Variadic<Variadic<int, bool, Q<T{0 < 0}.b> >, S<(0 < 0), Variadic<Q<b[0 < 0]> > > > Variadic_t;
26789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
26889a1d03eSRichard // CHECK-FIXES: using Variadic_t = Variadic<Variadic<int, bool, Q<T{0 < 0}.b> >, S<(0 < 0), Variadic<Q<b[0 < 0]> > > >
26989a1d03eSRichard 
27089a1d03eSRichard typedef Variadic<Variadic<int, bool, Q<T{0 < 0}.b> >, S<(0 < 0), Variadic<Q<b[0 < 0]> > > > Variadic_t, *Variadic_p;
27189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
27289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:103: warning: use 'using' instead of 'typedef'
27389a1d03eSRichard // CHECK-FIXES: using Variadic_t = Variadic<Variadic<int, bool, Q<T{0 < 0}.b> >, S<(0 < 0), Variadic<Q<b[0 < 0]> > > >;
27489a1d03eSRichard // CHECK-FIXES-NEXT: using Variadic_p = Variadic_t*;
27589a1d03eSRichard 
27689a1d03eSRichard typedef struct { int a; } R_t, *R_p;
27789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
27889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: use 'using' instead of 'typedef'
27989a1d03eSRichard // CHECK-FIXES: using R_t = struct { int a; };
28089a1d03eSRichard // CHECK-FIXES-NEXT: using R_p = R_t*;
28189a1d03eSRichard 
28289a1d03eSRichard typedef enum { ea1, eb1 } EnumT1;
28389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
28489a1d03eSRichard // CHECK-FIXES: using EnumT1 = enum { ea1, eb1 };
28589a1d03eSRichard 
28689a1d03eSRichard #include "modernize-use-using.h"
28789a1d03eSRichard 
28889a1d03eSRichard typedef enum { ea2, eb2 } EnumT2_CheckTypedefImpactFromAnotherFile;
28989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
29089a1d03eSRichard // CHECK-FIXES: using EnumT2_CheckTypedefImpactFromAnotherFile = enum { ea2, eb2 };
29189a1d03eSRichard 
29289a1d03eSRichard template <int A>
29389a1d03eSRichard struct InjectedClassName {
29489a1d03eSRichard   typedef InjectedClassName b;
29589a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
29689a1d03eSRichard   // CHECK-FIXES: using b = InjectedClassName;
29789a1d03eSRichard };
29889a1d03eSRichard 
29989a1d03eSRichard template <int>
30089a1d03eSRichard struct InjectedClassNameWithUnnamedArgument {
30189a1d03eSRichard   typedef InjectedClassNameWithUnnamedArgument b;
30289a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
30389a1d03eSRichard   // CHECK-FIXES: using b = InjectedClassNameWithUnnamedArgument;
30489a1d03eSRichard };
30589a1d03eSRichard 
30689a1d03eSRichard typedef struct { int a; union { int b; }; } PR50990;
30789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
30889a1d03eSRichard // CHECK-FIXES: using PR50990 = struct { int a; union { int b; }; };
30989a1d03eSRichard 
31089a1d03eSRichard typedef struct { struct { int a; struct { struct { int b; } c; int d; } e; } f; int g; } PR50990_nested;
31189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
31289a1d03eSRichard // CHECK-FIXES: using PR50990_nested = struct { struct { int a; struct { struct { int b; } c; int d; } e; } f; int g; };
31389a1d03eSRichard 
31489a1d03eSRichard typedef struct { struct { int a; } b; union { int c; float d; struct { int e; }; }; struct { double f; } g; } PR50990_siblings;
31589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
31689a1d03eSRichard // CHECK-FIXES: using PR50990_siblings = struct { struct { int a; } b; union { int c; float d; struct { int e; }; }; struct { double f; } g; };
31731ded495SCongcong Cai 
31831ded495SCongcong Cai typedef void (*ISSUE_65055_1)(int);
31931ded495SCongcong Cai typedef bool (*ISSUE_65055_2)(int);
32031ded495SCongcong Cai // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use 'using' instead of 'typedef'
32131ded495SCongcong Cai // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use 'using' instead of 'typedef'
32231ded495SCongcong Cai // CHECK-FIXES: {{^}}using ISSUE_65055_1 = void (*)(int);{{$}}
32331ded495SCongcong Cai // CHECK-FIXES: {{^}}using ISSUE_65055_2 = bool (*)(int);{{$}}
324eef35c28SQizhi Hu 
325eef35c28SQizhi Hu typedef class ISSUE_67529_1 *ISSUE_67529;
326eef35c28SQizhi Hu // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
327eef35c28SQizhi Hu // CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;
328583a2583SDa-Viper 
329583a2583SDa-Viper // Some Header
330583a2583SDa-Viper extern "C" {
331583a2583SDa-Viper 
332583a2583SDa-Viper typedef int InExternC;
333583a2583SDa-Viper // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
334583a2583SDa-Viper // CHECK-FIXES: using InExternC = int;
335583a2583SDa-Viper 
336583a2583SDa-Viper }
337583a2583SDa-Viper 
338583a2583SDa-Viper extern "C++" {
339583a2583SDa-Viper 
340583a2583SDa-Viper typedef int InExternCPP;
341583a2583SDa-Viper // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
342583a2583SDa-Viper // CHECK-FIXES: using InExternCPP = int;
343583a2583SDa-Viper 
344583a2583SDa-Viper }
3458ea94b61SFélix-Antoine Constantin 
3468ea94b61SFélix-Antoine Constantin namespace ISSUE_72179
3478ea94b61SFélix-Antoine Constantin {
3488ea94b61SFélix-Antoine Constantin   void foo()
3498ea94b61SFélix-Antoine Constantin   {
3508ea94b61SFélix-Antoine Constantin     typedef int a;
3518ea94b61SFélix-Antoine Constantin     // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 'typedef' [modernize-use-using]
3528ea94b61SFélix-Antoine Constantin     // CHECK-FIXES: using a = int;
3538ea94b61SFélix-Antoine Constantin 
3548ea94b61SFélix-Antoine Constantin   }
3558ea94b61SFélix-Antoine Constantin 
3568ea94b61SFélix-Antoine Constantin   void foo2()
3578ea94b61SFélix-Antoine Constantin   {
3588ea94b61SFélix-Antoine Constantin     typedef struct { int a; union { int b; }; } c;
3598ea94b61SFélix-Antoine Constantin     // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 'typedef' [modernize-use-using]
3608ea94b61SFélix-Antoine Constantin     // CHECK-FIXES: using c = struct { int a; union { int b; }; };
3618ea94b61SFélix-Antoine Constantin   }
3628ea94b61SFélix-Antoine Constantin 
3638ea94b61SFélix-Antoine Constantin   template <typename T>
3648ea94b61SFélix-Antoine Constantin   void foo3()
3658ea94b61SFélix-Antoine Constantin   {
3668ea94b61SFélix-Antoine Constantin     typedef T b;
3678ea94b61SFélix-Antoine Constantin     // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 'typedef' [modernize-use-using]
3688ea94b61SFélix-Antoine Constantin     // CHECK-FIXES: using b = T;
3698ea94b61SFélix-Antoine Constantin   }
3708ea94b61SFélix-Antoine Constantin 
3718ea94b61SFélix-Antoine Constantin   template <typename T>
3728ea94b61SFélix-Antoine Constantin   class MyClass
3738ea94b61SFélix-Antoine Constantin   {
3748ea94b61SFélix-Antoine Constantin     void foo()
3758ea94b61SFélix-Antoine Constantin     {
3768ea94b61SFélix-Antoine Constantin       typedef MyClass c;
3778ea94b61SFélix-Antoine Constantin       // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use 'using' instead of 'typedef' [modernize-use-using]
3788ea94b61SFélix-Antoine Constantin       // CHECK-FIXES: using c = MyClass;
3798ea94b61SFélix-Antoine Constantin     }
3808ea94b61SFélix-Antoine Constantin   };
3818ea94b61SFélix-Antoine Constantin 
3828ea94b61SFélix-Antoine Constantin   const auto foo4 = [](int a){typedef int d;};
3838ea94b61SFélix-Antoine Constantin   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: use 'using' instead of 'typedef' [modernize-use-using]
3848ea94b61SFélix-Antoine Constantin   // CHECK-FIXES: const auto foo4 = [](int a){using d = int;};
3858ea94b61SFélix-Antoine Constantin }
386*f77152d9SJulian Schmidt 
387*f77152d9SJulian Schmidt 
388*f77152d9SJulian Schmidt typedef int* int_ptr, *int_ptr_ptr;
389*f77152d9SJulian Schmidt // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
390*f77152d9SJulian Schmidt // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: use 'using' instead of 'typedef' [modernize-use-using]
391*f77152d9SJulian Schmidt // CHECK-FIXES: using int_ptr = int*;
392*f77152d9SJulian Schmidt // CHECK-FIXES-NEXT: using int_ptr_ptr = int_ptr*;
393*f77152d9SJulian Schmidt 
394*f77152d9SJulian Schmidt #ifndef SpecialMode
395*f77152d9SJulian Schmidt #define SomeMacro(x) x
396*f77152d9SJulian Schmidt #else
397*f77152d9SJulian Schmidt #define SomeMacro(x) SpecialType
398*f77152d9SJulian Schmidt #endif
399*f77152d9SJulian Schmidt 
400*f77152d9SJulian Schmidt class SomeMacro(GH33760) { };
401*f77152d9SJulian Schmidt 
402*f77152d9SJulian Schmidt typedef void(SomeMacro(GH33760)::* FunctionType)(float, int);
403*f77152d9SJulian Schmidt // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
404*f77152d9SJulian Schmidt // CHECK-FIXES: using FunctionType = void(SomeMacro(GH33760)::* )(float, int);
405*f77152d9SJulian Schmidt 
406*f77152d9SJulian Schmidt #define CDECL __attribute((cdecl))
407*f77152d9SJulian Schmidt 
408*f77152d9SJulian Schmidt // GH37846 & GH41685
409*f77152d9SJulian Schmidt typedef void (CDECL *GH37846)(int);
410*f77152d9SJulian Schmidt // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
411*f77152d9SJulian Schmidt // CHECK-FIXES: using GH37846 = void (CDECL *)(int);
412*f77152d9SJulian Schmidt 
413*f77152d9SJulian Schmidt typedef void (__attribute((cdecl)) *GH41685)(int);
414*f77152d9SJulian Schmidt // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
415*f77152d9SJulian Schmidt // CHECK-FIXES: using GH41685 = void (__attribute((cdecl)) *)(int);
416*f77152d9SJulian Schmidt 
417*f77152d9SJulian Schmidt namespace GH83568 {
418*f77152d9SJulian Schmidt   typedef int(*name)(int arg1, int arg2);
419*f77152d9SJulian Schmidt // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' [modernize-use-using]
420*f77152d9SJulian Schmidt // CHECK-FIXES: using name = int(*)(int arg1, int arg2);
421*f77152d9SJulian Schmidt }
422*f77152d9SJulian Schmidt 
423*f77152d9SJulian Schmidt #ifdef FOO
424*f77152d9SJulian Schmidt #define GH95716 float
425*f77152d9SJulian Schmidt #else
426*f77152d9SJulian Schmidt #define GH95716 double
427*f77152d9SJulian Schmidt #endif
428*f77152d9SJulian Schmidt 
429*f77152d9SJulian Schmidt typedef GH95716 foo;
430*f77152d9SJulian Schmidt // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
431*f77152d9SJulian Schmidt // CHECK-FIXES: using foo = GH95716;
432*f77152d9SJulian Schmidt 
433*f77152d9SJulian Schmidt namespace GH97009 {
434*f77152d9SJulian Schmidt   typedef double PointType[3];
435*f77152d9SJulian Schmidt // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' [modernize-use-using]
436*f77152d9SJulian Schmidt   typedef bool (*Function)(PointType, PointType);
437*f77152d9SJulian Schmidt // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' [modernize-use-using]
438*f77152d9SJulian Schmidt // CHECK-FIXES: using Function = bool (*)(PointType, PointType);
439*f77152d9SJulian Schmidt }
440