blob: 5ba1f2a5f34b21b24ad7304c5b14cbb0504b6824 [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
44namespace PR6948 {
45 template<typename T> class X;
46
47 void f() {
48 X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}}
49 }
50}
Douglas Gregor268f89e2010-11-09 14:57:47 +000051
52void unused_local_static() {
53 static int x = 0;
54 static int y = 0; // expected-warning{{unused variable 'y'}}
55#pragma unused(x)
56}
Richard Smithe3499ca2011-06-21 23:42:09 +000057
58// PR10168
59namespace PR10168 {
60 // We expect a warning in the definition only for non-dependent variables, and
61 // a warning in the instantiation only for dependent variables.
62 template<typename T>
63 struct S {
64 void f() {
65 int a; // expected-warning {{unused variable 'a'}}
66 T b; // expected-warning 2{{unused variable 'b'}}
67 }
68 };
69
70 template<typename T>
71 void f() {
72 int a; // expected-warning {{unused variable 'a'}}
73 T b; // expected-warning 2{{unused variable 'b'}}
74 }
75
76 void g() {
77 S<int>().f(); // expected-note {{here}}
78 S<char>().f(); // expected-note {{here}}
79 f<int>(); // expected-note {{here}}
80 f<char>(); // expected-note {{here}}
81 }
82}