1 // RUN: %clang_cc1 -fsyntax-only -Wunused-local-typedef -verify -std=c++1y %s
4 typedef int Foo
; // no diag
8 typedef int Foo
; // no diag
9 typedef int Foo2
; // no diag
12 template <class T
> class Vec
{};
14 typedef int global_foo
; // no diag
17 typedef int foo0
; // expected-warning {{unused typedef 'foo0'}}
18 using foo0alias
= int ; // expected-warning {{unused type alias 'foo0alias'}}
20 typedef int foo1
__attribute__((unused
)); // no diag
24 typedef int foo2
; // expected-warning {{unused typedef 'foo2'}}
26 typedef foo2 foo3
; // expected-warning {{unused typedef 'foo3'}}
28 typedef int foo2_2
; // expected-warning {{unused typedef 'foo2_2'}}
31 typedef foo2_2 foo3_2
; // expected-warning {{unused typedef 'foo3_2'}}
38 typedef foo5
* foo6
; // no diag
42 typedef int Foo
; // no diag
43 typedef int Foo2
; // expected-warning {{unused typedef 'Foo2'}}
46 typedef int DeepFoo
; // expected-warning {{unused typedef 'DeepFoo'}}
52 typedef struct {} foostruct
; // expected-warning {{unused typedef 'foostruct'}}
54 typedef struct {} foostruct2
; // no diag
57 typedef int vecint
; // no diag
62 typedef int ConstExprInt
;
63 static constexpr int a
= (ConstExprInt
)4;
66 int printf(char const *, ...);
69 typedef signed long int superint
; // no diag
70 printf("%ld", (superint
)42);
72 typedef signed long int superint2
; // no diag
73 printf("%ld", static_cast<superint2
>(42));
75 #pragma clang diagnostic push
76 #pragma clang diagnostic ignored "-Wunused-local-typedef"
77 typedef int trungl_bot_was_here
; // no diag
78 #pragma clang diagnostic pop
80 typedef int foo
; // expected-warning {{unused typedef 'foo'}}
84 void template_fun(T t
) {
85 typedef int foo
; // expected-warning {{unused typedef 'foo'}}
86 typedef int bar
; // no-diag
90 typedef int Foo
; // no diag
92 typedef int Foo2
; // expected-warning {{unused typedef 'Foo2'}}
94 typedef int Foo3
; // no diag
97 typename
S2::Foo s2foo
;
98 typename
T::Foo s3foo
;
100 typedef typename
S2::Foo3 TTSF
; // expected-warning {{unused typedef 'TTSF'}}
102 void template_fun_user() {
104 typedef int Foo
; // no-diag
105 typedef int Bar
; // expected-warning {{unused typedef 'Bar'}}
110 void typedef_in_nested_name() {
111 typedef struct { // expected-warning {{add a tag name}}
112 typedef int Foo
; // expected-note {{}}
113 } A
; // expected-note {{}}
116 using A2
= struct { // expected-warning {{add a tag name}} expected-note {{this alias declaration}}
117 typedef int Foo
; // expected-note {{}}
124 // Local typedefs can be used after the scope they were in has closed:
127 // Even if they aren't, this could be an inline function that could be used
128 // in another TU, so this shouldn't warn either:
132 typedef int p
; // expected-warning{{unused typedef 'p'}}
139 static auto static_sneaky() {
142 // This function has internal linkage, so we can warn:
143 typedef int s
; // expected-warning {{unused typedef 's'}}
147 auto sx
= static_sneaky();
150 auto sneaky_with_friends() {
154 // Can't warn if we have friends:
161 auto nstatic_sneaky() {
164 // This function has internal linkage, so we can warn:
165 typedef int s
; // expected-warning {{unused typedef 's'}}
169 auto nsx
= nstatic_sneaky();
170 decltype(nsx
)::t nsy
;
173 // Like sneaky(), but returning pointer to local type
175 struct remove_reference
{ typedef T type
; };
176 template<typename T
> struct remove_reference
<T
&> { typedef T type
; };
177 auto pointer_sneaky() {
184 remove_reference
<decltype(*pointer_sneaky())>::type::t py
;
186 // Like sneaky(), but returning templated struct referencing local type.
187 template <class T
> struct container
{ int a
; T t
; };
188 auto template_sneaky() {
193 return container
<S
>();
195 auto tx
= template_sneaky();
196 decltype(tx
.t
)::t ty
;
198 // Like sneaky(), but doing its sneakiness by returning a member function
200 auto sneaky_memfun() {
208 template <class T
> void sneaky_memfun_g(int T::*p
) {
212 void sneaky_memfun_h() {
213 sneaky_memfun_g(sneaky_memfun());
216 void typedefs_in_constructors() {
218 struct B
: public A
{
219 // Neither of these two should warn:
228 void *operator new(__SIZE_TYPE__
, void *p
) throw() { return p
; }
229 void placement_new_and_delete() {
231 char memory
[sizeof(MyStruct
)];
234 typedef MyStruct A_t1
;
235 MyStruct
*a
= new (p
) A_t1();
237 typedef MyStruct A_t2
;
241 // This should not disable any warnings:
242 #pragma clang diagnostic ignored "-Wunused-local-typedef"