This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/561: Compiler Error Casting Overloaded Function Pointers



>Number:         561
>Category:       c++
>Synopsis:       Compiler Error Casting Overloaded Function Pointers
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 21 11:06:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Don Mies
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
SunOS 5.7 Generic_106541-12 sun4u sparc SUNW,Ultra-5_10

No GCC specific environment variables set
>Description:
Attempting to compile the supplied program results in an
error message from GCC:

gcc -c gccBug.C
gccBug.C: In function `int main()':
gccBug.C:13: no matches converting function `foo' to type `void (A::*)()'
gccBug.C:6: candidates are: void B::foo()
gccBug.C:7:                 void B::foo(int)

Other C++ compilers accept this construct with no errors
or warnings.  Compilers tried:

   HPUX v10.0 - Unknown compiler version (Vendor supplied)
   Sun Forte v5 & v6
   MS Dev Studio v5 & v6

I posted this to the following web sites for feedback:

   gcc-bugs@gcc.gnu.org
   bug-gcc@gnu.org
   gcc@gcc.gnu.org

I received no helpful information except for the following:

> I did some research into this as our test suite was affected by the same
> problem and it appears that you're essentially correct in expecting
> the code to compile (edg, SunPro, and VisualAge all accept it). 5.2.9,
> p9 allows the cast but specifies undefined behavior since the base
> doesn't contain the member.
>How-To-Repeat:

class A { }; 

struct B : public A
{ 
    void foo (); 
    void foo (int);
}; 


int main ()
{
    void (A::*f)() = (void (A::*)()) &B::foo;
}
>Fix:
The problem can be worked around by changing the last line
of the example above to:

   void (A::*f)() = (void (A::*)()) (void (B::*)()) &B::foo;
>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]