473,498 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

compile time error due to changes in stl_list.h code

I am trying to get rid of compile time error that I am getting only in
RHEL5
(not in RHEL4) apparently due to the changes in the stl_list.h file.
The error that I am getting is coming from the following code that
attempts
to remove an item from the list:

class shm_objptr_list : public std::list < void*, SharedMemAlloc<void
* >
{
.....
bool remove(void *data) {
iterator l_iter = find(data);

if(l_iter == end()) return false;
erase(l_iter); // <=== Compiler flags this line
return true;
}

========================
The allocator is declared as :

template<class T>
class SharedMemAlloc {

public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T *pointer;
typedef const T *const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template <class _Tstruct rebind {
typedef SharedMemAlloc<_Tother;
};

static pointer allocate(size_type n)
{
return (pointer)SharedMemObj::allocate(n);
}
static void deallocate(void* p, size_type n)
{
SharedMemObj::deallocate(p, n);
}

void construct(pointer p, const T&val) {new (p) T(val); }
void destroy(pointer p) {p->~T(); }

};
==============================================
The error looks like this:
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/
bits/stl_list.h:
In member function typename _Alloc::rebind<_Tp >::other
std::_List_base<_Tp,
_Alloc>::_M_get_Tp_allocator() const [with _Tp = void*, _Alloc =
SharedMemAlloc<std::_List_node<void* ]:

/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/
bits/stl_list.h:1149:
instantiated from void std::list<_Tp, _
Alloc>::_M_erase(std::_List_iterator<_Tp>) [with _Tp = void*, _Alloc =
SharedMemAlloc<std::_List_node<void*]

/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/
bits/list.tcc:98:
instantiated from 'typename std::list<_Tp, _ Alloc>::iterator
std::list<_Tp,
_Alloc>::erase(std::_List_iterator<_Tp>) [with _Tp = void*, _Alloc =
SharedMemAlloc<std::_List_node <void*]'
shmcont.h:71: instantiated from here

/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/
bits/stl_list.h:327:
error: conversion from 'const SharedMemAllo c<std::_List_node<void*>
>' to
non-scalar type 'sharedMemAlloc<void*>' requested
================================================== ==========

I noticed that in a new stl_list.h we have the following:
-----------------------------------------------------------
typedef typename _Alloc::template rebind<_List_node<_Tp>
>::other
_Node_alloc_type;

typedef typename _Alloc::template rebind<_Tp>::other
_Tp_alloc_type;

Tp_alloc_type
_M_get_Tp_allocator() const
{ return *static_cast<const _Node_alloc_type*>(&this-
>_M_impl); }
allocator_type
get_allocator() const
{ return _M_get_Tp_allocator(); }
----------------------------------------------------------------

while in the old one:
----------------------------------------------------------------
typedef typename _Alloc::template rebind<_List_node<_Tp::other

_Node_Alloc_type;
allocator_type
get_allocator() const
{ return allocator_type(*static_cast<const
_Node_Alloc_type*>(&this->_M_impl)); }
-----------------------------------------------------------------

I do not know how to change my declaration of the allocator to allow
conversion required by the new header file.

-- FR

Jul 17 '07 #1
5 3156
On Tue, 17 Jul 2007 08:06:42 -0700, fimarn wrote:
I am trying to get rid of compile time error that I am getting only in
RHEL5
(not in RHEL4) apparently due to the changes in the stl_list.h file. The
error that I am getting is coming from the following code that attempts
to remove an item from the list:
[code snipped]

Could you possibly post a complete minimal program that demonstrates the
problem?

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8

Cheers,

--
Lionel B
Jul 17 '07 #2
fimarn wrote:
I am trying to get rid of compile time error that I am getting only in
RHEL5
(not in RHEL4) apparently due to the changes in the stl_list.h file.
....
================================================== ==========

I noticed that in a new stl_list.h we have the following:
-----------------------------------------------------------
typedef typename _Alloc::template rebind<_List_node<_Tp>
::other
_Node_alloc_type;

typedef typename _Alloc::template rebind<_Tp>::other
_Tp_alloc_type;

Tp_alloc_type
_M_get_Tp_allocator() const
{ return *static_cast<const _Node_alloc_type*>(&this-
_M_impl); }

allocator_type
get_allocator() const
{ return _M_get_Tp_allocator(); }
----------------------------------------------------------------

while in the old one:
----------------------------------------------------------------
typedef typename _Alloc::template rebind<_List_node<_Tp::other

_Node_Alloc_type;
allocator_type
get_allocator() const
{ return allocator_type(*static_cast<const
_Node_Alloc_type*>(&this->_M_impl)); }
-----------------------------------------------------------------

I do not know how to change my declaration of the allocator to allow
conversion required by the new header file.

-- FR
I love your use of 'l_' to prefix local variables. You also did a
good job of converting the code for the outside world (but I spotted
two anomalies ;-). It actually took me over 5 minutes to find the
problem, but I understand why you posted as little as you did. The
problem in your new stl_list is:
_Tp_alloc_type
_M_get_Tp_allocator() const
{ return *static_cast<const _Node_alloc_type*>(&this-
>_M_impl); }
should read
_Node_alloc_type
_M_get_Tp_allocator() const
{ return *static_cast<const _Node_alloc_type*>(&this-
>_M_impl); }
Also, make sure 'allocator_type' is typedef'd as '_Node_alloc_type',
not '_Tp_alloc_type'. I think Red Hat needs to fix that pronto...I
wonder how std::allocator even works with it the way it is.

Regards,
Milburn Young

Jul 18 '07 #3
fimarn wrote:
I am trying to get rid of compile time error that I am getting
only in RHEL5 (not in RHEL4) apparently due to the changes in
the stl_list.h file. The error that I am getting is coming
from the following code that attempts to remove an item from
the list:
[...]
========================
The allocator is declared as :
template<class T>
class SharedMemAlloc {

public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T *pointer;
typedef const T *const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template <class _Tstruct rebind {
typedef SharedMemAlloc<_Tother;
};

static pointer allocate(size_type n)
{
return (pointer)SharedMemObj::allocate(n);
}
static void deallocate(void* p, size_type n)
{
SharedMemObj::deallocate(p, n);
}

void construct(pointer p, const T&val) {new (p) T(val); }
void destroy(pointer p) {p->~T(); }
};
You're missing the conversion constructor. In the standard
allocator, it's a:

template< typename U allocator( allocator< U const& ) ;

but if I understand the requirements correctly, all that is
required is that:

Allocator< T a( b ) ;

is legal, where b has a type Allocator< U >, with U different
from T. (So a conversion operator or an explicit constructor
would be legal. But I'd follow the model of the standard
allocator; I'd guess that very few, if any, implementations are
tested with anything really exotic.)

PS: I've not tried to test with this added to your allocator,
but it looks like a likely cause. And did you compile with
"-D_GLIBCXX_CONCEPT_CHECKS -D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC"? I have no idea if this would help,
but I rather think that if you didn't get an error at the first
attempt to instantiate the template (i.e. when you use it as a
base class, in the header), the people at g++ would probably
consider this an error, and try to fix it in a future release.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 19 '07 #4
On Jul 19, 3:42 am, James Kanze <james.ka...@gmail.comwrote:
fimarn wrote:
I am trying to get rid of compile time error that I am getting
only in RHEL5 (not in RHEL4) apparently due to the changes in
the stl_list.h file. The error that I am getting is coming
from the following code that attempts to remove an item from
the list:

[...]


========================
The allocator is declared as :
template<class T>
class SharedMemAlloc {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T *pointer;
typedef const T *const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template <class _Tstruct rebind {
typedef SharedMemAlloc<_Tother;
};
static pointer allocate(size_type n)
{
return (pointer)SharedMemObj::allocate(n);
}
static void deallocate(void* p, size_type n)
{
SharedMemObj::deallocate(p, n);
}
void construct(pointer p, const T&val) {new (p) T(val); }
void destroy(pointer p) {p->~T(); }
};

You're missing the conversion constructor. In the standard
allocator, it's a:

template< typename U allocator( allocator< U const& ) ;

but if I understand the requirements correctly, all that is
required is that:

Allocator< T a( b ) ;

is legal, where b has a type Allocator< U >, with U different
from T. (So a conversion operator or an explicit constructor
would be legal. But I'd follow the model of the standard
allocator; I'd guess that very few, if any, implementations are
tested with anything really exotic.)

PS: I've not tried to test with this added to your allocator,
but it looks like a likely cause. And did you compile with
"-D_GLIBCXX_CONCEPT_CHECKS -D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC"? I have no idea if this would help,
but I rather think that if you didn't get an error at the first
attempt to instantiate the template (i.e. when you use it as a
base class, in the header), the people at g++ would probably
consider this an error, and try to fix it in a future release.

--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34- Hide quoted text -

- Show quoted text -
I am not sure if I understand your suggestion. My allocators name is
SharedMemAlloc, so do I do the conversion that you suggested:

Allocator< T a( b ) ;

I guess I need to make sure that my allocator handles not only (void
*) argument, but also std::_List_node<void* . I do not know how you
write it in C++.

Thanks for your help.

Jul 19 '07 #5
On Jul 19, 8:53 pm, fimarn <fim...@gmail.comwrote:
On Jul 19, 3:42 am, James Kanze <james.ka...@gmail.comwrote:
fimarn wrote:
I am trying to get rid of compile time error that I am getting
only in RHEL5 (not in RHEL4) apparently due to the changes in
the stl_list.h file. The error that I am getting is coming
from the following code that attempts to remove an item from
the list:
[...]
========================
The allocator is declared as :
template<class T>
class SharedMemAlloc {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T *pointer;
typedef const T *const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template <class _Tstruct rebind {
typedef SharedMemAlloc<_Tother;
};
static pointer allocate(size_type n)
{
return (pointer)SharedMemObj::allocate(n);
}
static void deallocate(void* p, size_type n)
{
SharedMemObj::deallocate(p, n);
}
void construct(pointer p, const T&val) {new (p) T(val); }
void destroy(pointer p) {p->~T(); }
};
You're missing the conversion constructor. In the standard
allocator, it's a:
template< typename U allocator( allocator< U const& ) ;
but if I understand the requirements correctly, all that is
required is that:
Allocator< T a( b ) ;
is legal, where b has a type Allocator< U >, with U different
from T. (So a conversion operator or an explicit constructor
would be legal. But I'd follow the model of the standard
allocator; I'd guess that very few, if any, implementations are
tested with anything really exotic.)
I am not sure if I understand your suggestion. My allocators name is
SharedMemAlloc, so do I do the conversion that you suggested:
Allocator< T a( b ) ;
Where? I don't see any user defined constructors or conversion
operators in SharedMemAlloc, and the compiler isn't going to
provide any generic constructor for you.
I guess I need to make sure that my allocator handles not only (void
*) argument, but also std::_List_node<void* .
That's what the standard says. You must be able to create an
allocator of type SharedMemAlloc< T1 by copying an allocator
of type SharedMemAlloc< T0 >. On the other hand, you don't need
to be able to construct an allocator instance from a void*
(which you don't support either); just from an allocator of a
different type.
I do not know how you write it in C++.
It's your allocator, so if you don't know, no one does:-).

If the allocator has no state, it is trivial. The template
constructor is empty. If the allocator has the same state for
all allocated types, then that state must be copied. If the
allocator has state which depends on the allocated type, then
you'll have to figure out how to generically map that state.

If the above declaration of SharedMemAlloc is complete, then it
has no state (which sort of surprises me; I'd expect at least a
pointer to the actual object which manages the shared memory).
So just adding:

template< typename U >
SharedMemAlloc( SharedMemAlloc< U const& ) {}

to the class template definition should do the trick.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 20 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1867
by: OMouse | last post by:
Hi, I just switched to using STL for my linked lists and obviously I need a way to insert. I have all the necessary includes (list & algorithm) and the other functions that I've used (erase & find)...
5
3297
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new...
2
4614
by: Glen | last post by:
I'm working on a custom assembly and I'm trying to figure out the best approach to handling known constraints within the assembly, once compiled, to alert the developer at compile time of a...
0
942
by: AMeador | last post by:
I have and app that has about a dozen forms and a globals.cs file (it is not a form, just code). I have a few variables in this file that I want all the other forms to use. I have a frmGeneral that...
3
1564
by: idikoko | last post by:
I have a small problem I am trying to extract charcters from one string store it in another and then compare the new string and out a msg. The code looks fine but it always runs into a compiler...
1
5367
by: electrixnow | last post by:
Help!, I need to compile this code with static libs so it run on another XP machine that does'nt have MS Studio installed. When I compile now I get an ERROR: 1>------ Rebuild All started:...
5
5352
by: DFB | last post by:
I am the author of the ZLibNetWrapper project on SourceForge (located at zlibnetwrapper.sf.net). This project is a simple mixed-mode .NET wrapper around the ZLib compression library. The ZLib...
2
2144
by: tikcireviva | last post by:
Hi Guys, I am not sure what's wrong with my program. When I ran it under the GDB, it shows the following messages , which said that the issue is from stl_list.h. Does anyone know what's...
0
920
by: mm | last post by:
I'm developing a C# Windows CE 5.0 Application. The Solution that I'm working with has only one project containing files for: - the main form - 4 or 5 forms which are used as modal dialogs - 3...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.