2013-01-25 07:15:30 +08:00
|
|
|
// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-inlining=constructors -verify %s
|
2010-11-01 17:09:44 +08:00
|
|
|
|
2012-05-17 00:01:10 +08:00
|
|
|
void clang_analyzer_eval(bool);
|
|
|
|
|
2012-08-16 05:56:23 +08:00
|
|
|
|
2010-04-20 13:48:57 +08:00
|
|
|
struct A {
|
|
|
|
int x;
|
|
|
|
A(int a) { x = a; }
|
2010-11-24 21:48:50 +08:00
|
|
|
int getx() const { return x; }
|
2010-04-20 13:48:57 +08:00
|
|
|
};
|
|
|
|
|
2012-10-31 09:18:26 +08:00
|
|
|
struct B{
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
|
2012-08-16 05:56:23 +08:00
|
|
|
void testNullObject(A *a) {
|
|
|
|
clang_analyzer_eval(a); // expected-warning{{UNKNOWN}}
|
|
|
|
(void)a->getx(); // assume we know what we're doing
|
|
|
|
clang_analyzer_eval(a); // expected-warning{{TRUE}}
|
|
|
|
}
|
|
|
|
|
2010-04-20 13:48:57 +08:00
|
|
|
void f1() {
|
|
|
|
A x(3);
|
2012-08-28 01:50:07 +08:00
|
|
|
clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}}
|
2010-04-20 13:48:57 +08:00
|
|
|
}
|
|
|
|
|
2010-11-25 11:18:57 +08:00
|
|
|
void f2() {
|
|
|
|
const A &x = A(3);
|
2012-08-28 01:50:07 +08:00
|
|
|
clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}}
|
2010-11-25 11:18:57 +08:00
|
|
|
}
|
|
|
|
|
2011-02-19 09:08:37 +08:00
|
|
|
void f3() {
|
|
|
|
const A &x = (A)3;
|
2012-08-28 01:50:07 +08:00
|
|
|
clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void f4() {
|
|
|
|
A x = 3;
|
|
|
|
clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}}
|
2011-02-19 09:08:37 +08:00
|
|
|
}
|
2012-10-31 09:18:26 +08:00
|
|
|
|
|
|
|
void checkThatCopyConstructorDoesNotInvalidateObjectBeingCopied() {
|
|
|
|
B t;
|
|
|
|
t.x = 0;
|
|
|
|
B t2(t);
|
|
|
|
clang_analyzer_eval(t.x == 0); // expected-warning{{TRUE}}
|
|
|
|
}
|