This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/49171] [C++0x][constexpr] Constant expressions support reinterpret_cast


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]