xref: /llvm-project/clang/test/SemaCXX/warn-unused-variables.cpp (revision 3698bf1c6d73c3d9597a835d17cb7780f73bd8ca)
1 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-value -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();
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 
55 namespace PR6948 {
56   template<typename T> class X;
57 
58   void f() {
59     X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}}
60   }
61 }
62