1 | // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-inlining=constructors -verify %s |
2 | |
3 | void clang_analyzer_eval(bool); |
4 | |
5 | |
6 | struct A { |
7 | int x; |
8 | A(int a) { x = a; } |
9 | int getx() const { return x; } |
10 | }; |
11 | |
12 | struct B{ |
13 | int x; |
14 | }; |
15 | |
16 | void testNullObject(A *a) { |
17 | clang_analyzer_eval(a); // expected-warning{{UNKNOWN}} |
18 | (void)a->getx(); // assume we know what we're doing |
19 | clang_analyzer_eval(a); // expected-warning{{TRUE}} |
20 | } |
21 | |
22 | void f1() { |
23 | A x(3); |
24 | clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}} |
25 | } |
26 | |
27 | void f2() { |
28 | const A &x = A(3); |
29 | clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}} |
30 | } |
31 | |
32 | void f3() { |
33 | const A &x = (A)3; |
34 | clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}} |
35 | } |
36 | |
37 | void f4() { |
38 | A x = 3; |
39 | clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}} |
40 | } |
41 | |
42 | void checkThatCopyConstructorDoesNotInvalidateObjectBeingCopied() { |
43 | B t; |
44 | t.x = 0; |
45 | B t2(t); |
46 | clang_analyzer_eval(t.x == 0); // expected-warning{{TRUE}} |
47 | } |
48 | |