]> granicus.if.org Git - clang/commitdiff
Allow implicit conversion from function pointer to void* in Microsoft mode.
authorFrancois Pichet <pichet2000@gmail.com>
Sun, 8 May 2011 22:52:41 +0000 (22:52 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Sun, 8 May 2011 22:52:41 +0000 (22:52 +0000)
Necessary to parse MFC code.

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

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

index 602ecd66027db773839617f2d1e9702b9459623b..e8dd56f66fb9bca623f505deaeedb23318ad2800 100644 (file)
@@ -1628,6 +1628,15 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
     return true;
   }
 
+  // MSVC allows implicit function to void* type conversion.
+  if (getLangOptions().Microsoft && FromPointeeType->isFunctionType() &&
+      ToPointeeType->isVoidType()) {
+    ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr,
+                                                       ToPointeeType,
+                                                       ToType, Context);
+    return true;
+  }
+
   // When we're overloading in C, we allow a special kind of pointer
   // conversion for compatible-but-not-identical pointee types.
   if (!getLangOptions().CPlusPlus &&
index 2d620b6da62083439b5f3953e5f2adb93b7a4593..40492608c04d58f11634c478a407edb93222f747 100644 (file)
@@ -179,4 +179,14 @@ void static_func(); // expected-note {{previous declaration is here}}
 static void static_func() // expected-warning {{static declaration of 'static_func' follows non-static declaration}}
 {
 
-}
\ No newline at end of file
+}
+
+long function_prototype(int a);
+long (*function_ptr)(int a);
+
+void function_to_voidptr_conv() {
+   void *a1 = function_prototype;
+   void *a2 = &function_prototype;
+   void *a1 = function_ptr;
+   void *a2 = &function_ptr;
+}