incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farid Zaripov (JIRA)" <j...@apache.org>
Subject [jira] Created: (STDCXX-556) Bug in MSVC 7.1 implementation of the empty base optimization
Date Fri, 14 Sep 2007 09:22:32 GMT
Bug in MSVC 7.1 implementation of the empty base optimization
-------------------------------------------------------------

                 Key: STDCXX-556
                 URL: https://issues.apache.org/jira/browse/STDCXX-556
             Project: C++ Standard Library
          Issue Type: Bug
          Components: External
         Environment: MSVC 7.1
            Reporter: Farid Zaripov


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
-----------------------------


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message