Skip to content

[conv.integral,over.best.ics.general,over.ics.user] Ignore cv-qualification differences #4860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions source/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@
where $\cv{}^j_i$ and $P^j_i$ are the components of
the qualification-decomposition of $\tcode{T}j$.
A prvalue of type \tcode{T1}
can be converted to type \tcode{T2}
can be converted to another type \tcode{T2}
Copy link
Contributor

@xmh0511 xmh0511 Jul 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have excluded the identity conversion from qualification conversion, [expr.const.cast] p7 should also have to be changed to adhere this modification

[expr.const.cast] p7 says

A conversion from a type T1 to a type T2 casts away constness if T1 and T2 are different, there is a qualification-decomposition ([conv.qual]) of T1 yielding n such that T2 has a qualification-decomposition of the form

  • [...]

and there is no qualification conversion that converts T1 to

  • [...] named T3

Consider this example:

int* ptr = 0;
static_cast<void*>(ptr); 

In this example, T1 is "pointer to int" while T2 is "pointer to void". When n=1, T3 is pointer to void, since T2 and T3 are the same types, hence there is no qualification conversion that converts T2 to T3([conv.qual] p3 excludes identify conversions). This is not the intent of the definition of the cast-away constness.

[expr.const.cast] p7 should be changed to

A conversion from a type T1 to a type T2 casts away constness if T1 and T2 are different, there is a qualification-decomposition ([conv.qual]) of T1 with the form

cv10 P10 cv11 P11 ... cv1n-1 P2n-1 cv1n U1

yielding n such that T2 has a qualification-decomposition of the form

  • cv20 P20 cv21 P21 ... cv2n-1 P2n-1 cv2n U2

and such that a type T3 has a qualification-decomposition of the form

  • cv20 P10 cv21 P11 ... cv2n-1 P1n-1 cv2n U1

there is no qualification conversion that converts T1 to T3 if they are different types

Option 2

Or we just say: The qualification-combined type of T1 and T3 is not T3.

if the qualification-combined type of \tcode{T1} and \tcode{T2} is \tcode{T2}.
\begin{note}
If a program could assign a pointer of type \tcode{T**} to a pointer of
Expand Down Expand Up @@ -899,8 +899,9 @@

\pnum
\indextext{conversion!integral}%
A prvalue of an integer type can be converted to a prvalue of another
integer type. A prvalue of an unscoped enumeration type can be converted to
A prvalue of an integer type \tcode{T} can be converted to
a prvalue of another integer type not similar\iref{conv.qual} to \tcode{T}.
A prvalue of an unscoped enumeration type can be converted to
a prvalue of an integer type.

\pnum
Expand All @@ -924,8 +925,10 @@

\pnum
\indextext{conversion!floating-point}%
A prvalue of floating-point type can be converted to a prvalue of
another floating-point type. If the source value can be exactly
A prvalue of a floating-point type \tcode{T} can be converted to
a prvalue of another floating-point type
not similar\iref{conv.qual} to \tcode{T}.
If the source value can be exactly
represented in the destination type, the result of the conversion is
that exact representation. If the source value is between two adjacent
destination values, the result of the conversion is an
Expand Down
7 changes: 4 additions & 3 deletions source/overloading.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1920,8 +1920,9 @@
to
\tcode{A}.
\end{example}
When the parameter has a class type and the argument expression has the
same type, the implicit conversion sequence is an identity conversion.
When the parameter has a class type and the argument expression has a
similar type\iref{conv.qual},
the implicit conversion sequence is an identity conversion.
When the parameter has a class type and the argument expression has a
derived class type, the implicit conversion sequence is a
derived-to-base
Expand Down Expand Up @@ -2085,7 +2086,7 @@

\pnum
A conversion of an expression of class type
to the same class type is given Exact Match rank, and
to a similar\iref{conv.qual} class type is given Exact Match rank, and
a conversion of an expression of class type
to a base class of that type is given Conversion rank,
in spite of the
Expand Down