2012-08-25 09:06:23 +08:00
|
|
|
// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-ipa=inlining -cfg-add-implicit-dtors -std=c++11 -verify %s
|
2012-07-27 04:04:21 +08:00
|
|
|
|
2012-08-01 02:04:59 +08:00
|
|
|
// We don't inline constructors unless we have destructors turned on.
|
2012-05-17 00:01:10 +08:00
|
|
|
|
|
|
|
void clang_analyzer_eval(bool);
|
2010-11-16 15:52:17 +08:00
|
|
|
|
|
|
|
class A {
|
|
|
|
int x;
|
|
|
|
public:
|
|
|
|
A();
|
|
|
|
};
|
|
|
|
|
|
|
|
A::A() : x(0) {
|
2012-05-17 00:01:10 +08:00
|
|
|
clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
|
2010-11-16 15:52:17 +08:00
|
|
|
}
|
2012-07-27 04:04:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
class DirectMember {
|
|
|
|
int x;
|
|
|
|
public:
|
|
|
|
DirectMember(int value) : x(value) {}
|
|
|
|
|
|
|
|
int getX() { return x; }
|
|
|
|
};
|
|
|
|
|
|
|
|
void testDirectMember() {
|
|
|
|
DirectMember obj(3);
|
|
|
|
clang_analyzer_eval(obj.getX() == 3); // expected-warning{{TRUE}}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class IndirectMember {
|
|
|
|
struct {
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
public:
|
|
|
|
IndirectMember(int value) : x(value) {}
|
|
|
|
|
|
|
|
int getX() { return x; }
|
|
|
|
};
|
|
|
|
|
|
|
|
void testIndirectMember() {
|
|
|
|
IndirectMember obj(3);
|
|
|
|
clang_analyzer_eval(obj.getX() == 3); // expected-warning{{TRUE}}
|
|
|
|
}
|
2012-08-03 05:33:42 +08:00
|
|
|
|
|
|
|
|
2012-08-04 07:31:15 +08:00
|
|
|
struct DelegatingConstructor {
|
|
|
|
int x;
|
|
|
|
DelegatingConstructor(int y) { x = y; }
|
|
|
|
DelegatingConstructor() : DelegatingConstructor(42) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void testDelegatingConstructor() {
|
|
|
|
DelegatingConstructor obj;
|
|
|
|
clang_analyzer_eval(obj.x == 42); // expected-warning{{TRUE}}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-03 05:33:42 +08:00
|
|
|
struct RefWrapper {
|
|
|
|
RefWrapper(int *p) : x(*p) {}
|
|
|
|
RefWrapper(int &r) : x(r) {}
|
|
|
|
int &x;
|
|
|
|
};
|
|
|
|
|
|
|
|
void testReferenceMember() {
|
|
|
|
int *p = 0;
|
2012-08-25 09:06:23 +08:00
|
|
|
RefWrapper X(p); // expected-warning@61 {{Dereference of null pointer}}
|
2012-08-03 05:33:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void testReferenceMember2() {
|
|
|
|
int *p = 0;
|
2012-08-25 09:06:23 +08:00
|
|
|
// FIXME: We should warn here, since we're creating the reference here.
|
|
|
|
RefWrapper X(*p); // expected-warning@62 {{Dereference of null pointer}}
|
2012-08-03 05:33:42 +08:00
|
|
|
}
|
2012-08-25 09:06:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
extern "C" char *strdup(const char *);
|
|
|
|
|
|
|
|
class StringWrapper {
|
|
|
|
char *str;
|
|
|
|
public:
|
|
|
|
StringWrapper(const char *input) : str(strdup(input)) {} // no-warning
|
|
|
|
};
|