This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 113d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-03-20


2048. C-style casts that cast away constness vs static_cast

Section: 7.6.1.9  [expr.static.cast]     Status: open     Submitter: Richard Smith     Date: 2014-11-19

According to 7.6.1.9 [expr.static.cast] paragraph 1,

The static_cast operator shall not cast away constness (7.6.1.11 [expr.const.cast]).

However, this phrasing is problematic in the context of a C-style cast like the following:

   const void *p;
   int *q = (int*)p;

The intent of 7.6.3 [expr.cast] is that this should be interpreted as a static_cast followed by a const_cast. However, because int* to const void* is a valid standard conversion, and 7.6.1.9 [expr.static.cast] paragraph 7 allows static_cast to perform the inverse of a standard conversion sequence, the C-style cast is interpreted as just a static_cast without a const_cast and is thus ill-formed.