This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16875] New: Fails to compile: STL container of const pointer to X


The IMHO valid C++ code in the sample program tt.cc (see below) fails to 
compile. I've tried using different STL containers, but the result was (more or 
less) the same. I've tried to compile this code with three different versions 
of gcc (3.2.1, 3.2.2, and 3.4.1), and all three fail. Furthermore, I've tried 
to compile it with the Intel C++ compiler (v8.0) which accepts the code.

$ g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-
checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

$ g++ -save-temps tt.cc
/usr/include/c++/3.2.2/bits/stl_alloc.h: In instantiation of `std::allocator<X* 
const>':
tt.cc:9:   instantiated from here
/usr/include/c++/3.2.2/bits/stl_alloc.h:674: `const _Tp* 
   std::allocator<_Alloc>::address(const _Tp&) const [with _Tp = X* const]' and 
   `_Tp* std::allocator<_Alloc>::address(_Tp&) const [with _Tp = X* const]' 
   cannot be overloaded
/usr/include/c++/3.2.2/bits/stl_construct.h: In function `void 
   std::_Construct(_T1*, const _T2&) [with _T1 = X* const, _T2 = X*]':
/usr/include/c++/3.2.2/bits/stl_list.h:328:   instantiated from 
`std::_List_node<_Tp>* std::list<_Tp, _Alloc>::_M_create_node(const _Tp&) [with 
_Tp = X* const, _Alloc = std::allocator<X* const>]'
/usr/include/c++/3.2.2/bits/stl_list.h:430:   instantiated from 
`std::_List_iterator<_Tp, _Tp&, _Tp*> std::list<_Tp, _Alloc>::insert
(std::_List_iterator<_Tp, _Tp&, _Tp*>, const _Tp&) [with _Tp = X* const, _Alloc 
= std::allocator<X* const>]'
/usr/include/c++/3.2.2/bits/stl_list.h:479:   instantiated from `void 
std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = X* const, _Alloc = 
std::allocator<X* const>]'
tt.cc:10:   instantiated from here
/usr/include/c++/3.2.2/bits/stl_construct.h:78: static_cast from type `X* 
   const*' to type `void*' casts away constness

$ cat tt.cc
#include <list>

struct X
{
};

int main()
{
  std::list<X* const> li;
  li.push_back(new X());
}

-- 
           Summary: Fails to compile: STL container of const pointer to X
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: loose at astron dot nl
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16875


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]