1 // RUN: %clang_cc1 -fblocks -fsyntax-only -Wunused-but-set-variable -verify %s
2 
3 struct S {
4   int i;
5 };
6 
7 struct __attribute__((warn_unused)) SWarnUnused {
8   int j;
9   void operator +=(int);
10 };
11 
12 int f0() {
13   int y; // expected-warning{{variable 'y' set but not used}}
14   y = 0;
15 
16   int z __attribute__((unused));
17   z = 0;
18 
19   // In C++, don't warn for structs. (following gcc's behavior)
20   struct S s;
21   struct S t;
22   s = t;
23 
24   // Unless it's marked with the warn_unused attribute.
25   struct SWarnUnused swu; // expected-warning{{variable 'swu' set but not used}}
26   struct SWarnUnused swu2;
27   swu = swu2;
28 
29   int x;
30   x = 0;
31   return x + 5;
32 }
33 
34 void f1(void) {
35   (void)^() {
36     int y; // expected-warning{{variable 'y' set but not used}}
37     y = 0;
38 
39     int x;
40     x = 0;
41     return x;
42   };
43 }
44 
45 void f2() {
46   // Don't warn for either of these cases.
47   constexpr int x = 2;
48   const int y = 1;
49   char a[x];
50   char b[y];
51 }
52 
53 void f3(int n) {
54   // Don't warn for overloaded compound assignment operators.
55   SWarnUnused swu;
56   swu += n;
57 }
58 
59 template<typename T> void f4(T n) {
60   // Don't warn for (potentially) overloaded compound assignment operators in
61   // template code.
62   SWarnUnused swu;
63   swu += n;
64 }
65