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
Confirmed.
*** Bug 29909 has been marked as a duplicate of this bug. ***
Duplicated Bug 29909 also points out the not-so-obvious case where the overridden virtual method is actually the automatically-compiler-generated derived class destructor: // compile with g++ -Wall -O class one { public: virtual __attribute((regparm(3))) ~one(); }; class two : public one { }; int main() { one * o = new two(); delete o; return 0; }
$ g++ --version i686-apple-darwin8-g++- 4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5250) Copyright (C) 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -o test test.cc && ./test two::test(0xbffff7d8, 0xbffff7d8) two::test(0xbffff7d8, 0x1b94) Still looks like a valid issue.
Patch at: http://gcc.gnu.org/ml/gcc-patches/2007-09/msg01498.html Danny
Subject: Bug number PR 14688 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-09/msg01498.html
Subject: Bug 14688 Author: dannysmith Date: Tue Sep 25 00:29:42 2007 New Revision: 128740 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128740 Log: PR c++/14688 * config/i386/i386.c (ix86_comp_type_attributes): Check METHOD_TYPE too. cp * search.c (check_final_overrider): Fail if targetm.comp_type_attributes returns 0. testsuite * g++.dg/inherit/override_attribs.C: New file. Added: trunk/gcc/testsuite/g++.dg/inherit/override-attribs.C Modified: trunk/gcc/ChangeLog trunk/gcc/config/i386/i386.c trunk/gcc/cp/ChangeLog trunk/gcc/cp/search.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk