User forums > Using Code::Blocks
CC: does not list "allocate", a member function of std::allocator.
ollydbg:
--- Quote from: edison on September 04, 2014, 04:06:14 pm ---
--- Code: ---#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;
}
--- End code ---
--- End quote ---
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
--- Code: --- /**
* @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.
};
--- End code ---
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
--- Code: ---#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
--- End code ---
and in mingw-builds\473\mingw32\lib\gcc\i686-w64-mingw32\4.7.3\include\c++\ext\new_allocator.h
I see
--- Code: --- 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)));
}
--- End code ---
See the last function, it is there.
But I'm still not sure how to fix this bug in our CC's code.
ollydbg:
Oh, it looks like it works OK here, see the screen shot.
I just close and reopen the project.
edison:
I am using mingw-w64 4.2 i686 dw2 (gcc 4.9.1) and codeblocks svn 9904, close then re-open project does not help here.
I will try the CB 13.12 w/tdm-gcc 4.7.1 latter.
ollydbg:
--- Quote from: edison on September 04, 2014, 04:50:31 pm ---I am using mingw-w64 4.2 i686 dw2 (gcc 4.9.1) and codeblocks svn 9904, close then re-open project does not help here.
I will try the CB 13.12 w/tdm-gcc 4.7.1 latter.
--- End quote ---
My testing environment is latest C::B trunk and mingw-build 4.7.3.
Jenna:
Works out of the box with C::B 9884 and "g++ (GCC) 4.8.3 20140624 (Red Hat 4.8.3-1)" 64Bit on Fedora 20.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version