[PATCH] D62825: [C++2a] Add __builtin_bit_cast, used to implement std::bit_cast

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 21 14:28:52 PDT 2019


Quuxplusone added inline comments.


================
Comment at: clang/include/clang/Basic/DiagnosticASTKinds.td:223
+def note_constexpr_bit_cast_invalid_type : Note<
+  "cannot constexpr evaluate a bit_cast with a "
+  "%select{union|pointer|member pointer|volatile|struct with a reference member}0"
----------------
rsmith wrote:
> "constexpr evaluate" doesn't really mean anything. Also, the "struct with a reference member type X" case seems a bit strangely phrased (and it need not be a struct anyway...).
> 
> Maybe "cannot bit_cast {from|to}0 a {|type with a}1 {union|pointer|member pointer|volatile|reference}2 {type|member}1 in a constant expression"?
Peanut gallery says: Surely wherever this message comes from should use the same wording as other similar messages: `"(this construction) is not allowed in a constant expression"`. That is, the diagnostics for
```
constexpr int *foo(void *p) { return reinterpret_cast<int*>(p); }
constexpr int *bar(void *p) { return std::bit_cast<int*>(p); }
```
should be word-for-word identical except for the kind of cast they're complaining about.

(And if I had my pedantic druthers, every such message would say "...does not produce a constant expression" instead of "...is not allowed in a constant expression." But that's way out of scope for this patch.)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62825/new/

https://reviews.llvm.org/D62825





More information about the cfe-commits mailing list