1a6115068cde719142eb394db88612c185cabd05bEli Friedman// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding -Wundefined-reinterpret-cast -Wno-unused-volatile-lvalue %s 22f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor 3f1cd5e5c85f2ad433874310d826c1860a262909cSean Hunt#include <stdint.h> 4f1cd5e5c85f2ad433874310d826c1860a262909cSean Hunt 52f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregorenum test { testval = 1 }; 62f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregorstruct structure { int m; }; 72f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregortypedef void (*fnptr)(); 82f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor 92f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor// Test the conversion to self. 102f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregorvoid self_conversion() 112f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor{ 1241f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier // T->T is allowed per [expr.reinterpret.cast]p2 so long as it doesn't 1341f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier // cast away constness, and is integral, enumeration, pointer or 1441f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier // pointer-to-member. 152f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor int i = 0; 1641f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier (void)reinterpret_cast<int>(i); 1741f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier 1841f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier test e = testval; 1941f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier (void)reinterpret_cast<test>(e); 2041f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier 2141f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier // T*->T* is allowed 222f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor int *pi = 0; 232f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor (void)reinterpret_cast<int*>(pi); 2441f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier 2541f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier const int structure::*psi = 0; 2641f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier (void)reinterpret_cast<const int structure::*>(psi); 2741f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier 2841f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier structure s; 2941f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier (void)reinterpret_cast<structure>(s); // expected-error {{reinterpret_cast from 'structure' to 'structure' is not allowed}} 3041f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier 3141f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier float f = 0.0f; 3241f4431f3989ff23029eaf2ad947f07e39fb268cChad Rosier (void)reinterpret_cast<float>(f); // expected-error {{reinterpret_cast from 'float' to 'float' is not allowed}} 332f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor} 342f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor 352f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor// Test conversion between pointer and integral types, as in /3 and /4. 362f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregorvoid integral_conversion() 372f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor{ 382f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor void *vp = reinterpret_cast<void*>(testval); 39f1cd5e5c85f2ad433874310d826c1860a262909cSean Hunt intptr_t i = reinterpret_cast<intptr_t>(vp); 40f1cd5e5c85f2ad433874310d826c1860a262909cSean Hunt (void)reinterpret_cast<float*>(i); 41f1cd5e5c85f2ad433874310d826c1860a262909cSean Hunt fnptr fnp = reinterpret_cast<fnptr>(i); 422f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor (void)reinterpret_cast<char>(fnp); // expected-error {{cast from pointer to smaller type 'char' loses information}} 43f1cd5e5c85f2ad433874310d826c1860a262909cSean Hunt (void)reinterpret_cast<intptr_t>(fnp); 442f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor} 452f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor 462f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregorvoid pointer_conversion() 472f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor{ 482f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor int *p1 = 0; 492f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor float *p2 = reinterpret_cast<float*>(p1); 502f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor structure *p3 = reinterpret_cast<structure*>(p2); 512f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor typedef int **ppint; 522f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor ppint *deep = reinterpret_cast<ppint*>(p3); 532f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor (void)reinterpret_cast<fnptr*>(deep); 542f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor} 552f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor 562f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregorvoid constness() 572f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor{ 582f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor int ***const ipppc = 0; 592f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor // Valid: T1* -> T2 const* 602f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor int const *icp = reinterpret_cast<int const*>(ipppc); 612f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor // Invalid: T1 const* -> T2* 62d4c5f84bbed2ecb5ddd0f0e8316c553b2084772aDouglas Gregor (void)reinterpret_cast<int*>(icp); // expected-error {{reinterpret_cast from 'const int *' to 'int *' casts away qualifiers}} 632f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor // Invalid: T1*** -> T2 const* const** 64d4c5f84bbed2ecb5ddd0f0e8316c553b2084772aDouglas Gregor int const *const **icpcpp = reinterpret_cast<int const* const**>(ipppc); // expected-error {{reinterpret_cast from 'int ***' to 'const int *const **' casts away qualifiers}} 652f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor // Valid: T1* -> T2* 662f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor int *ip = reinterpret_cast<int*>(icpcpp); 672f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor // Valid: T* -> T const* 682f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor (void)reinterpret_cast<int const*>(ip); 692f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor // Valid: T*** -> T2 const* const* const* 702f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor (void)reinterpret_cast<int const* const* const*>(ipppc); 712f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor} 722f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor 732f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregorvoid fnptrs() 742f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor{ 752f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor typedef int (*fnptr2)(int); 762f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor fnptr fp = 0; 772f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor (void)reinterpret_cast<fnptr2>(fp); 782f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor void *vp = reinterpret_cast<void*>(fp); 792f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor (void)reinterpret_cast<fnptr>(vp); 802f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor} 812f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor 822f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregorvoid refs() 832f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor{ 842f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor long l = 0; 852f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor char &c = reinterpret_cast<char&>(l); 862f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor // Bad: from rvalue 872f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor (void)reinterpret_cast<int&>(&c); // expected-error {{reinterpret_cast from rvalue to reference type 'int &'}} 882f639b9f3c6b081f076d2ac6d75115ce44bfa249Douglas Gregor} 89db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl 90db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redlvoid memptrs() 91db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl{ 92db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl const int structure::*psi = 0; 93db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl (void)reinterpret_cast<const float structure::*>(psi); 94d4c5f84bbed2ecb5ddd0f0e8316c553b2084772aDouglas Gregor (void)reinterpret_cast<int structure::*>(psi); // expected-error {{reinterpret_cast from 'const int structure::*' to 'int structure::*' casts away qualifiers}} 95db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl 96db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl void (structure::*psf)() = 0; 97db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl (void)reinterpret_cast<int (structure::*)()>(psf); 98db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl 9958f9e13e87e57236fee4b914eea9be6f92a1c345Chris Lattner (void)reinterpret_cast<void (structure::*)()>(psi); // expected-error {{reinterpret_cast from 'const int structure::*' to 'void (structure::*)()' is not allowed}} 1007c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall (void)reinterpret_cast<int structure::*>(psf); // expected-error {{reinterpret_cast from 'void (structure::*)()' to 'int structure::*' is not allowed}} 101db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl 102db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl // Cannot cast from integers to member pointers, not even the null pointer 103db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl // literal. 1047c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall (void)reinterpret_cast<void (structure::*)()>(0); // expected-error {{reinterpret_cast from 'int' to 'void (structure::*)()' is not allowed}} 1057c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall (void)reinterpret_cast<int structure::*>(0); // expected-error {{reinterpret_cast from 'int' to 'int structure::*' is not allowed}} 106db64728e69a45b89870ede13944a934d3c2ed12aSebastian Redl} 10776d69bb7f984c390f90504a06dfc7485387ffdd7Sebastian Redl 10852647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlssonnamespace PR5545 { 10976d69bb7f984c390f90504a06dfc7485387ffdd7Sebastian Redl// PR5545 11076d69bb7f984c390f90504a06dfc7485387ffdd7Sebastian Redlclass A; 11176d69bb7f984c390f90504a06dfc7485387ffdd7Sebastian Redlclass B; 11276d69bb7f984c390f90504a06dfc7485387ffdd7Sebastian Redlvoid (A::*a)(); 11376d69bb7f984c390f90504a06dfc7485387ffdd7Sebastian Redlvoid (B::*b)() = reinterpret_cast<void (B::*)()>(a); 11452647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlsson} 11552647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlsson 11652647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlsson// <rdar://problem/8018292> 11752647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlssonvoid const_arrays() { 11852647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlsson typedef char STRING[10]; 11952647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlsson const STRING *s; 12052647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlsson const char *c; 12152647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlsson 122d4c5f84bbed2ecb5ddd0f0e8316c553b2084772aDouglas Gregor (void)reinterpret_cast<char *>(s); // expected-error {{reinterpret_cast from 'const STRING *' (aka 'char const (*)[10]') to 'char *' casts away qualifiers}} 12352647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlsson (void)reinterpret_cast<const STRING *>(c); 12452647c63c3cbdf0c87fe8db3ef6f475bfd49725dAnders Carlsson} 125b464a5b18916b467ed884d07f9e34295d39cec0aArgyrios Kyrtzidis 126b464a5b18916b467ed884d07f9e34295d39cec0aArgyrios Kyrtzidisnamespace PR9564 { 127b464a5b18916b467ed884d07f9e34295d39cec0aArgyrios Kyrtzidis struct a { int a : 10; }; a x; 128bb29d1ba8b0895e3923c724f49845636f35b4bdeArgyrios Kyrtzidis int *y = &reinterpret_cast<int&>(x.a); // expected-error {{not allowed}} 129bb29d1ba8b0895e3923c724f49845636f35b4bdeArgyrios Kyrtzidis 130bb29d1ba8b0895e3923c724f49845636f35b4bdeArgyrios Kyrtzidis __attribute((ext_vector_type(4))) typedef float v4; 131bb29d1ba8b0895e3923c724f49845636f35b4bdeArgyrios Kyrtzidis float& w(v4 &a) { return reinterpret_cast<float&>(a[1]); } // expected-error {{not allowed}} 132b464a5b18916b467ed884d07f9e34295d39cec0aArgyrios Kyrtzidis} 133f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 134f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidisvoid dereference_reinterpret_cast() { 135f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis struct A {}; 1361f8f2d52ff3712770a49f318a687b0c8b0ada9d0Chandler Carruth typedef A A2; 137f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis class B {}; 1381f8f2d52ff3712770a49f318a687b0c8b0ada9d0Chandler Carruth typedef B B2; 139f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis A a; 140f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis B b; 1411f8f2d52ff3712770a49f318a687b0c8b0ada9d0Chandler Carruth A2 a2; 1421f8f2d52ff3712770a49f318a687b0c8b0ada9d0Chandler Carruth B2 b2; 143f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis long l; 144f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis double d; 145f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis float f; 146f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis char c; 147f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis unsigned char uc; 148f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis void* v_ptr; 149f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<double&>(l); // expected-warning {{reinterpret_cast from 'long' to 'double &' has undefined behavior}} 150f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<double*>(&l); // expected-warning {{dereference of type 'double *' that was reinterpret_cast from type 'long *' has undefined behavior}} 151f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<double&>(f); // expected-warning {{reinterpret_cast from 'float' to 'double &' has undefined behavior}} 152f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<double*>(&f); // expected-warning {{dereference of type 'double *' that was reinterpret_cast from type 'float *' has undefined behavior}} 153f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<float&>(l); // expected-warning {{reinterpret_cast from 'long' to 'float &' has undefined behavior}} 154f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<float*>(&l); // expected-warning {{dereference of type 'float *' that was reinterpret_cast from type 'long *' has undefined behavior}} 155f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<float&>(d); // expected-warning {{reinterpret_cast from 'double' to 'float &' has undefined behavior}} 156f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<float*>(&d); // expected-warning {{dereference of type 'float *' that was reinterpret_cast from type 'double *' has undefined behavior}} 157f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 158f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // TODO: add warning for tag types 159f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<A&>(b); 160f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<A*>(&b); 161f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<B&>(a); 162f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<B*>(&a); 1631f8f2d52ff3712770a49f318a687b0c8b0ada9d0Chandler Carruth (void)reinterpret_cast<A2&>(b2); 1641f8f2d52ff3712770a49f318a687b0c8b0ada9d0Chandler Carruth (void)*reinterpret_cast<A2*>(&b2); 1651f8f2d52ff3712770a49f318a687b0c8b0ada9d0Chandler Carruth (void)reinterpret_cast<B2&>(a2); 1661f8f2d52ff3712770a49f318a687b0c8b0ada9d0Chandler Carruth (void)*reinterpret_cast<B2*>(&a2); 167f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 168f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // Casting to itself is allowed 169f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<A&>(a); 170f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<A*>(&a); 171f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<B&>(b); 172f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<B*>(&b); 173f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<long&>(l); 174f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<long*>(&l); 175f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<double&>(d); 176f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<double*>(&d); 177f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<char&>(c); 178f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<char*>(&c); 179f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 180f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // Casting to and from chars are allowable 181f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<A&>(c); 182f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<A*>(&c); 183f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<B&>(c); 184f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<B*>(&c); 185f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<long&>(c); 186f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<long*>(&c); 187f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<double&>(c); 188f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<double*>(&c); 189f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<char&>(l); 190f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<char*>(&l); 191f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<char&>(d); 192f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<char*>(&d); 193f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<char&>(f); 194f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<char*>(&f); 195f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 196f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // Casting from void pointer. 197f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<A*>(v_ptr); 198f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<B*>(v_ptr); 199f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<long*>(v_ptr); 200f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<double*>(v_ptr); 201f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<float*>(v_ptr); 202f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 203f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // Casting to void pointer 204f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<void*>(&a); 205f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<void*>(&b); 206f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<void*>(&l); 207f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<void*>(&d); 208f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<void*>(&f); 209f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis} 210f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 211f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidisvoid reinterpret_cast_whitelist () { 212f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // the dynamic type of the object 213f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis int a; 214f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis float b; 215f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<int&>(a); 216f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<int*>(&a); 217f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<float&>(b); 218f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<float*>(&b); 219f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 220f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // a cv-qualified version of the dynamic object 221f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const int&>(a); 222f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const int*>(&a); 223f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<volatile int&>(a); 224f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<volatile int*>(&a); 225f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const volatile int&>(a); 226f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const volatile int*>(&a); 227f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const float&>(b); 228f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const float*>(&b); 229f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<volatile float&>(b); 230f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<volatile float*>(&b); 231f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const volatile float&>(b); 232f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const volatile float*>(&b); 233f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 234f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // a type that is the signed or unsigned type corresponding to the dynamic 235f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // type of the object 236f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis signed d; 237f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis unsigned e; 238f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<signed&>(d); 239f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<signed*>(&d); 240f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<signed&>(e); 241f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<signed*>(&e); 242f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<unsigned&>(d); 243f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<unsigned*>(&d); 244f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<unsigned&>(e); 245f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<unsigned*>(&e); 246f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 247f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // a type that is the signed or unsigned type corresponding a cv-qualified 248f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // version of the dynamic type the object 249f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const signed&>(d); 250f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const signed*>(&d); 251f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const signed&>(e); 252f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const signed*>(&e); 253f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const unsigned&>(d); 254f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const unsigned*>(&d); 255f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const unsigned&>(e); 256f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const unsigned*>(&e); 257f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<volatile signed&>(d); 258f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<volatile signed*>(&d); 259f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<volatile signed&>(e); 260f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<volatile signed*>(&e); 261f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<volatile unsigned&>(d); 262f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<volatile unsigned*>(&d); 263f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<volatile unsigned&>(e); 264f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<volatile unsigned*>(&e); 265f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const volatile signed&>(d); 266f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const volatile signed*>(&d); 267f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const volatile signed&>(e); 268f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const volatile signed*>(&e); 269f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const volatile unsigned&>(d); 270f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const volatile unsigned*>(&d); 271f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<const volatile unsigned&>(e); 272f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<const volatile unsigned*>(&e); 273f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 274f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // an aggregate or union type that includes one of the aforementioned types 275f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // among its members (including, recursively, a member of a subaggregate or 276f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // contained union) 277f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // TODO: checking is not implemented for tag types 278f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 279f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // a type that is a (possible cv-qualified) base class type of the dynamic 280f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // type of the object 281f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // TODO: checking is not implemented for tag types 282f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis 283f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis // a char or unsigned char type 284f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<char&>(a); 285f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<char*>(&a); 286f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<unsigned char&>(a); 287f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<unsigned char*>(&a); 288f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<char&>(b); 289f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<char*>(&b); 290f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)reinterpret_cast<unsigned char&>(b); 291f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis (void)*reinterpret_cast<unsigned char*>(&b); 292f4bbbf0aaf741cc7d014e2cf059670a6756f8cbdArgyrios Kyrtzidis} 293