[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Parser / warn-dangling-else.cpp
blobe91af9814ff97948d9a5484ffadb4aba0b39ca6d
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wdangling-else %s
3 void f(int a, int b, int c, int d, int e) {
5 // should warn
6 { if (a) if (b) d++; else e++; } // expected-warning {{add explicit braces to avoid dangling else}}
7 { if (a) while (b) if (c) d++; else e++; } // expected-warning {{add explicit braces to avoid dangling else}}
8 { if (a) switch (b) if (c) d++; else e++; } // expected-warning {{add explicit braces to avoid dangling else}}
9 { if (a) for (;;) if (c) d++; else e++; } // expected-warning {{add explicit braces to avoid dangling else}}
10 { if (a) if (b) if (d) d++; else e++; else d--; } // expected-warning {{add explicit braces to avoid dangling else}}
12 if (a)
13 if (b) {
14 d++;
15 } else e++; // expected-warning {{add explicit braces to avoid dangling else}}
17 // shouldn't
18 { if (a) if (b) d++; }
19 { if (a) if (b) if (c) d++; }
20 { if (a) if (b) d++; else e++; else d--; }
21 { if (a) if (b) if (d) d++; else e++; else d--; else e--; }
22 { if (a) do if (b) d++; else e++; while (c); }
24 if (a) {
25 if (b) d++;
26 else e++;
29 if (a) {
30 if (b) d++;
31 } else e++;
34 // Somewhat more elaborate case that shouldn't warn.
35 class A {
36 public:
37 void operator<<(const char* s) {}
40 void HandleDisabledThing() {}
41 A GetThing() { return A(); }
43 #define FOO(X) \
44 switch (0) default: \
45 if (!(X)) \
46 HandleDisabledThing(); \
47 else \
48 GetThing()
50 void f(bool cond) {
51 int x = 0;
52 if (cond)
53 FOO(x) << "hello"; // no warning