xref: /llvm-project/clang/test/SemaCXX/warn-unused-variables.cpp (revision 50dc219e8b1ca70a9b92aa3486c047636115cb27)
1 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -verify %s
2 template<typename T> void f() {
3   T t;
4   t = 17;
5 }
6 
7 // PR5407
8 struct A { A(); };
9 struct B { ~B(); };
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 
28   void test() {
29     A(); // expected-warning{{expression result unused}}
30     B(17);
31     C();
32   }
33 }
34 
35 
36 struct X {
37  int foo() __attribute__((warn_unused_result));
38 };
39 
40 void bah() {
41   X x, *x2;
42   x.foo(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}}
43   x2->foo(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}}
44 }
45 
46 template<typename T>
47 struct X0 { };
48 
49 template<typename T>
50 void test_dependent_init(T *p) {
51   X0<int> i(p);
52   (void)i;
53 }
54