1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
// RUN: %clang_analyze_cc1 %s -verify -analyzer-checker=core,debug.ExprInspection
// Refer to https://github.com/llvm/llvm-project/issues/70464 for more details.
//
// When the base class does not have a declared constructor, the base
// initializer in the constructor of the derived class should use the given
// initializer list to finish the initialization of the base class.
//
// Also testing base constructor and delegate constructor to make sure this
// change will not break these two cases when a CXXConstructExpr is available.
void clang_analyzer_dump(int);
namespace init_list {
struct Base {
int foox;
};
class Derived : public Base {
public:
Derived() : Base{42} {
// The dereference to this->foox below should be initialized properly.
clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
}
};
void entry() { Derived test; }
} // namespace init_list
namespace base_ctor_call {
struct Base {
int foox;
Base(int x) : foox(x) {}
};
class Derived : public Base {
public:
Derived() : Base{42} {
clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
}
};
void entry() { Derived test; }
} // namespace base_ctor_call
namespace delegate_ctor_call {
struct Base {
int foox;
};
struct Derived : Base {
Derived(int parx) { this->foox = parx; }
Derived() : Derived{42} {
clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
}
};
void entry() { Derived test; }
} // namespace delegate_ctor_call
// Additional test case from issue #59493
namespace init_list_array {
struct Base {
int foox[5];
};
class Derived1 : public Base {
public:
Derived1() : Base{{1,4,5,3,2}} {
// The dereference to this->foox below should be initialized properly.
clang_analyzer_dump(this->foox[0]); // expected-warning{{1 S32b}}
clang_analyzer_dump(this->foox[1]); // expected-warning{{4 S32b}}
clang_analyzer_dump(this->foox[2]); // expected-warning{{5 S32b}}
clang_analyzer_dump(this->foox[3]); // expected-warning{{3 S32b}}
clang_analyzer_dump(this->foox[4]); // expected-warning{{2 S32b}}
clang_analyzer_dump(foox[0]); // expected-warning{{1 S32b}}
clang_analyzer_dump(foox[1]); // expected-warning{{4 S32b}}
clang_analyzer_dump(foox[2]); // expected-warning{{5 S32b}}
clang_analyzer_dump(foox[3]); // expected-warning{{3 S32b}}
clang_analyzer_dump(foox[4]); // expected-warning{{2 S32b}}
}
};
void entry1() { Derived1 test; }
class Derived2 : public Base {
public:
Derived2() : Base{{0}} {
// The dereference to this->foox below should be initialized properly.
clang_analyzer_dump(this->foox[0]); // expected-warning{{0 S32b}}
clang_analyzer_dump(this->foox[1]); // expected-warning{{0 S32b}}
clang_analyzer_dump(this->foox[2]); // expected-warning{{0 S32b}}
clang_analyzer_dump(this->foox[3]); // expected-warning{{0 S32b}}
clang_analyzer_dump(this->foox[4]); // expected-warning{{0 S32b}}
clang_analyzer_dump(foox[0]); // expected-warning{{0 S32b}}
clang_analyzer_dump(foox[1]); // expected-warning{{0 S32b}}
clang_analyzer_dump(foox[2]); // expected-warning{{0 S32b}}
clang_analyzer_dump(foox[3]); // expected-warning{{0 S32b}}
clang_analyzer_dump(foox[4]); // expected-warning{{0 S32b}}
}
};
void entry2() { Derived2 test; }
} // namespace init_list_array
namespace init_list_struct {
struct Base {
struct { int a; int b; } foox;
};
class Derived : public Base {
public:
Derived() : Base{{42, 24}} {
// The dereference to this->foox below should be initialized properly.
clang_analyzer_dump(this->foox.a); // expected-warning{{42 S32b}}
clang_analyzer_dump(this->foox.b); // expected-warning{{24 S32b}}
clang_analyzer_dump(foox.a); // expected-warning{{42 S32b}}
clang_analyzer_dump(foox.b); // expected-warning{{24 S32b}}
}
};
} // namespace init_list_struct
// Additional test case from issue 54533
namespace init_list_enum {
struct Base {
enum : unsigned char { ZERO = 0, FORTY_TWO = 42 } foox;
};
class Derived : public Base {
public:
Derived() : Base{FORTY_TWO} {
// The dereference to this->foox below should be initialized properly.
clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
}
};
void entry() { Derived test; }
} // namespace init_list_enum
|