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 via email to