Issue Details (XML | Word | Printable)

Key: STDCXX-494
Type: Bug Bug
Status: In Progress In Progress
Priority: Major Major
Assignee: Martin Sebor
Reporter: Martin Sebor
Votes: 0
Watchers: 0
Operations

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

access error using UD new to construct a container with a UD allocator

Created: 24/Jul/07 12:47 AM   Updated: 17/Jul/08 09:59 PM
Return to search
Component/s: 23. Containers
Affects Version/s: 4.1.2, 4.1.3, 4.1.4, 4.2.0, 4.2.1
Fix Version/s: 4.2.2

Time Tracking:
Original Estimate: 8h
Original Estimate - 8h
Remaining Estimate: 6h
Time Spent - 2h Remaining Estimate - 6h
Time Spent: 2h
Time Spent - 2h Remaining Estimate - 6h

Issue Links:
Reference
 

Severity: Compiler Error


 Description  « Hide
Moved from Rogue Wave Bugzilla: http://bugzilla.cvo.roguewave.com/show_bug.cgi?id=1456

-------- Original Message --------
Subject: Re: CXX-DEV: cannot access member through private base
Date: Fri, 31 Dec 2004 17:03:02 +0530
From: Aditya Bhushan <abhushan@adobe.com>
To: Aditya Bhushan <abhushan@adobe.com>, cxx-dev@cxx.cup.hp.com,
hpux-devtools@cxx.cup.hp.com
CC: Prashant Verma <pverma@adobe.com>, Atul Puri <apuri@adobe.com>
References: <029301c4eda6$fce9a0a0$c519280a@corp.adobe.com>

Furthur investigation points out to the code in /opt/aCC/include_std/list:

template <class _TypeT,
class _Allocator _RWSTD_COMPLEX_DEFAULT (allocator<_TypeT>) >
class list : private _Allocator{...

I suspect the problem is due to the private derivation from
_Allocator, though that should not be the case because
a) all our classes have been publically derived and
b) the overloaded method new is also public

What is a recommended solution to this problem, keeping in mind the
fact that our code provides its own implementation of allocator?

Regards,
Aditya Bhushan
Adobe Systems India Pvt. Ltd.
----- Original Message -----
From: Aditya Bhushan
To: cxx-dev@cxx.cup.hp.com ; hpux-devtools@cxx.cup.hp.com
Cc: Prashant Verma ; Atul Puri
Sent: Wednesday, December 29, 2004 6:34 PM
Subject: CXX-DEV: cannot access member through private base

On compiling the file(source below) the following error is encountered.

Error 183: "abcd.cpp", line 60 # "int main()" cannot access member
"static void *XYZ::BaseClass::operator new(unsigned long)" through
private base.
new STLList();
^^^^^^^^^^^^^

I used aCC -AA abcd.cpp

we are using aCC version 3.52

Is there a workaround for this problem?

the Source file abcd.cpp is

*************************************************************************************************************************************************************************************
typedef unsigned long size_t;

namespace XYZ
{
class BaseClass
{
public:
inline static void* operator new (size_t n) { return 0; }

};


template<class T> struct Derived1 : public BaseClass { typedef T value_type; };


template<class T> class Derived2 : public Derived1<T>
{
public:
typedef typename Derived1<T>::value_type value_type;
typedef const value_type* const_pointer;
typedef const value_type& const_reference;
typedef int difference_type;
typedef value_type* pointer;
typedef value_type& reference;
typedef size_t size_type;

pointer address(reference _Val) const { return (&_Val); }
const_pointer address(const_reference _Val) const { return (&_Val); }

pointer allocate(size_type n) { return 0; }
pointer allocate(size_type n, void*) { return 0; }}

Derived2() {} // NOP
Derived2(const Derived2<T>&) {} // NOP
// construct from a related allocator (NOP)
template<class _Other> Derived2(const Derived2<_Other>&) {}

void construct(pointer ptr, const T& val) {
::new (ptr) T(val); }

void destroy(pointer ptr) { ptr->~T(); }

template<class _Other> struct rebind { typedef Derived2<_Other> other; };
};


}

using namespace XYZ;

#include <list>

int main(){ typedef std::list<void*, XYZ::Derived2<void*> > STLList; new STLList(); return 0; }


************************************************************************************************************************************************************************************
_________________________________________________________________
To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
with the message UNSUBSCRIBE cxx-dev
_________________________________________________________________
_________________________________________________________________
To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
with the message UNSUBSCRIBE cxx-dev
_________________________________________________________________



------- Additional Comments From sebor@roguewave.com 2005-01-03 14:38:34 ----

-------- Original Message --------
Subject: Re: CXX-DEV: cannot access member through private base
Date: Mon, 03 Jan 2005 15:34:14 -0700
From: Martin Sebor <sebor@roguewave.com>
To: cxx-dev@cxx.cup.hp.com
References: <029301c4eda6$fce9a0a0$c519280a@corp.adobe.com>
<05ad01c4ef2c$80f38920$c519280a@corp.adobe.com>

Aditya Bhushan wrote:
> Furthur investigation points out to the code in
/opt/aCC/include_std/list:
>
> template <class _TypeT,
> class _Allocator _RWSTD_COMPLEX_DEFAULT (allocator<_TypeT>) >
> class list : private _Allocator{...
>
> I suspect the problem is due to the private derivation from
_Allocator, though that should not be the case because
> a) all our classes have been publically derived and
> b) the overloaded method new is also public
>
> What is a recommended solution to this problem, keeping in mind the
fact that our code provides its own implementation of allocator?

I couldn't compile your test case because your allocator is missing
the deallocate() member function. But once I added it I was able to
reproduce the error. The private derivation does indeed seem to be
the cause of the error. We use it throughout the library to take
advantage of the empty base optimization implemented by some compilers.
Unless you are willing to give up the operator I'm afraid I can't think
of a simple workaround for you.

Martin

PS Here's a smaller test case that reproduces the error with vector:

#include <cstddef>
#include <vector>

template <class T>
struct MyAllocator: std::allocator<T>
{
template <class U>
struct rebind { typedef MyAllocator<U> other; };

MyAllocator () { }
MyAllocator (const MyAllocator &rhs): std::allocator<T>(rhs) { }

template <class U>
MyAllocator (const MyAllocator<U> &rhs): std::allocator<T>(rhs) { }

void* operator new (std::size_t) { return 0; }
void operator delete (void*) { }
};

int main ()
{
delete new std::vector<int, MyAllocator<int> >;
}



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Martin Sebor made changes - 17/Jul/08 08:48 PM
Field Original Value New Value
Assignee Martin Sebor [ sebor ]
Martin Sebor made changes - 17/Jul/08 08:50 PM
Severity Compiler Error
Affects Version/s 4.2.1 [ 12312690 ]
Affects Version/s 4.1.4 [ 12310693 ]
Affects Version/s 4.2.0 [ 12311945 ]
Fix Version/s 4.2.2 [ 12313096 ]
Remaining Estimate 8h [ 28800 ]
Original Estimate 8h [ 28800 ]
Martin Sebor made changes - 17/Jul/08 08:51 PM
Link This issue relates to STDCXX-744 [ STDCXX-744 ]
Martin Sebor made changes - 17/Jul/08 09:58 PM
Status Open [ 1 ] In Progress [ 3 ]
Martin Sebor made changes - 17/Jul/08 09:59 PM
Time Spent 2h [ 7200 ]
Remaining Estimate 8h [ 28800 ] 6h [ 21600 ]