blob: b561e65ac86ea494536073619b0d44c7fa36ad80 [file] [log] [blame]
Dominic Chen184c6242017-03-03 18:02:02 +00001// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=debug.ExprInspection %s
Jordan Rose61e221f2013-04-09 02:30:33 +00002
3void clang_analyzer_eval(bool);
4
5enum class Foo {
6 Zero
7};
8
9bool pr15703(int x) {
10 return Foo::Zero == (Foo)x; // don't crash
11}
12
13void testCasting(int i) {
14 Foo f = static_cast<Foo>(i);
15 int j = static_cast<int>(f);
16 if (i == 0)
17 {
18 clang_analyzer_eval(f == Foo::Zero); // expected-warning{{TRUE}}
19 clang_analyzer_eval(j == 0); // expected-warning{{TRUE}}
20 }
21 else
22 {
23 clang_analyzer_eval(f == Foo::Zero); // expected-warning{{FALSE}}
24 clang_analyzer_eval(j == 0); // expected-warning{{FALSE}}
25 }
26}
Alexander Shaposhnikov015da352017-04-21 01:05:26 +000027
28enum class EnumBool : bool {
29 F = false,
30 T = true
31};
32
33bool testNoCrashOnSwitchEnumBool(EnumBool E) {
34 switch (E) {
35 case EnumBool::F:
36 return false;
37 }
38 return true;
39}