public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/64913] New: basic_string fails to use custom allocator
@ 2015-02-03  9:29 antoshkka at gmail dot com
  2015-02-10 13:17 ` [Bug libstdc++/64913] " redi at gcc dot gnu.org
  2015-02-10 13:32 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: antoshkka at gmail dot com @ 2015-02-03  9:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64913

            Bug ID: 64913
           Summary: basic_string fails to use custom allocator
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com

Consider the following example:

template<class CharT>
struct my_allocator
  : std::allocator<CharT>
{};

typedef std::basic_string< char
  , std::char_traits<char>
  , my_allocator<char>
> my_string;


my_string s1;
my_string s2(static_cast<my_string&&>(s1)); // Oops

Attempt to move construct my_string produces the following error:

/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h: In
instantiation of ???std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)
[with _CharT = char; _Traits = std::char_traits<char>; _Alloc =
my_allocator<char>]???:
../boost/lexical_cast.hpp:45:16:   required from ???Target
boost::lexical_cast(const Source&) [with Target =
std::__cxx11::basic_string<char, std::char_traits<char>, my_allocator<char> >;
Source = std::__cxx11::basic_string<char, std::char_traits<char>,
my_allocator<char> >]???
../libs/lexical_cast/test/lexical_cast_test.cpp:510:5:   required from here
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:475:73:
error: no matching function for call to ???std::__cxx11::basic_string<char,
std::char_traits<char>, my_allocator<char>
>::_Alloc_hider::_Alloc_hider(std::__cxx11::basic_string<char,
std::char_traits<char>, my_allocator<char> >::pointer,
std::remove_reference<std::allocator<char>&>::type)???
       : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator()))
                                                                         ^
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:108:2:
note: candidate: std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::_Alloc_hider::_Alloc_hider(std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::pointer, const _Alloc&) [with _CharT = char; _Traits =
std::char_traits<char>; _Alloc = my_allocator<char>;
std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::pointer = char*]
  _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc())
  ^
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:108:2:
note:   no known conversion for argument 2 from
???std::remove_reference<std::allocator<char>&>::type {aka
std::allocator<char>}??? to ???const my_allocator<char>&???
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:106:14:
note: candidate: std::__cxx11::basic_string<char, std::char_traits<char>,
my_allocator<char> >::_Alloc_hider::_Alloc_hider(const
std::__cxx11::basic_string<char, std::char_traits<char>, my_allocator<char>
>::_Alloc_hider&)
       struct _Alloc_hider : allocator_type // TODO check __is_final
              ^
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:106:14:
note:   candidate expects 1 argument, 2 provided
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:106:14:
note: candidate: std::__cxx11::basic_string<char, std::char_traits<char>,
my_allocator<char>
>::_Alloc_hider::_Alloc_hider(std::__cxx11::basic_string<char,
std::char_traits<char>, my_allocator<char> >::_Alloc_hider&&)
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:106:14:
note:   candidate expects 1 argument, 2 provided
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h: In
instantiation of ???std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)
[with _CharT = wchar_t; _Traits = std::char_traits<wchar_t>; _Alloc =
my_allocator<wchar_t>]???:
../boost/lexical_cast.hpp:45:16:   required from ???Target
boost::lexical_cast(const Source&) [with Target =
std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>,
my_allocator<wchar_t> >; Source = std::__cxx11::basic_string<wchar_t,
std::char_traits<wchar_t>, my_allocator<wchar_t> >]???
../libs/lexical_cast/test/lexical_cast_test.cpp:532:5:   required from here
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:475:73:
error: no matching function for call to ???std::__cxx11::basic_string<wchar_t,
std::char_traits<wchar_t>, my_allocator<wchar_t>
>::_Alloc_hider::_Alloc_hider(std::__cxx11::basic_string<wchar_t,
std::char_traits<wchar_t>, my_allocator<wchar_t> >::pointer,
std::remove_reference<std::allocator<wchar_t>&>::type)???
       : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator()))
                                                                         ^
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:108:2:
note: candidate: std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::_Alloc_hider::_Alloc_hider(std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::pointer, const _Alloc&) [with _CharT = wchar_t; _Traits =
std::char_traits<wchar_t>; _Alloc = my_allocator<wchar_t>;
std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::pointer = wchar_t*]
  _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc())
  ^
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:108:2:
note:   no known conversion for argument 2 from
???std::remove_reference<std::allocator<wchar_t>&>::type {aka
std::allocator<wchar_t>}??? to ???const my_allocator<wchar_t>&???
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:106:14:
note: candidate: std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>,
my_allocator<wchar_t> >::_Alloc_hider::_Alloc_hider(const
std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>,
my_allocator<wchar_t> >::_Alloc_hider&)
       struct _Alloc_hider : allocator_type // TODO check __is_final
              ^
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:106:14:
note:   candidate expects 1 argument, 2 provided
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:106:14:
note: candidate: std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>,
my_allocator<wchar_t>
>::_Alloc_hider::_Alloc_hider(std::__cxx11::basic_string<wchar_t,
std::char_traits<wchar_t>, my_allocator<wchar_t> >::_Alloc_hider&&)
/home/trippels/gcc_test/usr/local/include/c++/5.0.0/bits/basic_string.h:106:14:
note:   candidate expects 1 argument, 2 provided


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libstdc++/64913] basic_string fails to use custom allocator
  2015-02-03  9:29 [Bug libstdc++/64913] New: basic_string fails to use custom allocator antoshkka at gmail dot com
@ 2015-02-10 13:17 ` redi at gcc dot gnu.org
  2015-02-10 13:32 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2015-02-10 13:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64913

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That's not a valid allocator,
allocator_traits<my_allocator<X>>::rebind_alloc<X> produces std::allocator<X>
but it should be my_allocator<X>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libstdc++/64913] basic_string fails to use custom allocator
  2015-02-03  9:29 [Bug libstdc++/64913] New: basic_string fails to use custom allocator antoshkka at gmail dot com
  2015-02-10 13:17 ` [Bug libstdc++/64913] " redi at gcc dot gnu.org
@ 2015-02-10 13:32 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2015-02-10 13:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64913

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And indeed if you fix the allocator (either by defining a correct
my_allocator::rebind, or declaring it as private so std::allocator::rebind
isn't found) then it compiles OK.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-10 13:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-03  9:29 [Bug libstdc++/64913] New: basic_string fails to use custom allocator antoshkka at gmail dot com
2015-02-10 13:17 ` [Bug libstdc++/64913] " redi at gcc dot gnu.org
2015-02-10 13:32 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).