• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -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 
44 namespace PR6948 {
45   template<typename T> class X; // expected-note{{template is declared here}}
46 
f()47   void f() {
48     X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}} \
49                                        expected-error{{implicit instantiation of undefined template 'PR6948::X<char>'}}
50   }
51 }
52 
unused_local_static()53 void unused_local_static() {
54   static int x = 0;
55   static int y = 0; // expected-warning{{unused variable 'y'}}
56 #pragma unused(x)
57 }
58 
59 // PR10168
60 namespace PR10168 {
61   // We expect a warning in the definition only for non-dependent variables, and
62   // a warning in the instantiation only for dependent variables.
63   template<typename T>
64   struct S {
fPR10168::S65     void f() {
66       int a; // expected-warning {{unused variable 'a'}}
67       T b; // expected-warning 2{{unused variable 'b'}}
68     }
69   };
70 
71   template<typename T>
f()72   void f() {
73     int a; // expected-warning {{unused variable 'a'}}
74     T b; // expected-warning 2{{unused variable 'b'}}
75   }
76 
g()77   void g() {
78     S<int>().f(); // expected-note {{here}}
79     S<char>().f(); // expected-note {{here}}
80     f<int>(); // expected-note {{here}}
81     f<char>(); // expected-note {{here}}
82   }
83 }
84 
85 namespace PR11550 {
86   struct S1 {
87     S1();
88   };
89   S1 makeS1();
testS1(S1 a)90   void testS1(S1 a) {
91     // This constructor call can be elided.
92     S1 x = makeS1(); // expected-warning {{unused variable 'x'}}
93 
94     // This one cannot, so no warning.
95     S1 y;
96 
97     // This call cannot, but the constructor is trivial.
98     S1 z = a; // expected-warning {{unused variable 'z'}}
99   }
100 
101   // The same is true even when we know thet constructor has side effects.
102   void foo();
103   struct S2 {
S2PR11550::S2104     S2() {
105       foo();
106     }
107   };
108   S2 makeS2();
testS2(S2 a)109   void testS2(S2 a) {
110     S2 x = makeS2(); // expected-warning {{unused variable 'x'}}
111     S2 y;
112     S2 z = a; // expected-warning {{unused variable 'z'}}
113   }
114 
115   // Or when the constructor is not declared by the user.
116   struct S3 {
117     S1 m;
118   };
119   S3 makeS3();
testS3(S3 a)120   void testS3(S3 a) {
121     S3 x = makeS3(); // expected-warning {{unused variable 'x'}}
122     S3 y;
123     S3 z = a; // expected-warning {{unused variable 'z'}}
124   }
125 }
126 
127 namespace ctor_with_cleanups {
128   struct S1 {
129     ~S1();
130   };
131   struct S2 {
132     S2(const S1&);
133   };
func()134   void func() {
135     S2 s((S1()));
136   }
137 }
138