Bug 10818 - C-style cast to void* of a pointer-to-member-function does not issue a warning/error
Summary: C-style cast to void* of a pointer-to-member-function does not issue a warnin...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: 4.0.0
Assignee: Gabriel Dos Reis
URL:
Keywords: accepts-invalid, diagnostic
: 26030 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-05-16 15:06 UTC by razeh
Modified: 2006-01-30 13:52 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-10-11 14:31:35


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description razeh 2003-05-16 15:06:01 UTC
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.
Comment 1 Giovanni Bajo 2003-05-16 17:00:20 UTC
Responsible-Changed-From-To: unassigned->gdr
Responsible-Changed-Why: Diagnostic mantainer.
Comment 2 Giovanni Bajo 2003-05-16 17:00:20 UTC
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.
Comment 3 Gabriel Dos Reis 2003-08-29 08:04:28 UTC
Subject: Re:  C-style cast to void* of a pointer-to-member-function does not issue a warning/error


oops, this is operator error.
Comment 4 Mark Mitchell 2003-08-29 19:39:17 UTC
I've unassigned myself; until/unless this turns out to be a regression caused by
one of my patches.
Comment 5 Eric Botcazou 2003-09-08 07:32:49 UTC
Generic C++ front-end problem.
Comment 6 Gabriel Dos Reis 2003-12-24 23:03:59 UTC
mine.
Comment 7 Andrew Pinski 2005-01-11 02:19:18 UTC
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
        ....
Comment 8 Andrew Pinski 2006-01-30 13:52:01 UTC
*** Bug 26030 has been marked as a duplicate of this bug. ***