Issue Details (XML | Word | Printable)

Key: STDCXX-744
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Martin Sebor
Votes: 0
Watchers: 0
Operations

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

error calling std::allocator::allocate() from user-defined allocator

Created: 10/Mar/08 09:15 PM   Updated: 02/Dec/08 03:05 AM
Return to search
Component/s: 20. General Utilities
Affects Version/s: 4.2.0, 4.2.1
Fix Version/s: 4.2.2

Time Tracking:
Original Estimate: 2h
Original Estimate - 2h
Remaining Estimate: 2h
Remaining Estimate - 2h
Time Spent: Not Specified
Remaining Estimate - 2h

Environment: gcc 4.1.2
Issue Links:
Reference
 

Severity: Compiler Error


 Description  « Hide
The program below reduced from Plum Hall test case lvs07a/t237.dir/_23252Y11.cpp fails to compile with both the head of trunk and stdcxx 4.2.0. It compiles fine with gcc 4.1.2.
$ cat t.cpp && make t
#include <memory>
#include <vector>

template <class T>
struct Allocator: std::allocator<T> {
    T* allocate (unsigned n, const T *p) {
        return std::allocator<T>::allocate (n, p);
    }
};

int main () {
    std::vector<int, Allocator<int> > v (2, 3);
}
gcc -c -I$TOPDIRinclude/ansi -D_RWSTDDEBUG    -I$TOPDIRinclude -I/build/sebor/stdcxx-gcc-4.1.2-11S-LVS/include -I$TOPDIRinclude/ansi -I/build/sebor/PlumHall/lvs07a/conform -I/build/sebor/PlumHall/lvs07a/dst.3  -pedantic -nostdinc++ -g   -W -Wall -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long -Wcast-align    t.cpp
$TOPDIRinclude/vector.cc: In member function 'void std::vector<_TypeT, _Allocator>::_C_realloc(typename _Allocator::size_type) [with _TypeT = int, _Allocator = Allocator<int>]':
$TOPDIRinclude/vector:501:   instantiated from 'void std::vector<_TypeT, _Allocator>::reserve(typename _Allocator::size_type) [with _TypeT = int, _A
llocator = Allocator<int>]'
$TOPDIRinclude/vector.cc:219:   instantiated from 'void std::vector<_TypeT, _Allocator>::_C_insert_n(const _rw::__rw_debug_iter<std::vector<_TypeT,
 _Allocator>, typename _Allocator::pointer, typename _Allocator::pointer>&, typename _Allocator::size_type, typename _Allocator::const_reference) [with _TypeT = int, _Allocator = Allocator<int>]'
$TOPDIRinclude/vector:301:   instantiated from 'void std::vector<_TypeT, _Allocator>::insert(__rw::__rw_debug_iter<std::vector<_TypeT, _Allocator>, 
typename _Allocator::pointer, typename _Allocator::pointer>, typename _Allocator::size_type, typename _Allocator::const_reference) [with _TypeT = int, _Allocator = Allocator<int>]'
$TOPDIRinclude/vector.cc:152:   instantiated from 'void std::vector<_TypeT, _Allocator>::_C_assign_n(typename _Allocator::size_type, typename _Allocator::const_reference) [with _TypeT = int, _Allocator = Allocator<int>]'
$TOPDIRinclude/vector:362:   instantiated from 'void std::vector<_TypeT, _Allocator>::_C_assign(_IntType, _IntType, int) [with _IntType = int, _Type
T = int, _Allocator = Allocator<int>]'
$TOPDIRinclude/vector:194:   instantiated from 'void std::vector<_TypeT, _Allocator>::assign(_InputIter, _InputIter) [with _InputIter = int, _TypeT = int, _Allocator = Allocator<int>]'
$TOPDIRinclude/vector:173:   instantiated from 'std::vector<_TypeT, _Allocator>::vector(_InputIter, _InputIter, const _Allocator&) [with _InputIter = int, _TypeT = int, _Allocator = Allocator<int>]'
t.cpp:12:   instantiated from here
$TOPDIRinclude/vector.cc:85: error: no matching function for call to  'std::vector<int, Allocator<int> >::allocate(long unsigned int&, std::vector<int, Allocator<int> >* const)'
t.cpp:6: note: candidates are: T* Allocator<T>::allocate(unsigned int, const T*) [with T = int]
make: *** [t.o] Error 1


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Martin Sebor added a comment - 14/May/08 06:37 PM
Let's look into this in 4.2.2.

Martin Sebor added a comment - 17/Jul/08 08:11 PM
This is partly because our vector derives from its Allocator argument to take advantage of the EBO. The direct derivation has turned out to be a mistake but fixing it has to be done with care so as not to break the ABI. The fix is to make the Allocator a base class of a member type containing a non-empty member object such as the size of the vector instead.