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++/158: Re: weird stuff with pointers to members, casts



>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:

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