blob: 00597f929b259962ed1bced1cb2313b057ab2324 [file] [log] [blame]
Argyrios Kyrtzidis1b2ad2f2010-09-19 23:03:35 +00001// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -verify %s
Douglas Gregorb5352cf2009-10-08 21:35:42 +00002template<typename T> void f() {
Douglas Gregor4dffad62010-02-11 22:55:30 +00003 T t;
4 t = 17;
Douglas Gregorb5352cf2009-10-08 21:35:42 +00005}
Anders Carlssonf7613d52009-11-07 07:26:56 +00006
Anders Carlsson6a8b7f32009-11-07 08:24:59 +00007// PR5407
Anders Carlssonf7613d52009-11-07 07:26:56 +00008struct A { A(); };
9struct B { ~B(); };
Anders Carlssonf7613d52009-11-07 07:26:56 +000010void f() {
11 A a;
12 B b;
Anders Carlsson6a8b7f32009-11-07 08:24:59 +000013}
Anders Carlsson58beed92009-11-17 17:11:23 +000014
15// PR5531
16namespace PR5531 {
17 struct A {
18 };
19
20 struct B {
21 B(int);
22 };
23
24 struct C {
25 ~C();
26 };
27
28 void test() {
Douglas Gregored8abf12010-07-08 06:14:04 +000029 A();
Anders Carlsson58beed92009-11-17 17:11:23 +000030 B(17);
31 C();
32 }
33}
Nuno Lopescb1c77f2009-12-24 00:28:18 +000034
Douglas Gregor4dffad62010-02-11 22:55:30 +000035template<typename T>
36struct X0 { };
37
38template<typename T>
39void test_dependent_init(T *p) {
40 X0<int> i(p);
41 (void)i;
42}
Douglas Gregora6a292b2010-04-27 16:20:13 +000043
Douglas Gregor268f89e2010-11-09 14:57:47 +000044void unused_local_static() {
45 static int x = 0;
46 static int y = 0; // expected-warning{{unused variable 'y'}}
47#pragma unused(x)
48}
Richard Smithe3499ca2011-06-21 23:42:09 +000049
50// PR10168
51namespace 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 {
56 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>
63 void f() {
64 int a; // expected-warning {{unused variable 'a'}}
65 T b; // expected-warning 2{{unused variable 'b'}}
66 }
67
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}
Rafael Espindola1a5d3552012-01-06 04:54:01 +000075
76namespace PR11550 {
77 struct S1 {
78 S1();
79 };
80 S1 makeS1();
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 {
95 S2() {
96 foo();
97 }
98 };
99 S2 makeS2();
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();
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}
David Blaikie39e17762012-10-24 21:29:06 +0000117
118namespace ctor_with_cleanups {
119 struct S1 {
120 ~S1();
121 };
122 struct S2 {
123 S2(const S1&);
124 };
125 void func() {
126 S2 s((S1()));
127 }
128}
Matt Beaumont-Gay19b6a702013-04-10 00:47:10 +0000129
130#include "Inputs/warn-unused-variables.h"