[PATCH] D102689: [C++4OpenCL] Allow address space conversion in reinterpret_cast

Ole Strohm via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 1 02:43:01 PDT 2021


olestrohm added inline comments.


================
Comment at: clang/lib/Sema/SemaCast.cpp:2359
 
-  if (SrcType == DestType) {
+  if (SrcType == Self.Context.removeAddrSpaceQualType(DestType)) {
     // C++ 5.2.10p2 has a note that mentions that, subject to all other
----------------
rjmccall wrote:
> I think the upshot of the conversation Richard and I just had is that there's a bug here for all qualifiers; that is, `reinterpret_cast<const int>(5)` should be allowed.  Probably the right thing to do is to strip qualifiers from DestType in the CastOperation constructor when the type is not a class or an array.  Richard, do you agree?  This isn't strictly implied by the C++ wording since the semantic analysis of the cast is logically prior to the introduction of a qualifier pr-value expression.
Ah, I see, I did indeed misunderstand the conversation above. I see now that with what Richard mentioned with `If a prvalue initially has the type “cv T”, where T is a cv-unqualified non-class, non-array type, the type of the expression is adjusted to T prior to any further analysis.` it makes sense to strip qualifiers for those cases. I also checked out gcc to compare to another implementation, and it does work there, so this behaviour doesn't seem unreasonable.

I'll rework this to strip all qualifiers somewhere in the CastOperation constructor as you suggested then.


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

https://reviews.llvm.org/D102689



More information about the cfe-commits mailing list