You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Scott Zhong <Sc...@roguewave.com> on 2008/03/06 23:50:21 UTC

STDCXX-615

The following test case reproduces the bug:

*****************************************************

template <class T>
struct Base
{
   int i;
};

template <class T>
struct Base_0 : virtual Base<T>
{
public:
    T a; // non-empty body
    Base_0();
};

template <class T>
struct Derived : public Base_0<T>
{
public:
    T b; // non-empty body
    Derived();
};

template <class T>
class my_ptr
{
public:
    T* _ptr;
    my_ptr();

    template <class U>
    my_ptr(U *rhs) : _ptr (rhs) { }
   
    template <class U>
    my_ptr(const my_ptr<U> &rhs) : _ptr (rhs._ptr) { }
};

Derived<int>* const pDer = new Derived<int>;
my_ptr<volatile Derived<int> > ptr_0 (pDer);
my_ptr<volatile Base_0<int> > ptr_1 (ptr_0);

********************************************************

aCC -V t2.cpp
aCC: HP ANSI C++ B3910B A.03.73
Error 440: "t2.cpp", line 34 # Cannot initialize 'volatile Base_0<int>
*' with 'volatile Derived<int> *const'.
        my_ptr(const my_ptr<U> &rhs) : _ptr (rhs._ptr) { }
                                             ^^^^^^^^     
Error 445: "t2.cpp", line 1 # Cannot recover from earlier errors.
    template <class T>
    ^^^^^^^^^^^^^^^^^^

********************************************************

It seems to me that 

>Derived<int>* const pDer = new Derived<int>;
>my_ptr<volatile Derived<int> > ptr_0 (pDer);
>my_ptr<volatile Base_0<int> > ptr_1 (ptr_0);

Is essentially performing the following which doesn't cause the compiler
error to occur:

>Derived<int>* const pDer = new Derived<int>;
>volatile Derived<int> *ptr_0 = pDer;
>volatile Base_0<int> *ptr_1 = ptr_0;

Re: STDCXX-615

Posted by Martin Sebor <se...@roguewave.com>.
Scott Zhong wrote:
> The following test case reproduces the bug:

Thanks for the test case! I sent a reduced version of it to HP.

> 
[...]
> 
> It seems to me that 
> 
>> Derived<int>* const pDer = new Derived<int>;
>> my_ptr<volatile Derived<int> > ptr_0 (pDer);
>> my_ptr<volatile Base_0<int> > ptr_1 (ptr_0);
> 
> Is essentially performing the following which doesn't cause the compiler
> error to occur:
> 
>> Derived<int>* const pDer = new Derived<int>;
>> volatile Derived<int> *ptr_0 = pDer;
>> volatile Base_0<int> *ptr_1 = ptr_0;
> 

Changing the test this way would defeat its purpose: to exercise
shared_ptr's ability to perform conversions between related types
with different (but compatible) cv-qualifications.

Unless you can think of a workaround that doesn't compromise the
test's efficacy, now that we have a test case that clearly shows
it's a compiler bug we can either mark the compilation failure
of test as EXPECTED in xfail.txt or disable that part of the test.

Martin