[PATCH] [libc++abi] Disallow conversions from function pointers to void*.

Jonathan Roelofs jonathan at codesourcery.com
Fri Apr 3 16:14:08 PDT 2015


================
Comment at: src/private_typeinfo.cpp:390
@@ -389,4 +389,3 @@
     // bullet 3A
-    if (is_equal(__pointee, &typeid(void), false))
-        return true;
-
+    if (is_equal(__pointee, &typeid(void), false)) {
+        // pointers to functions cannot be converted to void*.
----------------
jroelofs wrote:
> Why would a function pointer have the same typeid as void?
> 
> Is it clang that's getting this wrong? Do your new tests pass with GCC as the compiler, but this change reverted?
Actually, I think clang gets this right, but I'm still confused by your patch because:

```
#include <cstdio>
void foo() {}
int main() {
  printf("foo   %p %s\n", (void*)&typeid(foo),   typeid(foo).name());
  printf("&foo  %p %s\n", (void*)&typeid(&foo),  typeid(&foo).name());
  printf("void  %p %s\n", (void*)&typeid(void),  typeid(void).name());
  printf("void* %p %s\n", (void*)&typeid(void*), typeid(void*).name());
}
```

gives:

```
foo   0x804d4e8 FvvE
&foo  0x804d4f0 PFvvE
void  0x804e440 v
void* 0x804e430 Pv
```

on codepad (http://codepad.org/beuXVTtd), with similar results for Apple clang.

http://reviews.llvm.org/D8811

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list