public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "peifeng2005 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/97432] Casting away constness in the drafts [conv.qual] a cv-decomposition exists in the following examples but fails in gcc
Date: Thu, 15 Oct 2020 00:12:17 +0000	[thread overview]
Message-ID: <bug-97432-4-k0iKtQ77pU@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97432-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97432

--- Comment #1 from Ray Zhang <peifeng2005 at gmail dot com> ---
Providing more context with the first example (also applies for the rest):

1)  // pointer to array - works in clang (trunk),
    // works in gcc (trunk)
    reinterpret_cast<int* const T::* const (*) [2]>(x);

T1: const pointer to const pointer to const pm(T) to const pointer to const U1
T2:       pointer to const array of 2 const pm(T) to const pointer to       U2

In this case, there exists multiple cv-decompositions, as [7.3.6].1 example 1
states:

> [Example 1: The type denoted by the type-id const int ** has three cv-decompositions, taking U as “int”, as “pointer to const int”, and as “pointer to pointer to const int”.

The cv-decompositions we have here for T1 is:

- const pointer to const U1
- const pointer to const pointer to const U1
- const pointer to const pointer to const pm(T) to const U1
- const pointer to const pointer to const pm(T) to const pointer to const U1

If we fulfill one such cv-decompositions, we can consider that reinterpret_cast
will not cast away constness, though U1 and U2 may be nested pointer/array
types of interest.

The unique cv-decomposition that a compiler can decide to take of T1 is:

- const pointer to const U1, where U1 is "pointer to const pm(T) to const
pointer to const int"

The cv-decomposition on T2 can be done similarly:

- const pointer to const U2, where U2 is "array of 2 const pm(T) to const
pointer to int"

Thus, we can perform a reinterpret cast from U1 to U2 without casting away
constness.

  reply	other threads:[~2020-10-15  0:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-15  0:10 [Bug c++/97432] New: " peifeng2005 at gmail dot com
2020-10-15  0:12 ` peifeng2005 at gmail dot com [this message]
2020-10-15  8:06 ` [Bug c++/97432] " peifeng2005 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-97432-4-k0iKtQ77pU@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).