extern "C" { void g( void *); }; struct X { static void a() { } }; extern "C" void f() { void *a = (void*)(X::a); void *b = reinterpret_cast<void*>(X::a); void *c = reinterpret_cast<void*>(&f); } The the (void*)line compiles, while the reinterpret_cast lines generate: fp4.C:15: error: ISO C++ forbids casting between pointer-to-function and pointer-to-object fp4.C:16: error: ISO C++ forbids casting between pointer-to-function and pointer-to-object I would expect all three lines to fail. Release: unknown Environment: /home/host/razeh/testing$ gcc -v Reading specs from /usr/local/packages/gcc-3.3/lib/gcc-lib/sparc-sun-solaris2.8/3.3/specs Configured with: ../configure --prefix=/usr/local/packages/gcc-3.3 : (reconfigured) ../configure --prefix=/usr/local/packages/gcc-3.3 --disable-multilib Thread model: posix gcc version 3.3 /home/host/razeh/testing$ uname -a SunOS terk 5.8 Generic_108528-13 sun4u sparc SUNW,Sun-Blade-100 How-To-Repeat: Compile the file.
Responsible-Changed-From-To: unassigned->gdr Responsible-Changed-Why: Diagnostic mantainer.
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed. The compiler should reject the C-style cast to void exactly like it does with reinterpret_cast<void*>. I tried also with -pedantic but there is simply no warning/ error for it.
Subject: Re: C-style cast to void* of a pointer-to-member-function does not issue a warning/error oops, this is operator error.
I've unassigned myself; until/unless this turns out to be a regression caused by one of my patches.
Generic C++ front-end problem.
mine.
We only warn about all three cases with "-pedantic" in 4.0.0 only. There is a DR report asking if this is valid C++ or not, I think there is another bug about that. So closing as fixed. This was changed with the following patches: 2004-10-28 Nathan Sidwell <nathan@codesourcery.com> * typeck.c (composite_pointer_type): Remove comment about DR 195. (build_reinterpret_cast_1): Revert DR195 patch. Only emit a warning when being pedantic. (build_reinterpet_cast, build_c_cast): Adjust. 2004-10-20 Nathan Sidwell <nathan@codesourcery.com> * typeck.c (composite_pointer_type): Add comment about DR 195 (build_reinterpret_cast_1): Add for_reinterpret_cast_p parameter. Allow function pointer conversions that DR195 suggests. (build_reinterpret_cast, build_c_cast): Update build_reinterpret_cast_1 calls. 2004-10-19 Mark Mitchell <mark@codesourcery.com> PR c++/14035 ....
*** Bug 26030 has been marked as a duplicate of this bug. ***