Re: Initializing of vector<const string> fails - gcc bug?
The problem appears to be that vector does not have a constructor that
accepts a const type.
Can you change it to
const std::vector<string> ...
or will you be adding more elements to the vector later?
On Wed, 4 Dec 2013 07:07:04 CST, Helmut Jarausch
<jarausch@igpm.rwth-aachen.de> wrote:
Hi,
I cannot initialize a vector of const string elements with gcc-4.8.2
-std=c++11
The example below will be compiled if 'const string' is replaced by
'string'.
Is this a gcc bug or a restriction of the C++11 standard?
Many thanks for a hint,
Helmut
#include <string>
using std::string;
#include <vector>
int main() { // compiled with std=c++11 using gcc-4.8.2
std::vector<const string> Labels= {"A","B"};
}
/* I have removed '/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/include'
at the beginning of the error messages below
In file included
from x86_64-pc-linux-gnu/bits/c++allocator.h:33:0,
from bits/allocator.h:46,
from string:41,
from Vector_init_const_string.C:1:
ext/new_allocator.h: In instantiation of
'struct __gnu_cxx::new_allocator<const std::basic_string<char> >':
...
Vector_init_const_string.C:8:29:
required from here
ext/new_allocator.h:93:7: error:
'const _Tp* __gnu_cxx::new_allocator<_Tp>::
address(__gnu_cxx::new_allocator<_Tp>::const_reference) const
[with _Tp = const std::basic_string<char>;
__gnu_cxx::new_allocator<_Tp>::const_pointer
= const std::basic_string<char>*;
__gnu_cxx::new_allocator<_Tp>::const_reference
= const std::basic_string<char>&]' cannot be overloaded
address(const_reference __x) const _GLIBCXX_NOEXCEPT
ext/new_allocator.h:89:7: error:
with '_Tp*
__gnu_cxx::new_allocator<_Tp>::address(__gnu_cxx::new_allocator<_Tp>::refere
nce)
const [with _Tp = const std::basic_string<char>;
__gnu_cxx::new_allocator<_Tp>::pointer
= const std::basic_string<char>*;
__gnu_cxx::new_allocator<_Tp>::reference = const std::basic_string<char>&]'
address(reference __x) const _GLIBCXX_NOEXCEPT
ext/new_allocator.h: In instantiation of
'void
__gnu_cxx::new_allocator<_Tp>::deallocate(__gnu_cxx::new_allocator<_Tp>::poi
nter,
__gnu_cxx::new_allocator<_Tp>::size_type)
[with _Tp = const std::basic_string<char>;
__gnu_cxx::new_allocator<_Tp>::pointer
= const std::basic_string<char>*;
__gnu_cxx::new_allocator<_Tp>::size_type = long unsigned int]':
...
Vector_init_const_string.C:8:45: required from here
ext/new_allocator.h:110:30: error: invalid conversion from 'const void*' to
'void*' [-fpermissive]
{ ::operator delete(__p); }
In file included
from ext/new_allocator.h:33:0,
...
from string:41,
from Vector_init_const_string.C:1:
new:95:6: error: initializing argument 1 of 'void operator delete(void*)'
[-fpermissive]
void operator delete(void*) _GLIBCXX_USE_NOEXCEPT
In file included
from vector:62:0,
from Vector_init_const_string.C:4:
...
Vector_init_const_string.C:8:45: required from here
bits/stl_construct.h:75:7: error:
invalid static_cast from type 'const std::basic_string<char>*' to type
'void*'
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...);
}
*/
--
Remove del for email
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]