[PATCH] D7606: Fix adress cast for C++ in SEMA

Richard Smith richard at metafoo.co.uk
Tue Jul 21 14:11:12 PDT 2015


rsmith added inline comments.

================
Comment at: lib/Sema/Sema.cpp:366
@@ +365,3 @@
+  // In the event an address space cast is requested, the kind passed from the
+  // caller should no be CK_NoOp.
+  assert((Kind != CK_NoOp ||
----------------
Typo "no" -> "not"

================
Comment at: lib/Sema/SemaCast.cpp:2106-2113
@@ -2105,1 +2105,10 @@
 
+  // If we are casting pointers, we need to check whether this refers to an
+  // address cast.
+  if (DestType->isPointerType() && SrcExpr.get()->getType()->isPointerType() &&
+      DestType->getPointeeType().getAddressSpace() !=
+          SrcExpr.get()->getType().getAddressSpace()) {
+    Kind = CK_AddressSpaceConversion;
+    return;
+  }
+
----------------
Looks like this would allow casting between any pointer type and any other pointer type with a different address space, independent of the pointee type. That's not right; we should still diagnose casts between pointer-to-object and pointer-to-function types and the like. Also, `reinterpret_cast`s will still fail with this check. This check should go at the end of `TryReinterpretCast` rather than here.


http://reviews.llvm.org/D7606







More information about the cfe-commits mailing list