struct ConcreteIntLocTest {
int *ptr;
ConcreteIntLocTest() : ptr(reinterpret_cast<int *>(0xDEADBEEF)) {}
};
void fConcreteIntLocTest() {
ConcreteIntLocTest();
}
using intptr_t = unsigned long long;
struct LocAsIntegerTest {
intptr_t ptr; int dontGetFilteredByNonPedanticMode = 0;
LocAsIntegerTest(void *ptr) : ptr(reinterpret_cast<intptr_t>(ptr)) {} };
void fLocAsIntegerTest() {
char c;
LocAsIntegerTest t(&c);
}
class NullPtrTest {
struct RecordType {
int x;
int y;
};
float *fptr = nullptr;
int *ptr;
RecordType *recPtr;
public:
NullPtrTest() : ptr(nullptr), recPtr(nullptr) {
}
};
void fNullPtrTest() {
NullPtrTest();
}
struct UntypedAllocaTest {
void *allocaPtr;
int dontGetFilteredByNonPedanticMode = 0;
UntypedAllocaTest() : allocaPtr(__builtin_alloca(sizeof(int))) {
}
};
void fUntypedAllocaTest() {
UntypedAllocaTest();
}
struct TypedAllocaTest1 {
int *allocaPtr; int dontGetFilteredByNonPedanticMode = 0;
TypedAllocaTest1() : allocaPtr(static_cast<int *>(__builtin_alloca(sizeof(int)))) {}
};
void fTypedAllocaTest1() {
TypedAllocaTest1();
}
struct TypedAllocaTest2 {
int *allocaPtr;
int dontGetFilteredByNonPedanticMode = 0;
TypedAllocaTest2()
: allocaPtr(static_cast<int *>(__builtin_alloca(sizeof(int)))) {
*allocaPtr = 55555;
}
};
void fTypedAllocaTest2() {
TypedAllocaTest2();
}
class HeapPointerTest1 {
struct RecordType {
int x; int y; };
float *fptr = new float; int *ptr; RecordType *recPtr;
public:
HeapPointerTest1() : ptr(new int), recPtr(new RecordType) { }
};
void fHeapPointerTest1() {
HeapPointerTest1();
}
class HeapPointerTest2 {
struct RecordType {
int x;
int y;
};
float *fptr = new float(); int *ptr;
RecordType *recPtr;
public:
HeapPointerTest2() : ptr(new int{25}), recPtr(new RecordType{26, 27}) {
}
};
void fHeapPointerTest2() {
HeapPointerTest2();
}
class StackPointerTest1 {
public:
struct RecordType {
int x;
int y;
};
private:
int *ptr;
RecordType *recPtr;
public:
StackPointerTest1(int *_ptr, StackPointerTest1::RecordType *_recPtr) : ptr(_ptr), recPtr(_recPtr) {
}
};
void fStackPointerTest1() {
int ok_a = 28;
StackPointerTest1::RecordType ok_rec{29, 30};
StackPointerTest1(&ok_a, &ok_rec); }
#ifdef PEDANTIC
class StackPointerTest2 {
public:
struct RecordType {
int x; int y; };
private:
int *ptr; RecordType *recPtr;
public:
StackPointerTest2(int *_ptr, RecordType *_recPtr) : ptr(_ptr), recPtr(_recPtr) { }
};
void fStackPointerTest2() {
int a;
StackPointerTest2::RecordType rec;
StackPointerTest2(&a, &rec); }
#else
class StackPointerTest2 {
public:
struct RecordType {
int x;
int y;
};
private:
int *ptr;
RecordType *recPtr;
public:
StackPointerTest2(int *_ptr, RecordType *_recPtr) : ptr(_ptr), recPtr(_recPtr) {
}
};
void fStackPointerTest2() {
int a;
StackPointerTest2::RecordType rec;
StackPointerTest2(&a, &rec); }
#endif
class UninitPointerTest {
struct RecordType {
int x;
int y;
};
int *ptr; RecordType *recPtr;
public:
UninitPointerTest() : recPtr(new RecordType{13, 13}) { }
};
void fUninitPointerTest() {
UninitPointerTest();
}
struct CharPointerTest {
const char *str;
int dontGetFilteredByNonPedanticMode = 0;
CharPointerTest() : str("") {}
};
void fCharPointerTest() {
CharPointerTest();
}
struct VectorSizePointer {
VectorSizePointer() {} __attribute__((__vector_size__(8))) int *x; int dontGetFilteredByNonPedanticMode = 0;
};
void __vector_size__PointerTest() {
VectorSizePointer v;
}
struct VectorSizePointee {
using MyVectorType = __attribute__((__vector_size__(8))) int;
MyVectorType *x;
VectorSizePointee(decltype(x) x) : x(x) {}
};
void __vector_size__PointeeTest() {
VectorSizePointee::MyVectorType i;
VectorSizePointee v(&i);
}
struct CyclicPointerTest1 {
int *ptr; int dontGetFilteredByNonPedanticMode = 0;
CyclicPointerTest1() : ptr(reinterpret_cast<int *>(&ptr)) {} };
void fCyclicPointerTest1() {
CyclicPointerTest1();
}
struct CyclicPointerTest2 {
int **pptr; int dontGetFilteredByNonPedanticMode = 0;
CyclicPointerTest2() : pptr(reinterpret_cast<int **>(&pptr)) {} };
void fCyclicPointerTest2() {
CyclicPointerTest2();
}
void *malloc(int size);
class VoidPointerTest1 {
void *vptr;
public:
VoidPointerTest1(void *vptr, char) : vptr(vptr) {
}
};
void fVoidPointerTest1() {
void *vptr = malloc(sizeof(int));
VoidPointerTest1(vptr, char());
}
class VoidPointerTest2 {
void **vpptr;
public:
VoidPointerTest2(void **vpptr, char) : vpptr(vpptr) {
}
};
void fVoidPointerTest2() {
void *vptr = malloc(sizeof(int));
VoidPointerTest2(&vptr, char());
}
class VoidPointerRRefTest1 {
void *&&vptrrref;
public:
VoidPointerRRefTest1(void *vptr, char) : vptrrref(static_cast<void *&&>(vptr)) { }
};
void fVoidPointerRRefTest1() {
void *vptr = malloc(sizeof(int));
VoidPointerRRefTest1(vptr, char());
}
class VoidPointerRRefTest2 {
void **&&vpptrrref;
public:
VoidPointerRRefTest2(void **vptr, char) : vpptrrref(static_cast<void **&&>(vptr)) { }
};
void fVoidPointerRRefTest2() {
void *vptr = malloc(sizeof(int));
VoidPointerRRefTest2(&vptr, char());
}
class VoidPointerLRefTest {
void *&vptrrref;
public:
VoidPointerLRefTest(void *vptr, char) : vptrrref(static_cast<void *&>(vptr)) { }
};
void fVoidPointerLRefTest() {
void *vptr = malloc(sizeof(int));
VoidPointerLRefTest(vptr, char());
}
struct CyclicVoidPointerTest {
void *vptr; int dontGetFilteredByNonPedanticMode = 0;
CyclicVoidPointerTest() : vptr(&vptr) {} };
void fCyclicVoidPointerTest() {
CyclicVoidPointerTest();
}
struct IntDynTypedVoidPointerTest1 {
void *vptr; int dontGetFilteredByNonPedanticMode = 0;
IntDynTypedVoidPointerTest1(void *vptr) : vptr(vptr) {} };
void fIntDynTypedVoidPointerTest1() {
int a;
IntDynTypedVoidPointerTest1 tmp(&a);
}
struct RecordDynTypedVoidPointerTest {
struct RecordType {
int x; int y; };
void *vptr;
int dontGetFilteredByNonPedanticMode = 0;
RecordDynTypedVoidPointerTest(void *vptr) : vptr(vptr) {} };
void fRecordDynTypedVoidPointerTest() {
RecordDynTypedVoidPointerTest::RecordType a;
RecordDynTypedVoidPointerTest tmp(&a);
}
struct NestedNonVoidDynTypedVoidPointerTest {
struct RecordType {
int x; int y; void *vptr; };
void *vptr;
int dontGetFilteredByNonPedanticMode = 0;
NestedNonVoidDynTypedVoidPointerTest(void *vptr, void *c) : vptr(vptr) {
static_cast<RecordType *>(vptr)->vptr = c; }
};
void fNestedNonVoidDynTypedVoidPointerTest() {
NestedNonVoidDynTypedVoidPointerTest::RecordType a;
char c;
NestedNonVoidDynTypedVoidPointerTest tmp(&a, &c);
}
#ifdef PEDANTIC
class MultiPointerTest1 {
public:
struct RecordType {
int x;
int y;
};
private:
RecordType **mptr;
public:
MultiPointerTest1(RecordType **p, int) : mptr(p) { }
};
void fMultiPointerTest1() {
MultiPointerTest1::RecordType *p1;
MultiPointerTest1::RecordType **mptr = &p1;
MultiPointerTest1(mptr, int()); }
#else
class MultiPointerTest1 {
public:
struct RecordType {
int x;
int y;
};
private:
RecordType **mptr;
public:
MultiPointerTest1(RecordType **p, int) : mptr(p) {}
};
void fMultiPointerTest1() {
MultiPointerTest1::RecordType *p1;
MultiPointerTest1::RecordType **mptr = &p1;
MultiPointerTest1(mptr, int()); }
#endif
#ifdef PEDANTIC
class MultiPointerTest2 {
public:
struct RecordType {
int x; int y; };
private:
RecordType **mptr;
public:
MultiPointerTest2(RecordType **p, int) : mptr(p) { }
};
void fMultiPointerTest2() {
MultiPointerTest2::RecordType i;
MultiPointerTest2::RecordType *p1 = &i;
MultiPointerTest2::RecordType **mptr = &p1;
MultiPointerTest2(mptr, int()); }
#else
class MultiPointerTest2 {
public:
struct RecordType {
int x;
int y;
};
private:
RecordType **mptr;
public:
MultiPointerTest2(RecordType **p, int) : mptr(p) {
}
};
void fMultiPointerTest2() {
MultiPointerTest2::RecordType i;
MultiPointerTest2::RecordType *p1 = &i;
MultiPointerTest2::RecordType **mptr = &p1;
MultiPointerTest2(mptr, int()); }
#endif
class MultiPointerTest3 {
public:
struct RecordType {
int x;
int y;
};
private:
RecordType **mptr;
public:
MultiPointerTest3(RecordType **p, int) : mptr(p) {
}
};
void fMultiPointerTest3() {
MultiPointerTest3::RecordType i{31, 32};
MultiPointerTest3::RecordType *p1 = &i;
MultiPointerTest3::RecordType **mptr = &p1;
MultiPointerTest3(mptr, int()); }
class IncompleteType;
struct IncompletePointeeTypeTest {
IncompleteType *pImpl; int dontGetFilteredByNonPedanticMode = 0;
IncompletePointeeTypeTest(IncompleteType *A) : pImpl(A) {}
};
void fIncompletePointeeTypeTest(void *ptr) {
IncompletePointeeTypeTest(reinterpret_cast<IncompleteType *>(ptr));
}
struct FunctionPointerWithDifferentDynTypeTest {
using Func1 = void *(*)();
using Func2 = int *(*)();
Func1 f; FunctionPointerWithDifferentDynTypeTest(Func2 f) : f((Func1)f) {}
};
struct UsefulFunctions {
int a, b;
void print() {}
void dump() {}
};
#ifdef PEDANTIC
struct PointerToMemberFunctionTest1 {
void (UsefulFunctions::*f)(void); PointerToMemberFunctionTest1() {}
};
void fPointerToMemberFunctionTest1() {
PointerToMemberFunctionTest1(); }
struct PointerToMemberFunctionTest2 {
void (UsefulFunctions::*f)(void);
PointerToMemberFunctionTest2(void (UsefulFunctions::*f)(void)) : f(f) {
}
};
void fPointerToMemberFunctionTest2() {
void (UsefulFunctions::*f)(void) = &UsefulFunctions::print;
PointerToMemberFunctionTest2 a(f);
}
struct MultiPointerToMemberFunctionTest1 {
void (UsefulFunctions::**f)(void); MultiPointerToMemberFunctionTest1() {}
};
void fMultiPointerToMemberFunctionTest1() {
MultiPointerToMemberFunctionTest1(); }
struct MultiPointerToMemberFunctionTest2 {
void (UsefulFunctions::**f)(void);
MultiPointerToMemberFunctionTest2(void (UsefulFunctions::**f)(void)) : f(f) {
}
};
void fMultiPointerToMemberFunctionTest2() {
void (UsefulFunctions::*f)(void) = &UsefulFunctions::print;
MultiPointerToMemberFunctionTest2 a(&f);
}
struct PointerToMemberDataTest1 {
int UsefulFunctions::*d; PointerToMemberDataTest1() {}
};
void fPointerToMemberDataTest1() {
PointerToMemberDataTest1(); }
struct PointerToMemberDataTest2 {
int UsefulFunctions::*d;
PointerToMemberDataTest2(int UsefulFunctions::*d) : d(d) {
}
};
void fPointerToMemberDataTest2() {
int UsefulFunctions::*d = &UsefulFunctions::a;
PointerToMemberDataTest2 a(d);
}
struct MultiPointerToMemberDataTest1 {
int UsefulFunctions::**d; MultiPointerToMemberDataTest1() {}
};
void fMultiPointerToMemberDataTest1() {
MultiPointerToMemberDataTest1(); }
struct MultiPointerToMemberDataTest2 {
int UsefulFunctions::**d;
MultiPointerToMemberDataTest2(int UsefulFunctions::**d) : d(d) {
}
};
void fMultiPointerToMemberDataTest2() {
int UsefulFunctions::*d = &UsefulFunctions::a;
MultiPointerToMemberDataTest2 a(&d);
}
#endif
class ListTest1 {
public:
struct Node {
Node *next = nullptr; int i;
};
private:
Node *head = nullptr;
public:
ListTest1() {
}
};
void fListTest1() {
ListTest1();
}
class ListTest2 {
public:
struct Node {
Node *next = nullptr;
int i; };
private:
Node *head = nullptr;
public:
ListTest2(Node *node, int) : head(node) { }
};
void fListTest2() {
ListTest2::Node n;
ListTest2(&n, int());
}
class CyclicList {
public:
struct Node {
Node *next = nullptr;
int i; };
private:
Node *head = nullptr;
public:
CyclicList(Node *node, int) : head(node) { }
};
void fCyclicList() {
CyclicList::Node n1;
CyclicList::Node n2;
n2.next = &n1;
n2.i = 50;
CyclicList::Node n3;
n3.next = &n2;
n3.i = 50;
n1.next = &n3;
CyclicList(&n1, int());
}
struct RingListTest {
RingListTest *next; RingListTest() : next(this) {}
};
void fRingListTest() {
RingListTest();
}
class ReferenceTest1 {
public:
struct RecordType {
int x;
int y;
};
private:
RecordType &lref;
RecordType &&rref;
public:
ReferenceTest1(RecordType &lref, RecordType &rref) : lref(lref), rref(static_cast<RecordType &&>(rref)) {
}
};
void fReferenceTest1() {
ReferenceTest1::RecordType d{33, 34};
ReferenceTest1(d, d);
}
#ifdef PEDANTIC
class ReferenceTest2 {
public:
struct RecordType {
int x; int y; };
private:
RecordType &lref;
RecordType &&rref;
public:
ReferenceTest2(RecordType &lref, RecordType &rref)
: lref(lref), rref(static_cast<RecordType &&>(rref)) { }
};
void fReferenceTest2() {
ReferenceTest2::RecordType c;
ReferenceTest2(c, c);
}
#else
class ReferenceTest2 {
public:
struct RecordType {
int x;
int y;
};
private:
RecordType &lref;
RecordType &&rref;
public:
ReferenceTest2(RecordType &lref, RecordType &rref)
: lref(lref), rref(static_cast<RecordType &&>(rref)) {
}
};
void fReferenceTest2() {
ReferenceTest2::RecordType c;
ReferenceTest2(c, c);
}
#endif
class ReferenceTest3 {
public:
struct RecordType {
int x; int y; };
private:
RecordType &lref;
RecordType &&rref;
public:
ReferenceTest3(RecordType &lref, RecordType &rref)
: lref(lref), rref(static_cast<RecordType &&>(rref)) { }
};
void fReferenceTest3() {
ReferenceTest3::RecordType c, d{35, 36};
ReferenceTest3(c, d);
}
class ReferenceTest4 {
public:
struct RecordType {
int x; int y; };
private:
RecordType &lref;
RecordType &&rref;
public:
ReferenceTest4(RecordType &lref, RecordType &rref)
: lref(lref), rref(static_cast<RecordType &&>(rref)) { }
};
void fReferenceTest5() {
ReferenceTest4::RecordType c, d{37, 38};
ReferenceTest4(d, c);
}
struct IntMultipleReferenceToSameObjectTest {
int *iptr; int &iref;
int dontGetFilteredByNonPedanticMode = 0;
IntMultipleReferenceToSameObjectTest(int *i) : iptr(i), iref(*i) {} };
void fIntMultipleReferenceToSameObjectTest() {
int a;
IntMultipleReferenceToSameObjectTest Test(&a);
}
struct IntReferenceWrapper1 {
int &a;
int dontGetFilteredByNonPedanticMode = 0;
IntReferenceWrapper1(int &a) : a(a) {} };
struct IntReferenceWrapper2 {
int &a;
int dontGetFilteredByNonPedanticMode = 0;
IntReferenceWrapper2(int &a) : a(a) {} };
void fMultipleObjectsReferencingTheSameObjectTest() {
int a;
IntReferenceWrapper1 T1(a);
IntReferenceWrapper2 T2(a);
}