This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/158: Re: weird stuff with pointers to members, casts
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/158: Re: weird stuff with pointers to members, casts
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Thu, 30 Mar 2000 16:45:22 +0200
- References: <38e50574.7229451@busybee>
- Resent-Cc: gcc-prs at gcc dot gnu dot org, dvv at egcs dot dvv dot ru
- Resent-Reply-To: gcc-gnats@gcc.gnu.org, "Martin v. Loewis" <martin@loewis.home.cs.tu-berlin.de>
>Number: 158
>Category: c++
>Synopsis: weird stuff with pointers to members, casts
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: analyzed
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Thu Mar 30 06:56:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: dvv@egcs.dvv.ru (Dima Volodin)
>Release: 2.95.2
>Organization:
Huh?
>Environment:
>Description:
Date: Thu, 30 Mar 2000 07:44:49 GMT
Original-Message-ID: <38e50574.7229451@busybee>
[MvL: The function f is called four times, even though there is only
a single call in the source code.]
# cat mp.cc
#include <iostream>
struct C;
typedef void (C::* VMCP) ();
struct C {
static int counter;
VMCP f () {
counter++;
cout << this << "->f ()" << endl;
return (VMCP)&C::f;
}
};
int C::counter (0);
int
main () {
C c;
VMCP (C::* p1) ();
p1 = (VMCP (C::*) ()) c.f ();
if (c.counter != 1) {
cerr << "C::f called " << c.counter << " times" << endl;
return 1;
}
}
# ./mp
0x80479cb->f ()
0x80479cb->f ()
0x80479cb->f ()
0x80479cb->f ()
C::f called 4 times
#
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: