public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Casting Overloaded Function Pointer Problem...Repost..
@ 2000-09-18 14:39 Don Mies
  0 siblings, 0 replies; 2+ messages in thread
From: Don Mies @ 2000-09-18 14:39 UTC (permalink / raw)
  To: gcc-bugs, bug-gcc, gcc

This is a reposting of an earlier message because I received a request
from one of the list members to post the request without any of the
HTML formatting.

------

Gentlemen,

This is a reposting of an earlier request.  I received no responses
that helped in resolving my problem so I will try posting the query
again...

I have run into a problem trying to use the g++ compiler on a Sun
Solaris 7 system.

I've been trying to compile a version of the Microsoft MFC library
with the g++ compiler and have run into a problem that I don't know
how to resolve.

Here is a highly condensed test file that illustrates the problem.

--------------------------------------------
     1
     2  class CCmdTarget;
     3  class CWnd;
     4  class CRecordView;
     5
     6  typedef int (CCmdTarget::*PMSG)(int);
     7
     8  class CCmdTarget {};
     9
    10
    11  class CWnd : public CCmdTarget
    12  {
    13    public:
    14      int OnMove (int x, int y);
    15  };
    16
    17
    18  class CRecordView : public CWnd
    19  {
    20    public:
    21      int OnMove (int);
    22    protected:
    23      void OnMove (int cx, int cy);
    24    private:
    25      static const PMSG _messageEntries[];
    26  };
    27
    28
    29  ////////////////////////////////////////////////////////////
    30
    31  const PMSG CRecordView::_messageEntries[] =
    32  {
    33      (PMSG)&CRecordView::OnMove
    34  };

  ----------------------------------------

If I compile the above with the Sun CC compiler, I get no complaints
or warnings.  When I compile it with g++ (gcc version 2.95.2 19991024
(release)) I get the following error messages:

@
"xx" 107 lines, 3353 characters 

f % cat xx

Gentlemen, 

This is a reposting of an earlier request.  I received no responses 
that helped in resolving my problem so I will try posting the query 
again... 

I have run into a problem trying to use the g++ compiler on a Sun 
Solaris 7 system. 

I've been trying to compile a version of the Microsoft MFC library 
with the g++ compiler and have run into a problem that I don't know 
how to resolve. 

Here is a highly condensed test file that illustrates the problem. 

-------------------------------------------- 
     1 
     2  class CCmdTarget; 
     3  class CWnd; 
     4  class CRecordView; 
     5 
     6  typedef int (CCmdTarget::*PMSG)(int); 
     7 
     8  class CCmdTarget {}; 
     9 
    10 
    11  class CWnd : public CCmdTarget 
    12  { 
    13    public: 
    14      int OnMove (int x, int y); 
    15  }; 
    16 
    17 
    18  class CRecordView : public CWnd 
    19  { 
    20    public: 
    21      int OnMove (int); 
    22    protected: 
    23      void OnMove (int cx, int cy); 
    24    private: 
    25      static const PMSG _messageEntries[]; 
    26  }; 
    27 
    28 
    29  //////////////////////////////////////////////////////////// 
    30 
    31  const PMSG CRecordView::_messageEntries[] = 
    32  { 
    33      (PMSG)&CRecordView::OnMove 
    34  }; 

  ---------------------------------------- 

If I compile the above with the Sun CC compiler, I get no complaints 
or warnings.  When I compile it with g++ (gcc version 2.95.2 19991024 
(release)) I get the following error messages: 

    t.C:34: no matches converting function `OnMove' to type `int (CCmdTarget::*)(int)' 
    t.C:21: candidates are: int CRecordView::OnMove(int) 
    t.C:23:                 void CRecordView::OnMove(int, int) 

If I comment out the overloaded function declaration at line 23, it will compile 
with no errors. 

The compiler appears to be ignoring the cast operator at line 23 when it determines 
the function signature. 

I received one response to my initial posting with the following information: 

> Your code is essentially asking GCC to convert the pointer 
> to the member function into a p-to-m-f of the base class. 
> If I'm interpreting this correctly, according to the C++ 
> Standard, section 13.4, this is not allowed: 
> 
> [Note: there are no standard conversions (clause 4) of one 
> pointer-to-function type into another. In particular, even 
> if B is a public base of D, we have 
> 
>       D* f(); 
>       B* (*p1)() = &f; // error 
>       void g(D*); 
>       void (*p2)(B*) = &g; // error 
> 
> -end note] 
> 
> Therefore, I think GCC may be right in complaining about 
> this code. 

However, I don't believe the above interpretation is incorrect as 
my example program above is doing an explicit cast and not 
a standard cast as the above response contends.  In addition, 
if I comment out line 23 to remove the overloading function 
declaration, it will compile with no errors and the casting 
operation is still in effect and unchanged. 

Sections 5.1.10.6, 5.2.10.9, and 5.4.5 of the C++ Standard seem 
to indicate that the above construct should be legal but the g++ 
compiler appears to disagree. 

Is there a way to fix this without making major changes to the source files 
(I don't understand  the MFC library well enough to make changes to it)? 

Thank you, 
  

Don Mies

-- 
<i><font size=-2>This e-mail contains information intended only for the
use of the individual or entity named above.&nbsp; If the reader of this
e-mail is not the intended recipient or the employee or agent responsible
for delivering it to the intended recipient, any dissemination, publication
or copy of this e-mail is strictly prohibited.&nbsp; If you have received
this e-mail in error, please immediately notify the sender.
<br>Thank you.</font></i>
begin:vcard 
n:Mies;Don
tel;fax:(714) 375-2737
tel;work:(714) 843-6050
x-mozilla-html:FALSE
url: http://www.bluekite.com
org:BlueKite.com, Inc.;Unix Development
version:2.1
email;internet:dmies@bluekite.com
adr;quoted-printable:;;17011 Beach Blvd, Suite 1230=0D=0A;Huntington Beach;CA;92647;U.S.A.
x-mozilla-cpt:;-24136
fn:Don Mies
end:vcard

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Casting Overloaded Function Pointer Problem...Repost...
@ 2000-09-18 11:06 Don Mies
  0 siblings, 0 replies; 2+ messages in thread
From: Don Mies @ 2000-09-18 11:06 UTC (permalink / raw)
  To: gcc-bugs, bug-gcc, gcc

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4680 bytes --]

 
Gentlemen,
This is a reposting of an earlier request.  I received no responses
that helped in resolving my problem so I will try posting the query
again...
I have run into a problem trying to use the g++ compiler on a Sun
Solaris 7 system.
I've been trying to compile a version of the Microsoft MFC library
with the g++ compiler and have run into a problem that I don't know
how to resolve.
Here is a highly condensed test file that illustrates the problem.
--------------------------------------------
     1
     2  class
CCmdTarget;
     3  class
CWnd;
     4  class
CRecordView;
     5
     6  typedef
int (CCmdTarget::*PMSG)(int);
     7
     8  class
CCmdTarget {};
     9
    10
    11  class
CWnd : public CCmdTarget
    12  {
    13   
public:
    14     
int OnMove (int x, int y);
    15  };
    16
    17
    18  class
CRecordView : public CWnd
    19  {
    20   
public:
    21     
int OnMove (int);
    22   
protected:
    23     
void OnMove (int cx, int cy);
    24   
private:
    25     
static const PMSG _messageEntries[];
    26  };
    27
    28
    29  ////////////////////////////////////////////////////////////
    30
    31  const
PMSG CRecordView::_messageEntries[] =
    32  {
    33     
(PMSG)&CRecordView::OnMove
    34  };
  ----------------------------------------
If I compile the above with the Sun CC compiler, I get no complaints
or warnings.  When I compile it with g++ (gcc version 2.95.2 19991024
(release)) I get the following error messages:
    t.C:34: no matches converting function `OnMove' to
type `int (CCmdTarget::*)(int)'
    t.C:21: candidates are: int CRecordView::OnMove(int)
    t.C:23:                
void CRecordView::OnMove(int, int)
If I comment out the overloaded function declaration at line 23, it
will compile
with no errors.
The compiler appears to be ignoring the cast operator at line 33 when
it determines
the function signature.
I received one response to my initial posting with the following information:
> Your code is essentially asking GCC to convert the pointer
> to the member function into a p-to-m-f of the base class.
> If I'm interpreting this correctly, according to the C++
> Standard, section 13.4, this is not allowed:
>
> [Note: there are no standard conversions (clause 4) of one
> pointer-to-function type into another. In particular, even
> if B is a public base of D, we have
>
>       D* f();
>       B* (*p1)() = &f; // error
>       void g(D*);
>       void (*p2)(B*) = &g; // error
>
> -end note]
>
> Therefore, I think GCC may be right in complaining about
> this code.
However, I don't believe the above interpretation is incorrect as
my example program above is doing an explicit cast and not
a standard cast as the above response contends.  In addition,
if I comment out line 23 to remove the overloading function
declaration, it will compile with no errors and the casting
operation is still in effect and unchanged.
Sections 5.1.10.6, 5.2.10.9, and 5.4.5 of the C++ Standard seem
to indicate that the above construct should be legal but the g++
compiler appears to disagree.
Is there a way to fix this without making major changes to the source
files
(I don't understand  the MFC library well enough to make changes
to it)?
Thank you,
 
Don Mies
-- 
This e-mail contains information intended only for the
use of the individual or entity named above.  If the reader of this
e-mail is not the intended recipient or the employee or agent responsible
for delivering it to the intended recipient, any dissemination, publication
or copy of this e-mail is strictly prohibited.  If you have received
this e-mail in error, please immediately notify the sender.

Thank you.
 
begin:vcard 
n:Mies;Don
tel;fax:(714) 375-2737
tel;work:(714) 843-6050
x-mozilla-html:FALSE
url: http://www.bluekite.com
org:BlueKite.com, Inc.;Unix Development
version:2.1
email;internet:dmies@bluekite.com
adr;quoted-printable:;;17011 Beach Blvd, Suite 1230=0D=0A;Huntington Beach;CA;92647;U.S.A.
x-mozilla-cpt:;-24136
fn:Don Mies
end:vcard

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-09-18 14:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-18 14:39 Casting Overloaded Function Pointer Problem...Repost Don Mies
  -- strict thread matches above, loose matches on Subject: below --
2000-09-18 11:06 Don Mies

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).