• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify %s
f()2 template<typename T> void f() {
3   T t;
4   t = 17;
5 }
6 
7 // PR5407
8 struct A { A(); };
9 struct B { ~B(); };
f()10 void f() {
11   A a;
12   B b;
13 }
14 
15 // PR5531
16 namespace PR5531 {
17   struct A {
18   };
19 
20   struct B {
21     B(int);
22   };
23 
24   struct C {
25     ~C();
26   };
27 
test()28   void test() {
29     A();
30     B(17);
31     C();
32   }
33 }
34 
35 template<typename T>
36 struct X0 { };
37 
38 template<typename T>
test_dependent_init(T * p)39 void test_dependent_init(T *p) {
40   X0<int> i(p);
41   (void)i;
42 }
43 
unused_local_static()44 void unused_local_static() {
45   static int x = 0;
46   static int y = 0; // expected-warning{{unused variable 'y'}}
47 #pragma unused(x)
48 }
49 
50 // PR10168
51 namespace PR10168 {
52   // We expect a warning in the definition only for non-dependent variables, and
53   // a warning in the instantiation only for dependent variables.
54   template<typename T>
55   struct S {
fPR10168::S56     void f() {
57       int a; // expected-warning {{unused variable 'a'}}
58       T b; // expected-warning 2{{unused variable 'b'}}
59     }
60   };
61 
62   template<typename T>
f()63   void f() {
64     int a; // expected-warning {{unused variable 'a'}}
65     T b; // expected-warning 2{{unused variable 'b'}}
66   }
67 
g()68   void g() {
69     S<int>().f(); // expected-note {{here}}
70     S<char>().f(); // expected-note {{here}}
71     f<int>(); // expected-note {{here}}
72     f<char>(); // expected-note {{here}}
73   }
74 }
75 
76 namespace PR11550 {
77   struct S1 {
78     S1();
79   };
80   S1 makeS1();
testS1(S1 a)81   void testS1(S1 a) {
82     // This constructor call can be elided.
83     S1 x = makeS1(); // expected-warning {{unused variable 'x'}}
84 
85     // This one cannot, so no warning.
86     S1 y;
87 
88     // This call cannot, but the constructor is trivial.
89     S1 z = a; // expected-warning {{unused variable 'z'}}
90   }
91 
92   // The same is true even when we know thet constructor has side effects.
93   void foo();
94   struct S2 {
S2PR11550::S295     S2() {
96       foo();
97     }
98   };
99   S2 makeS2();
testS2(S2 a)100   void testS2(S2 a) {
101     S2 x = makeS2(); // expected-warning {{unused variable 'x'}}
102     S2 y;
103     S2 z = a; // expected-warning {{unused variable 'z'}}
104   }
105 
106   // Or when the constructor is not declared by the user.
107   struct S3 {
108     S1 m;
109   };
110   S3 makeS3();
testS3(S3 a)111   void testS3(S3 a) {
112     S3 x = makeS3(); // expected-warning {{unused variable 'x'}}
113     S3 y;
114     S3 z = a; // expected-warning {{unused variable 'z'}}
115   }
116 }
117 
118 namespace PR19305 {
119   template<typename T> int n = 0; // no warning
120   int a = n<int>;
121 
122   template<typename T> const int l = 0; // no warning
123   int b = l<int>;
124 
125   // PR19558
126   template<typename T> const int o = 0; // no warning
127   template<typename T> const int o<T*> = 0; // no warning
128   int c = o<int*>;
129 
130   template<> int o<void> = 0; // no warning
131   int d = o<void>;
132 
133   // FIXME: It'd be nice to warn here.
134   template<typename T> int m = 0;
135   template<typename T> int m<T*> = 0;
136 
137   template<> const int m<void> = 0; // expected-warning {{unused variable}}
138 }
139 
140 namespace ctor_with_cleanups {
141   struct S1 {
142     ~S1();
143   };
144   struct S2 {
145     S2(const S1&);
146   };
func()147   void func() {
148     S2 s((S1()));
149   }
150 }
151 
152 #include "Inputs/warn-unused-variables.h"
153