public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14688] New: Mis-matched calling convention on virtual functions accepted without error
@ 2004-03-23 11:11 dannysmith at users dot sourceforge dot net
  2004-03-23 14:46 ` [Bug c++/14688] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 8+ messages in thread
From: dannysmith at users dot sourceforge dot net @ 2004-03-23 11:11 UTC (permalink / raw)
  To: gcc-bugs

Hello,
The following i386 bug was reported to mingw list by Justin Forest.

No error nor even a warning message is emitted when a virtual function in a
derived class uses a different calling convention than the function
in the base class. In the testcase that follows, this leads to the passing
of undefined parameters to the inherited method.

// virtual_mismatch.cc
 
#include <stdio.h>

class one {
public:
	virtual void test(void* value);
};

class two : public one {
public:
	void  __attribute__((regparm(2)))  test(void* value);
};


void one::test(void* value)
{
  printf("one::test(%p, %p)\n", this, value);
}

void two::test(void* value)
{
  printf("two::test(%p, %p)\n", this, value);
}


int main(int argc, const char **argv)
{
	two t;
	one *o = &t;
	t.test(o);  // a direct call,
		    // parameters passed through registers, ok
	o->test(o); // called through one::vtable,
 		    // parameters put to stack, read from registers
	return 0;
}


This compiles without warning;

> g++ -Wall -ovirtual_mismatch virtual_mismatch,cc

and produces:
 
> virtual_mismatch
> two::test(0022FF68, 0022FF68)
> two::test(00401282, 004041CC)

The problem was reported against 3.3.3 but occurs also on trunk and 3.4.

Danny

-- 
           Summary: Mis-matched calling convention on virtual functions
                    accepted without error
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dannysmith at users dot sourceforge dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-pc-mingw32
  GCC host triplet: i386-pc-mingw32
GCC target triplet: i386-pc-mingw32


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14688


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

end of thread, other threads:[~2007-09-25  0:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-14688-4066@http.gcc.gnu.org/bugzilla/>
2006-11-20 12:22 ` [Bug c++/14688] Mis-matched calling convention on virtual functions accepted without error massimiliano dot ghilardi at gmail dot com
2006-11-20 14:04 ` massimiliano dot ghilardi at gmail dot com
2007-05-14  9:58 ` justin dot forest at gmail dot com
2007-09-19  0:59 ` dannysmith at users dot sourceforge dot net
2007-09-19  2:24 ` patchapp at dberlin dot org
2007-09-25  0:30 ` dannysmith at gcc dot gnu dot org
2007-09-25  0:31 ` dannysmith at users dot sourceforge dot net
2004-03-23 11:11 [Bug c++/14688] New: " dannysmith at users dot sourceforge dot net
2004-03-23 14:46 ` [Bug c++/14688] " pinskia at gcc dot gnu dot org

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).