[PATCH] D87565: [Sema] Improve const_cast conformance to N4261
Richard Smith - zygoloid via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 18:22:01 PDT 2020
rsmith added inline comments.
================
Comment at: clang/lib/Sema/SemaCast.cpp:1817-1819
+ NeedToMaterializeTemporary =
+ SrcType->isRecordType() || SrcType->isArrayType() ||
+ SrcType->isFunctionPointerType() || SrcType->isMemberPointerType();
----------------
It looks like GCC allowing a cast from `T*` to `T*&&` is just a bug in their implementation. Consider:
```
using T = int*;
T &&r1 = const_cast<T&&>(T{}); // GCC accepts
T &&r2 = const_cast<T&&>(T()); // GCC rejects
```
... and the same behavior seems to show up for all scalar types: they permit `const_cast` from `T{}` but not from `T()` when `T` is `int`, `int*`, .... This doesn't seem like good behavior to follow. I think we should either implement the current direction of 1965 (that is, only allow classes and arrays here) or leave the current behavior (following the standard as-is) alone.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87565/new/
https://reviews.llvm.org/D87565
More information about the cfe-commits
mailing list