#include <memory>
int main()
{
std::allocator<int> a1; // default allocator for ints
// int * a = a1.allocate(10); // space for 10 ints
int * a = a1. //<--- here is the bug happened.
return 0;
}
#include <memory>
int main()
{
std::allocator<int> a1; // default allocator for ints
// int * a = a1.allocate(10); // space for 10 ints
int * a = a1. //<--- here is the bug happened.
return 0;
}
OK, I see the reason. (tested under MinGW 4.7.x compiler)
1, I see that std::allocator class is correctly located in
mingw-builds\473\mingw32\lib\gcc\i686-w64-mingw32\4.7.3\include\c++\bits\allocator.h around line 84
/**
* @brief The @a standard allocator, as per [20.4].
*
* See http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt04ch11.html
* for further details.
*/
template<typename _Tp>
class allocator: public __glibcxx_base_allocator<_Tp>
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
template<typename _Tp1>
struct rebind
{ typedef allocator<_Tp1> other; };
allocator() throw() { }
allocator(const allocator& __a) throw()
: __glibcxx_base_allocator<_Tp>(__a) { }
template<typename _Tp1>
allocator(const allocator<_Tp1>&) throw() { }
~allocator() throw() { }
// Inherit everything else.
};
Look, there is not member named "allocate", so it should be in its base class. But when I hover the "__glibcxx_base_allocator", I can't see the declaration...
In mingw-builds\473\mingw32\lib\gcc\i686-w64-mingw32\4.7.3\include\c++\i686-w64-mingw32\bits\c++allocator.h
I see
#ifndef _GLIBCXX_CXX_ALLOCATOR_H
#define _GLIBCXX_CXX_ALLOCATOR_H 1
// Define new_allocator as the base class to std::allocator.
#include <ext/new_allocator.h>
#define __glibcxx_base_allocator __gnu_cxx::new_allocator
#endif
and in mingw-builds\473\mingw32\lib\gcc\i686-w64-mingw32\4.7.3\include\c++\ext\new_allocator.h
I see
template<typename _Tp>
class new_allocator
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
template<typename _Tp1>
struct rebind
{ typedef new_allocator<_Tp1> other; };
new_allocator() _GLIBCXX_USE_NOEXCEPT { }
new_allocator(const new_allocator&) _GLIBCXX_USE_NOEXCEPT { }
template<typename _Tp1>
new_allocator(const new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { }
~new_allocator() _GLIBCXX_USE_NOEXCEPT { }
pointer
address(reference __x) const _GLIBCXX_NOEXCEPT
{ return std::__addressof(__x); }
const_pointer
address(const_reference __x) const _GLIBCXX_NOEXCEPT
{ return std::__addressof(__x); }
// NB: __n is permitted to be 0. The C++ standard says nothing
// about what the return value is when __n == 0.
pointer
allocate(size_type __n, const void* = 0)
{
if (__n > this->max_size())
std::__throw_bad_alloc();
return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
}
See the last function, it is there.
But I'm still not sure how to fix this bug in our CC's code.
If there are multiple copies of the header file I'm not sure which one the code completion plugin will use (or even whether it consistently uses the same header). And mingw-w64 has different files like these:
\mingw32\lib\gcc\i686-w64-mingw32\4.8.1\include\stdint.h
\mingw32\i686-w64-mingw32\include\stdint.h
etc..