Issue Details (XML | Word | Printable)

Key: STDCXX-556
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Farid Zaripov
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
C++ Standard Library

[MSVC 7.1] Bug in implementation of the empty base optimization

Created: 14/Sep/07 09:22 AM   Updated: 14/Sep/07 09:30 AM
Return to search
Component/s: External
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Environment:
MSVC 7.1 with Service Pack 1

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.6030 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

Issue Links:
Blocker
 

Severity: Incorrect Behavior


 Description  « Hide
The test below exit with exitcode 1 due to bug in MSVC 7.1 implementation of the empty base optimization.

-----------------------------
#include <cstring>
#include <cstdio>

#include <new>

class empty_base { };

class base
{
public:
base (int val) : __val (val) { }

volatile int __val;
};

class derived1 : public base, public empty_base
{
public:
derived1 (int val) : base (val), empty_base () { }
};

class derived2 : public base, public empty_base
{
public:
derived2 (int val) : base (val) { }
};

template <class T>
int foo (const int val, const char* name)
{
const char fill = '\xdc';

char buf [sizeof (T) + 1];
std::memset (buf, fill, sizeof (buf));

T* t = new (buf) T (val);

int ret = 0;

if (fill != buf [sizeof (T)]) { ++ret; std::printf ("buf [sizeof (%s)] expected %d, got %d\n", name, int (fill), int (buf [sizeof (T)])); }

if (val != t->__val) { ++ret; std::printf ("%s::__val expected %d, got %d\n", name, val, t->__val); }

t->~T ();

return ret;
}

int main(int, char**)
{
const int init = 0xcdcdcdcd;

return foo <derived1> (init, "derived1")
+ foo <derived2> (init, "derived2");
}
-----------------------------

The test output:
-----------------------------
buf [sizeof (derived1)] expected -36, got 0
-----------------------------



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
There are no subversion log entries for this issue yet.