intconst*const**icpcpp=reinterpret_cast<intconst*const**>(ipppc);// expected-error {{reinterpret_cast from 'int ***' to 'const int *const **' casts away qualifiers}}
(void)reinterpret_cast<intstructure::*>(psi);// expected-error {{reinterpret_cast from 'const int structure::*' to 'int structure::*' casts away qualifiers}}
(void)reinterpret_cast<void(structure::*)()>(psi);// expected-error-re {{reinterpret_cast from 'const int structure::*' to 'void (structure::*)(){{( __attribute__\(\(thiscall\)\))?}}' is not allowed}}
(void)reinterpret_cast<intstructure::*>(psf);// expected-error-re {{reinterpret_cast from 'void (structure::*)(){{( __attribute__\(\(thiscall\)\))?}}' to 'int structure::*' is not allowed}}
(void)reinterpret_cast<void(structure::*)()>(0);// expected-error-re {{reinterpret_cast from 'int' to 'void (structure::*)(){{( __attribute__\(\(thiscall\)\))?}}' is not allowed}}
(void)reinterpret_cast<double&>(l);// expected-warning {{reinterpret_cast from 'long' to 'double &' has undefined behavior}}
(void)*reinterpret_cast<double*>(&l);// expected-warning {{dereference of type 'double *' that was reinterpret_cast from type 'long *' has undefined behavior}}
(void)reinterpret_cast<double&>(f);// expected-warning {{reinterpret_cast from 'float' to 'double &' has undefined behavior}}
(void)*reinterpret_cast<double*>(&f);// expected-warning {{dereference of type 'double *' that was reinterpret_cast from type 'float *' has undefined behavior}}
(void)reinterpret_cast<float&>(l);// expected-warning {{reinterpret_cast from 'long' to 'float &' has undefined behavior}}
(void)*reinterpret_cast<float*>(&l);// expected-warning {{dereference of type 'float *' that was reinterpret_cast from type 'long *' has undefined behavior}}
(void)reinterpret_cast<float&>(d);// expected-warning {{reinterpret_cast from 'double' to 'float &' has undefined behavior}}
(void)*reinterpret_cast<float*>(&d);// expected-warning {{dereference of type 'float *' that was reinterpret_cast from type 'double *' has undefined behavior}}
// TODO: add warning for tag types
(void)reinterpret_cast<A&>(b);
(void)*reinterpret_cast<A*>(&b);
(void)reinterpret_cast<B&>(a);
(void)*reinterpret_cast<B*>(&a);
(void)reinterpret_cast<A2&>(b2);
(void)*reinterpret_cast<A2*>(&b2);
(void)reinterpret_cast<B2&>(a2);
(void)*reinterpret_cast<B2*>(&a2);
// Casting to itself is allowed
(void)reinterpret_cast<A&>(a);
(void)*reinterpret_cast<A*>(&a);
(void)reinterpret_cast<B&>(b);
(void)*reinterpret_cast<B*>(&b);
(void)reinterpret_cast<long&>(l);
(void)*reinterpret_cast<long*>(&l);
(void)reinterpret_cast<double&>(d);
(void)*reinterpret_cast<double*>(&d);
(void)reinterpret_cast<char&>(c);
(void)*reinterpret_cast<char*>(&c);
// Casting to and from chars are allowable
(void)reinterpret_cast<A&>(c);
(void)*reinterpret_cast<A*>(&c);
(void)reinterpret_cast<B&>(c);
(void)*reinterpret_cast<B*>(&c);
(void)reinterpret_cast<long&>(c);
(void)*reinterpret_cast<long*>(&c);
(void)reinterpret_cast<double&>(c);
(void)*reinterpret_cast<double*>(&c);
(void)reinterpret_cast<char&>(l);
(void)*reinterpret_cast<char*>(&l);
(void)reinterpret_cast<char&>(d);
(void)*reinterpret_cast<char*>(&d);
(void)reinterpret_cast<char&>(f);
(void)*reinterpret_cast<char*>(&f);
// Casting from void pointer.
(void)*reinterpret_cast<A*>(v_ptr);
(void)*reinterpret_cast<B*>(v_ptr);
(void)*reinterpret_cast<long*>(v_ptr);
(void)*reinterpret_cast<double*>(v_ptr);
(void)*reinterpret_cast<float*>(v_ptr);
// Casting to void pointer
(void)*reinterpret_cast<void*>(&a);
(void)*reinterpret_cast<void*>(&b);
(void)*reinterpret_cast<void*>(&l);
(void)*reinterpret_cast<void*>(&d);
(void)*reinterpret_cast<void*>(&f);
}
voidreinterpret_cast_whitelist(){
// the dynamic type of the object
inta;
floatb;
(void)reinterpret_cast<int&>(a);
(void)*reinterpret_cast<int*>(&a);
(void)reinterpret_cast<float&>(b);
(void)*reinterpret_cast<float*>(&b);
// a cv-qualified version of the dynamic object
(void)reinterpret_cast<constint&>(a);
(void)*reinterpret_cast<constint*>(&a);
(void)reinterpret_cast<volatileint&>(a);
(void)*reinterpret_cast<volatileint*>(&a);
(void)reinterpret_cast<constvolatileint&>(a);
(void)*reinterpret_cast<constvolatileint*>(&a);
(void)reinterpret_cast<constfloat&>(b);
(void)*reinterpret_cast<constfloat*>(&b);
(void)reinterpret_cast<volatilefloat&>(b);
(void)*reinterpret_cast<volatilefloat*>(&b);
(void)reinterpret_cast<constvolatilefloat&>(b);
(void)*reinterpret_cast<constvolatilefloat*>(&b);
// a type that is the signed or unsigned type corresponding to the dynamic
// type of the object
signedd;
unsignede;
(void)reinterpret_cast<signed&>(d);
(void)*reinterpret_cast<signed*>(&d);
(void)reinterpret_cast<signed&>(e);
(void)*reinterpret_cast<signed*>(&e);
(void)reinterpret_cast<unsigned&>(d);
(void)*reinterpret_cast<unsigned*>(&d);
(void)reinterpret_cast<unsigned&>(e);
(void)*reinterpret_cast<unsigned*>(&e);
// a type that is the signed or unsigned type corresponding a cv-qualified