public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "daniel.kruegler at googlemail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/49171] [C++0x][constexpr] Constant expressions support reinterpret_cast
Date: Wed, 03 Oct 2012 18:46:00 -0000	[thread overview]
Message-ID: <bug-49171-4-KLoJM1ZOwn@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-49171-4@http.gcc.gnu.org/bugzilla/>


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

--- Comment #6 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-10-03 18:46:09 UTC ---
(In reply to comment #5)
> Ok, thanks. Sorry about the naive question: is it already clear what it means
> for reinterpret_cast uses to be "well-defined" in this sense?

This is surely no naive question. I should have been more specific: I think
only those reinterpret_cast operations that have a *specified* result, should
be allowed (similar to relational or equality operations). For example "An
expression of integral, enumeration, pointer, or pointer-to-member type can be
explicitly converted to its own type; such a cast yields the value of its
operand." seems well specified and uncontroversial to me. Another example (and
this is relevant for std::addressof) is the combination of p7

"An object pointer can be explicitly converted to an object pointer of a
different type. [..] Converting a prvalue of type “pointer to T1” to the type
“pointer to T2” (where T1 and T2 are object types and where the alignment
requirements of T2 are no stricter than those of T1) and back to its original
type yields the original pointer value."

and p11

"An lvalue expression of type T1 can be cast to the type “reference to T2” if
an expression of type “pointer to T1” can be explicitly converted to the type
“pointer to T2” using a reinterpret_cast. That is, a reference cast
reinterpret_cast<T&>(x) has the same effect as the conversion
*reinterpret_cast<T*>(&x) with the built-in & and * operators (and similarly
for reinterpret_cast<T&&>(x))."

In other words, the whole expression

reinterpret_cast<T*>(&const_cast<char&>(
  reinterpret_cast<const volatile char&>(t)))

that is typically used for the real address deduction seems to have
well-specified behaviour and should thus be "constexpr-friendly".


  parent reply	other threads:[~2012-10-03 18:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-26 12:10 [Bug c++/49171] New: " daniel.kruegler at googlemail dot com
2011-05-26 12:13 ` [Bug c++/49171] " daniel.kruegler at googlemail dot com
2011-08-30  9:52 ` daniel.kruegler at googlemail dot com
2012-10-03 14:28 ` paolo.carlini at oracle dot com
2012-10-03 16:22 ` daniel.kruegler at googlemail dot com
2012-10-03 16:46 ` paolo.carlini at oracle dot com
2012-10-03 18:46 ` daniel.kruegler at googlemail dot com [this message]
2012-10-05 14:10 ` paolo.carlini at oracle dot com
2012-10-05 14:17 ` daniel.kruegler at googlemail dot com
2012-10-23 23:00 ` paolo.carlini at oracle dot com
2012-10-23 23:02 ` paolo.carlini at oracle dot com
2014-11-18 13:44 ` jason at gcc dot gnu.org
2015-04-27 17:51 ` ktietz at gcc dot gnu.org
2015-08-23 16:41 ` myriachan at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-49171-4-KLoJM1ZOwn@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).