http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49171

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> 
2011-08-30 09:39:43 UTC ---
I believe I found a conforming usage of reinterpret_cast in constant
expressions useable in C++03:

//----------------
struct X {
 X* operator&();
};

X x[2];

const bool p = (reinterpret_cast<X*>(&reinterpret_cast<char&>(x[1]))
- reinterpret_cast<X*>(&reinterpret_cast<char&>(x[0]))) == sizeof(X);

enum E { e = p }; // e should have a value equal to 1
//----------------

Basically this program demonstrates the technique, the C++11 library function
addressof is based on and thus excluding reinterpret_cast *unconditionally*
from constant expressions in the core language would render this useful program
invalid and would make it impossible to declare addressof as a constexpr
function.

Reply via email to