void clang_analyzer_eval(bool);
typedef __typeof__(sizeof(int)) size_t;
extern "C" void *malloc(size_t);
int someGlobal;
void testImplicitlyDeclaredGlobalNew() {
if (someGlobal != 0)
return;
void *x = ::operator new(0);
::operator delete(x);
clang_analyzer_eval(someGlobal == 0); }
inline void* operator new(size_t, void* __p) throw()
{
return __p;
}
void *testPlacementNew() {
int *x = (int *)malloc(sizeof(int));
*x = 1;
clang_analyzer_eval(*x == 1);
void *y = new (x) int;
clang_analyzer_eval(x == y); clang_analyzer_eval(*x == 1);
return y;
}
void *operator new(size_t, size_t, int *);
void *testCustomNew() {
int x[1] = {1};
clang_analyzer_eval(*x == 1);
void *y = new (0, x) int;
clang_analyzer_eval(*x == 1);
return y; }
void *operator new(size_t, void *, void *);
void *testCustomNewMalloc() {
int *x = (int *)malloc(sizeof(int));
void *y = new (0, x) int;
return y;
}
void testScalarInitialization() {
int *n = new int(3);
clang_analyzer_eval(*n == 3);
new (n) int();
clang_analyzer_eval(*n == 0);
new (n) int{3};
clang_analyzer_eval(*n == 3);
new (n) int{};
clang_analyzer_eval(*n == 0); }
struct PtrWrapper {
int *x;
PtrWrapper(int *input) : x(input) {}
};
PtrWrapper *testNewInvalidation() {
return new PtrWrapper(static_cast<int *>(malloc(4)));
}
int testNoInitialization() {
int *n = new int;
if (*n) { return 0;
}
return 1;
}
int testNoInitializationPlacement() {
int n;
new (&n) int;
if (n) { return 0;
}
return 1;
}