Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e28cedb
CWG1953 Data races and common initial sequence
burblebee Nov 27, 2024
97837d7
CWG2283 Missing complete type requirements
burblebee Nov 27, 2024
b6c37b1
CWG2815 Overload resolution for references/pointers to noexcept funct…
burblebee Nov 27, 2024
fc62fb5
CWG2879 Undesired outcomes with const_cast
burblebee Nov 27, 2024
f304952
CWG2890 Defining members of local classes
burblebee Nov 27, 2024
0b1cf18
CWG2894 Functional casts create prvalues of reference type
burblebee Nov 27, 2024
4c2bc49
CWG2899 Bad value representations should cause undefined behavior
burblebee Nov 27, 2024
35569a9
CWG2901 Unclear semantics for near-match aliased access
burblebee Nov 27, 2024
c7193c9
CWG2905 Value-dependence of noexcept-expression
burblebee Nov 28, 2024
538a55b
CWG2906 Lvalue-to-rvalue conversion of class types for conditional op…
burblebee Nov 28, 2024
96cdeff
CWG2907 Constant lvalue-to-rvalue conversion on uninitialized std::nu…
burblebee Nov 28, 2024
de1b557
CWG2908 Counting physical source lines for __LINE__
burblebee Nov 28, 2024
3171600
CWG2909 Subtle difference between constant-initialized and constexpr
burblebee Nov 28, 2024
8b66da2
CWG2910 Effect of requirement-parameter-lists on odr-usability
burblebee Nov 28, 2024
1348564
CWG2911 Unclear meaning of expressions "appearing within" subexpressions
burblebee Nov 28, 2024
3bd5fcb
CWG2913 Grammar for deduction-guide has requires-clause in the wrong …
burblebee Nov 28, 2024
521364d
CWG2915 Explicit object parameters of type void
burblebee Nov 28, 2024
3f3c5c9
CWG2918 Consideration of constraints for address of overloaded function
burblebee Nov 28, 2024
a7eff9a
CWG2919 Conversion function candidates for initialization of const lv…
burblebee Nov 28, 2024
fb49b41
CWG2921 Exporting redeclarations of entities not attached to a named …
burblebee Nov 28, 2024
1811723
CWG2922 constexpr placement-new is too permissive
burblebee Nov 28, 2024
011e687
CWG2924 Undefined behavior during constant evaluation
burblebee Nov 28, 2024
5225f68
[dcl.attr.assume] Add missing \pnum's
tkoeppe Dec 16, 2024
6280657
CWG2927 Unclear status of translation unit with module keyword
burblebee Nov 28, 2024
018efd1
CWG2930 Unclear term "copy/move operation" in specification of copy e…
burblebee Nov 28, 2024
18f8ef2
CWG2931 Restrictions on operator functions that are explicit object m…
burblebee Nov 28, 2024
c0a7e92
CWG2933 Dangling references
burblebee Nov 28, 2024
716c99a
CWG2936 Local classes of templated functions should be part of the cu…
burblebee Nov 28, 2024
8384ae9
CWG2937 Grammar for preprocessing-file has no normative effect
burblebee Nov 28, 2024
afaa669
CWG2939 Do not allow reinterpret_cast from prvalue to rvalue reference
burblebee Nov 28, 2024
8f6236e
CWG2944 Unsequenced throw-expressions
burblebee Nov 28, 2024
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
Prev Previous commit
Next Next commit
CWG2879 Undesired outcomes with const_cast
Also fixes CWG1965.
  • Loading branch information
burblebee authored and tkoeppe committed Dec 15, 2024
commit fc62fb5e950fd34efb31983322863d9a661f0207
4 changes: 4 additions & 0 deletions source/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5810,6 +5810,10 @@
return x;
}
constexpr int z = f(); // error: not a constant expression

typedef int *A[3]; // array of 3 pointer to \tcode{int}
typedef const int *const CA[3]; // array of 3 const pointer to \tcode{const int}
ACPC &&r = AP{}; // binds directly
\end{codeblock}
\end{example}

Expand Down
49 changes: 24 additions & 25 deletions source/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@
\end{note}

\pnum
Whenever a prvalue appears as an operand of an operator that
Unless otherwise specified\iref{expr.const.cast},
whenever a prvalue appears as an operand of an operator that
expects a glvalue for that operand, the
temporary materialization conversion\iref{conv.rval} is
applied to convert the expression to an xvalue.
Expand Down Expand Up @@ -4497,7 +4498,10 @@
otherwise, the result is a prvalue and the
lvalue-to-rvalue\iref{conv.lval}, array-to-pointer\iref{conv.array},
and function-to-pointer\iref{conv.func} standard conversions are
performed on the expression \tcode{v}. Conversions that can be performed explicitly using
performed on the expression \tcode{v}.
The temporary materialization conversion\iref{conv.rval} is not
performed on \tcode{v}, other than as specified below.
Conversions that can be performed explicitly using
\keyword{const_cast} are listed below. No other conversion shall be
performed explicitly using \keyword{const_cast}.

Expand All @@ -4508,23 +4512,16 @@
\end{note}

\pnum
For two similar types \tcode{T1} and \tcode{T2}\iref{conv.qual},
a prvalue of type \tcode{T1} may be explicitly
For two similar object pointer or pointer to data member types
\tcode{T1} and \tcode{T2}\iref{conv.qual},
a prvalue of type \tcode{T1} can be explicitly
converted to the type \tcode{T2} using a \keyword{const_cast}
if, considering the qualification-decompositions of both types,
each $P^1_i$ is the same as $P^2_i$ for all $i$.
The result of a \keyword{const_cast} refers to the original entity.
\begin{example}
\begin{codeblock}
typedef int *A[3]; // array of 3 pointer to \tcode{int}
typedef const int *const CA[3]; // array of 3 const pointer to \tcode{const int}

CA &&r = A{}; // OK, reference binds to temporary array object
// after qualification conversion to type \tcode{CA}
A &&r1 = const_cast<A>(CA{}); // error: temporary array decayed to pointer
A &&r2 = const_cast<A&&>(CA{}); // OK
\end{codeblock}
\end{example}
If \tcode{v} is a null pointer or null member pointer,
the result is a null pointer or null member pointer, respectively.
Otherwise, the result points to or past the end of the same object, or
points to the same member, respectively, as \tcode{v}.

\pnum
For two object types \tcode{T1} and \tcode{T2}, if a pointer to \tcode{T1} can
Expand All @@ -4537,20 +4534,22 @@
\item a glvalue of type \tcode{T1} can be explicitly converted to an xvalue
of type \tcode{T2} using the cast \tcode{\keyword{const_cast}<T2\&\&>}; and

\item if \tcode{T1} is a class type, a prvalue of type \tcode{T1} can be
\item if \tcode{T1} is a class or array type,
a prvalue of type \tcode{T1} can be
explicitly converted to an xvalue of type \tcode{T2} using the cast
\tcode{\keyword{const_cast}<T2\&\&>}.
The temporary materialization conversion is performed on \tcode{v}.
\end{itemize}

The result of a reference \keyword{const_cast} refers
to the original object if the operand is a glvalue and
to the result of applying the temporary materialization conversion\iref{conv.rval} otherwise.
The result refers to the same object as the (possibly converted) operand.
\begin{example}
\begin{codeblock}
typedef int *A[3]; // array of 3 pointer to \tcode{int}
typedef const int *const CA[3]; // array of 3 const pointer to \tcode{const int}

\pnum
A null pointer value\iref{basic.compound} is converted to the null pointer
value of the destination type. The null member pointer
value\iref{conv.mem} is converted to the null member pointer value of
the destination type.
auto &&r2 = const_cast<A&&>(CA{}); // OK, temporary materialization conversion is performed
\end{codeblock}
\end{example}

\pnum
\begin{note}
Expand Down