[PATCH] D151087: [Clang] Permit address space casts with 'reinterpret_cast' in C++

Bevin Hansson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 10:03:22 PDT 2023


ebevhan added a comment.

In D151087#4361263 <https://reviews.llvm.org/D151087#4361263>, @jhuber6 wrote:

> I'd rather have an operation whose semantics are a little dangerous than something that doesn't work at all. As it stands we need to use C-style casts for this and I don't think there's a good reason to forbid this at least from the C++ standard point of view. For OpenCL where we have the concept of address spaces it makes sense, but not for C++.

I don't think the standard argument really holds. It doesn't mention restrictions on address spaces because it doesn't have to, since they don't exist in C++. If they did, I'm pretty sure that reinterpret_cast would disallow arbitrary address space-modifying casts, since they wouldn't necessarily be bitcasts.

Like @arsenm said, any behaviors that you're using or observing regarding conversion of target address spaces in both C and C++ are purely coincidental. I don't think it's a great idea to add more such coincidental behaviors. The result will be that future code will become dependent on these arbitrary, less restrictive behaviors, and it will be much harder to properly define sensible semantics later on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151087



More information about the cfe-commits mailing list