473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

VC++2003 Bug: Pointer-to-member type template arguments instantiated with virtual methods always call through first vtable slot

It appears that VC++2003 has a code generator bug related to template
parameters that are a pointer-to-member type:
If the actual template argument is a virtual method, VC generates code that
always calls the method at the first vtable slot (index 0).
To reproduce this bug, consider the following code:

template<class CLASS_T, void (CLASS_T::*METHOD_T)(void)>
class MethodCaller
{
public:
explicit MethodCaller(CLASS_T* pClass) :
m_pClass(pClass)
{
}

void invoke(void)
{
(m_pClass->*METHOD_T)();
}
CLASS_T* m_pClass;
};

class Test
{
public:
Test(void) :
m_fooInvoker(this),
m_barInvoker(this)
{
}

virtual void foo(void)
{
std::cout << "Test::foo()" << std::endl;
}

virtual void bar(void)
{
std::cout << "Test::bar()" << std::endl;
}

MethodCaller<Test, &Test::foo> m_fooInvoker;
MethodCaller<Test, &Test::bar> m_barInvoker;
};

int main(int, char*)
{
Test test;
Test.m_fooInvoker.invoke();
Test.m_barInvoker.invoke();
return 0;
}

In VC++2003, this outputs

Test::foo()
Test::foo()

If the template is instantiated with non-virtual methods, VC++2003 generates
the correct code.

Thanks,
Felix I. Wyss
Interactive Intelligence, Inc.

Nov 17 '05 #1
6 1877
Felix I. Wyss wrote:
It appears that VC++2003 has a code generator bug related to template
parameters that are a pointer-to-member type:
If the actual template argument is a virtual method, VC generates
code that always calls the method at the first vtable slot (index 0).
To reproduce this bug, consider the following code:
[ code snipped - thanks for the repro case! ]
In VC++2003, this outputs

Test::foo()
Test::foo()
Actually, in VC7.1 the code doesn't compile at all. It's missing a #include
of <iostream> and 'Test' is used where 'test' was inteded in two places (in
main()).

If the template is instantiated with non-virtual methods, VC++2003
generates the correct code.


Indeed.

Compiling with -vmg to force the use of the most general pointer-to-member
representation results in a link error!

The VC8 Feb CTP version produces an ICE on this code - definitely a bug that
needs attention.

http://lab.msdn.microsoft.com/produc...c-7b7713653395

seems to describe this very bug. The resolution there indicates that a fix
has been checked in, but it's clearly not present in the Feb CTP. Beta 2
should be released any day now, perhaps it's fixed there.

I couldn't fund any workaround for VC7.1.

-cd
Nov 17 '05 #2
Thanks a lot for the quick response!
Actually, in VC7.1 the code doesn't compile at all. It's missing a
#include of <iostream> and 'Test' is used where 'test' was inteded in two
places (in main()). Sorry -- transcription bug (damn auto-uppercase-first-word-in-sentence Word
editor).
The VC8 Feb CTP version produces an ICE on this code - definitely a bug
that needs attention.

http://lab.msdn.microsoft.com/produc...c-7b7713653395

seems to describe this very bug. The resolution there indicates that a
fix has been checked in, but it's clearly not present in the Feb CTP.
Beta 2 should be released any day now, perhaps it's fixed there.


It does appear to be related and may well be caused by the same compiler
bug. However, the code shown uses only a single virtual method and fails to
compile in VC8, so we don't know whether the compiler generates the correct
code once that problem is fixed. Considering that VC7.1 generates incorrect
code by always calling through vtable slot 0, I recommend adding a test case
for this particular issue to make sure the correct code is produced.

Thanks,
Felix I. Wyss
Interactive Intelligence, Inc.
Nov 17 '05 #3
Felix I. Wyss wrote:
Thanks a lot for the quick response!
Actually, in VC7.1 the code doesn't compile at all. It's missing a
#include of <iostream> and 'Test' is used where 'test' was inteded
in two places (in main()).

Sorry -- transcription bug (damn
auto-uppercase-first-word-in-sentence Word editor).
The VC8 Feb CTP version produces an ICE on this code - definitely a
bug that needs attention.

http://lab.msdn.microsoft.com/produc...c-7b7713653395

seems to describe this very bug. The resolution there indicates
that a fix has been checked in, but it's clearly not present in the Feb
CTP.
Beta 2 should be released any day now, perhaps it's fixed there.


It does appear to be related and may well be caused by the same
compiler bug. However, the code shown uses only a single virtual method
and
fails to compile in VC8, so we don't know whether the compiler generates
the
correct code once that problem is fixed. Considering that VC7.1 generates
incorrect code by always calling through vtable slot 0, I recommend adding
a
test case for this particular issue to make sure the correct code is
produced.


Go ahead and open a case for it - you're right, it might not be the same
bug. If you post a link here, people can vote for it.

-cd
Nov 17 '05 #4
Carl Daniel [VC++ MVP] wrote:
Felix I. Wyss wrote:
I just posted this bug as
http://lab.msdn.microsoft.com/Produc...ckId=FDBK24395.


Thanks! I added a note of my own, marked it as validated and cast my
vote.


This is fixed in VS 2005 beta 2.

-cd
Nov 17 '05 #5
Does anyone know if a service pack will be released for VS.NET 2003 ?
Or do we have to run the risk of using a beta version of the compiler, and
hope there are no new bugs in it ?

This affects code I'm responsible for, so I'm moderately interested.

Thanks,

Adam.
--
===========================
Adam Benson
Omnibus Systems,
Leics. UK
Email : Ad*********@NOSPAM.omnibus.co.uk
Nov 17 '05 #6
Adam Benson wrote:
Does anyone know if a service pack will be released for VS.NET 2003 ?
Or do we have to run the risk of using a beta version of the compiler, and
hope there are no new bugs in it ?

This affects code I'm responsible for, so I'm moderately interested.

Thanks,

Adam.


Yes, one will be released. The timing has not yet been deciced but it
will likely ship after the release of Visual Studio 2005.

Ronald Laeremans
Visual C++ team
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: LTO | last post by:
What is going on with MS VC compiler team? The following trivial program will give wrong answer of 9 instead of 10. Perhaps MS is spending too much time on managed world and forget about the real...
1
by: Shankar | last post by:
Hi, Our product(library) built with MSVC++ 7.0/.NET 2002 is already in the market. This is dynamically linked with MSVCR70.DLL and MSVCP70.DLL. Can developers using VC++ 2003 (7.1 ?) use our...
1
by: Lynn McGuire | last post by:
How do I get a list of unused functions in my application using Visual C++ 2003 ? I know that I have several in 300,000 lines of C++ code. However, tracking them down is very difficult. ...
5
by: Michael | last post by:
i experience slower compile times with VC++ 2003 compared to VC+6.0. Anyone experiencing the same? Should that be expected? This ineed matters, when total compilation time is > 1h and you have to...
1
by: Ioannis Vranos | last post by:
Can VC++ Toolkit 2003 compile VC++ 2003 projects out of the box? I mean read the project files themselves and compile? Or some other way? I am talking about a more convenient way than building in...
6
by: | last post by:
The following code snippet can be build in VC 6.0, but failed in VC 2003. //////////////save the following code in t.cpp #define _MT #define _WIN32_WINNT 0x0500 #include <iostream> #include...
2
by: Al | last post by:
I'd installed VC++ Express 2005 beta 2 but I couldn't create new projects from templates or when I opened an existing solution, I couldn' build it: 'exe not found!' The same happened whith...
4
by: Serge Skorokhodov (216716244) | last post by:
Hi, I don't know whether this is a known buf. The following snippet: == start == #include "stdafx.h" #include <iostream> #include <tchar.h> int _tmain(int argc, _TCHAR* argv)
14
by: Jeffrey Baker | last post by:
Hello, I wrote a program way back when VC++ 5.0 was around and when using this program in VC++ 2003 I get garbage. I was able to let the program run through code that would view the data. Since...
9
by: fabio.bizzetti | last post by:
Hello all, I went across what seems possibly a bug of the compiler (VisualC 2005, just for the record) or a very strange and non-expected (by me at least) behaviour of the C++ ISO standard. Thus...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.