473,669 Members | 2,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::*METH OD_T)(void)>
class MethodCaller
{
public:
explicit MethodCaller(CL ASS_T* pClass) :
m_pClass(pClass )
{
}

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

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

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

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

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

int main(int, char*)
{
Test test;
Test.m_fooInvok er.invoke();
Test.m_barInvok er.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 1889
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*********@NOS PAM.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
2115
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 world. If we can not multiply two numbers and get a right answer, what good is it ? // test_int.cpp : Defines the entry point for the console application. // the program will give wrong answer for ftemp=0.01,0.02,0.03,0.04 #include "stdafx.h"...
1
2125
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 library directly ? Will there be a binary compatibility issue? I believe the CRT libraries are now MSVCR71DLL & MSVCP71.DLL. Thanks in advance.
1
1260
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. Thanks, Lynn McGuire
5
1446
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 wait 10-50% longer...
1
1197
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 the style cl /EHsc form1.cpp someotherfile.cpp ... etc.
6
5795
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 <process.h> #include <windows.h> #pragma comment(lib,"libcmt.lib") __int64 Counter=0; BOOL volatile stop_thread = FALSE;
2
1094
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 VC++.NET 2003 (a friend's). Is it a framework problem? (I've got the 1.1)
4
1041
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
1796
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 each object is new there should be no data to show. Here is some code that would run clean in VC++ 5.0 and in VC++ 2003 there is garbage. //Reproduce Garbage
9
2045
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 I'm posting on both newsgroups. Here we go: I noticed that if I nest a structure inside another one, the wrong constructor will be called.. the one from a different class!! Here is some test code:
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8894
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8803
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.