]> granicus.if.org Git - clang/commitdiff
In Microsoft mode, allow conversion from pointer to integral type no matter what...
authorFrancois Pichet <pichet2000@gmail.com>
Wed, 11 May 2011 22:13:54 +0000 (22:13 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Wed, 11 May 2011 22:13:54 +0000 (22:13 +0000)
Example:
void f(char *ptr) {
  char var = (char)ptr;
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131201 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCXXCast.cpp
test/SemaCXX/MicrosoftExtensions.cpp

index 2ea3b46829fd9d82e3c742ff104b8b81d6f3c170..31a5f92dacc5db3633dee1098c3bd180cb5f38d3 100644 (file)
@@ -1514,9 +1514,11 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr,
   if (DestType->isIntegralType(Self.Context)) {
     assert(srcIsPtr && "One type must be a pointer");
     // C++ 5.2.10p4: A pointer can be explicitly converted to any integral
-    //   type large enough to hold it.
-    if (Self.Context.getTypeSize(SrcType) >
-        Self.Context.getTypeSize(DestType)) {
+    //   type large enough to hold it; except in Microsoft mode, where the
+    //   integral type size doesn't matter.
+    if ((Self.Context.getTypeSize(SrcType) >
+         Self.Context.getTypeSize(DestType)) &&
+         !Self.getLangOptions().Microsoft) {
       msg = diag::err_bad_reinterpret_cast_small_int;
       return TC_Failed;
     }
index d1da0f7db0500bac34490a3a78bc99e4ddf7894f..88e39226708c98cb7944bac6cc5fde5b4d1a1ec0 100644 (file)
@@ -189,3 +189,11 @@ void function_to_voidptr_conv() {
    void *a2 = &function_prototype;
    void *a3 = function_ptr;
 }
+
+
+void pointer_to_integral_type_conv(char* ptr) {
+   char ch = (char)ptr;
+   short sh = (short)ptr;
+   ch = (char)ptr;
+   sh = (short)ptr;
+}