Debian Codegraph @

clang/test/Analysis/cxx-inherited-ctor-init-expr.cpp

raw
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
2
3 void clang_analyzer_eval(bool);
4
5 namespace basic_tests {
6 struct A {
7 int x;
8 A(int x): x(x) {}
9 };
10
11 struct B : A {
12 using A::A;
13 };
14
15 struct C : B {
16 using B::B;
17 };
18
19 void test_B() {
20 B b(1);
21 clang_analyzer_eval(b.x == 1); // expected-warning{{TRUE}}
22 }
23
24 void test_C() {
25 C c(2);
26 clang_analyzer_eval(c.x == 2); // expected-warning{{TRUE}}
27 }
28 } // namespace basic_tests
29
30 namespace arguments_with_constructors {
31 struct S {
32 int x, y;
33 S(int x, int y): x(x), y(y) {}
34 ~S() {}
35 };
36
37 struct A {
38 S s;
39 int z;
40 A(S s, int z) : s(s), z(z) {}
41 };
42
43 struct B : A {
44 using A::A;
45 };
46
47 void test_B() {
48 B b(S(1, 2), 3);
49 // FIXME: There should be no execution path on which this is false.
50 clang_analyzer_eval(b.s.x == 1); // expected-warning{{TRUE}}
51 // expected-warning@-1{{FALSE}}
52
53 // FIXME: There should be no execution path on which this is false.
54 clang_analyzer_eval(b.s.y == 2); // expected-warning{{TRUE}}
55 // expected-warning@-1{{FALSE}}
56
57 clang_analyzer_eval(b.z == 3); // expected-warning{{TRUE}}
58 }
59 } // namespace arguments_with_constructors
60
61 namespace inherited_constructor_crash {
62 class a {
63 public:
64 a(int);
65 };
66 struct b : a {
67 using a::a; // Ihnerited ctor.
68 };
69 void c() {
70 int d;
71 // This construct expr utilizes the inherited ctor.
72 // Note that d must be uninitialized to cause the crash.
73 (b(d)); // expected-warning{{1st function call argument is an uninitialized value}}
74 }
75 } // namespace inherited_constructor_crash