The specific issue that a came across is that there is some inconsistency in how compilers handle it.
For instance this code (https://godbolt.org/z/08Z-zi):
constexpr auto value = 1;
static_assert(*const_cast<int *>(&value), "value should be 1");
compiles fine with GCC, Clang and MSVC but fails with Intel C++ Compiler 19.0.1 with the following error:
error: expression must have a constant value
static_assert(*const_cast<int *>(&value), "value should be 1");
As far as I can tell the standard does not explicitly state that a const_cast
is not permitted in a constant expression. Writing through the resulting pointer would be undefined and therefore not permitted but reading should be OK.
Considering that all the major compilers compile this code (including ICC < 19.0.1), it could just be a regression in ICC 19.0.1.