From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29898 invoked by alias); 30 Aug 2011 09:40:17 -0000 Received: (qmail 29887 invoked by uid 22791); 30 Aug 2011 09:40:15 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 30 Aug 2011 09:40:01 +0000 From: "daniel.kruegler at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/49171] [C++0x][constexpr] Constant expressions support reinterpret_cast Date: Tue, 30 Aug 2011 09:52:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: daniel.kruegler at googlemail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-08/txt/msg02377.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D49171 --- Comment #2 from Daniel Kr=C3=BCgler 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 =3D (reinterpret_cast(&reinterpret_cast(x[1])) - reinterpret_cast(&reinterpret_cast(x[0]))) =3D=3D sizeof(X); enum E { e =3D p }; // e should have a value equal to 1 //---------------- Basically this program demonstrates the technique, the C++11 library functi= on addressof is based on and thus excluding reinterpret_cast *unconditionally* from constant expressions in the core language would render this useful pro= gram invalid and would make it impossible to declare addressof as a constexpr function.