[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / warn-unused-but-set-variables-cpp.cpp
blob418baa78aa964b37fd751b61eec9bd62cabb6895
1 // RUN: %clang_cc1 -fblocks -fsyntax-only -Wunused-but-set-variable -verify %s
3 struct S {
4 int i;
5 };
7 struct __attribute__((warn_unused)) SWarnUnused {
8 int j;
9 void operator +=(int);
10 void operator ++();
13 int f0() {
14 int y; // expected-warning{{variable 'y' set but not used}}
15 y = 0;
17 int z __attribute__((unused));
18 z = 0;
20 // In C++, don't warn for structs. (following gcc's behavior)
21 struct S s;
22 struct S t;
23 s = t;
25 // Unless it's marked with the warn_unused attribute.
26 struct SWarnUnused swu; // expected-warning{{variable 'swu' set but not used}}
27 struct SWarnUnused swu2;
28 swu = swu2;
30 int x;
31 x = 0;
32 return x + 5;
35 void f1(void) {
36 (void)^() {
37 int y; // expected-warning{{variable 'y' set but not used}}
38 y = 0;
40 int x;
41 x = 0;
42 return x;
46 void f2() {
47 // Don't warn for either of these cases.
48 constexpr int x = 2;
49 const int y = 1;
50 char a[x];
51 char b[y];
54 void f3(int n) {
55 // Don't warn for overloaded compound assignment operators.
56 SWarnUnused swu;
57 swu += n;
60 template<typename T> void f4(T n) {
61 // Don't warn for (potentially) overloaded compound assignment operators in
62 // template code.
63 SWarnUnused swu;
64 swu += n;
67 template <typename T> void f5() {
68 // Don't warn for overloaded pre/post operators in template code.
69 SWarnUnused swu;
70 ++swu;