It's a simplification. The old code didn't go through the voting system
probably because of another bug. The problem is even worse than I thought
before. I am just unable to use mixed managed/unmanaged code, especially
with another bug with wcschr(). Who knows how many other bugs are there!
I wonder whether it's possible to get a hotfix from Microsoft? They don't
seem to want to fix VC7.1. I am pretty sure 8.0 will contain a lot of new
bugs, and it's at least a half of a year away.
// Compile with "cl /clr bug.cpp"
#include <iostream>
using namespace std;
struct A
{
A() { cout << "A() " << this << endl; }
A( const A& ) { cout << "A(A) " << this << endl; }
~A() { cout << "~A() " << this << endl; }
};
#pragma unmanaged // Comment out to fix the problem
void foo( A o ) { cout << "foo" << endl; }
#pragma managed
void main()
{
cout << "Before foo" << endl;
foo( A() ); cout << "After foo" << endl;
}
Results:
Before foo
A() 0012F584
~A() 0012F584
foo
~A() 0012F500
After foo