2017-05-11 4 views
1

라이브러리에 gcc 6.3.1이있는 시스템 (arch linux)에서 clang ++ 4.0.0을 사용하는 사용자 정의 할당자를 사용하는 데 많은 어려움이 있습니다.clang ++ v4 및 gcc 6.3 라이브러리가있는 사용자 정의 할당 자

#include <string> 

struct myalloc : std::allocator<char> { 
    using std::allocator<char>::allocator; 
}; 

struct mystring 
    : std::basic_string<char, std::char_traits<char>, myalloc> { 
    using std::basic_string<char, std::char_traits<char>, myalloc>::basic_string; 
}; 

int 
main() 
{ 
    mystring r = "hello"; 
    mystring s (std::move(r)); 
} 

여기 내 의도가 시스템 std::allocator과 완전히 동일하게 동작 사용자 정의 할당을 할 분명히 myalloc에 대한, 그리고 mystring 그것을 사용하는 것을 제외하고 std::string와 동일로 : 여기에 최소한의 비 작동 예입니다 myalloc. 문제를 일으킬 가능성이 가장 적은 시나리오 여야합니다. 이 코드는 g++ -std=c++14 -Wall -Werror 깨끗하게 컴파일

을 (. 물론 한번 내가 더 할당을 사용자 정의하려는 노력), 그러나 함께 clang++ -std=c++14 실패 :

In file included from strerror.cc:1: 
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/string:52: 
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.h:477:9: error: 
     no matching constructor for initialization of 
     'std::__cxx11::basic_string<char, std::char_traits<char>, 
     myalloc>::_Alloc_hider' 
     : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator())) 
     ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
strerror.cc:7:8: note: in instantiation of member function 
     'std::__cxx11::basic_string<char, std::char_traits<char>, 
     myalloc>::basic_string' requested here 
struct mystring 
    ^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.h:109:2: note: 
     candidate constructor not viable: no known conversion from 'typename 
     std::remove_reference<allocator<char> &>::type' (aka 
     'std::allocator<char>') to 'const myalloc' for 2nd argument 
     _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc()) 
     ^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.h:107:14: note: 
     candidate constructor (the implicit move constructor) not viable: requires 
     1 argument, but 2 were provided 
     struct _Alloc_hider : allocator_type // TODO check __is_final 
      ^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.h:107:14: note: 
     candidate constructor (the implicit copy constructor) not viable: requires 
     1 argument, but 2 were provided 
1 error generated. 

는 그 소리 또는 GCC의 도서관이 단지 버그인가, 또는 내 코드에 개념적으로 잘못된 것이 있습니까?

는 당신의 최소한의 예를 들어
+0

왜 'basic_string'에서 파생됩니까? 너의 커스텀 스트링은'use mystring = std :: basic_string , myalloc>'이 아닌가? – j6t

+0

실제 문자열 클래스에 몇 가지 생성자를 추가하고 예를 들어 단순화해야합니다. – user3188445

+0

표준에서 아무것도 basic_string이 상속 가능해야한다고 주장하지 않습니다 ... –

답변

2

최소한의 수정은 가장 (이 경우 당신은 리 바인드 필요하지 않습니다) 표준 : : 할당에서 상속하지 않는 것입니다 물론 struct myalloc

template<class> struct rebind { 
    using other = myalloc; 
}; 

에이 멤버를 추가하는 것입니다, 그리고 문자열을 상속하는 경우에도 해당 클래스는 공용베이스가 아닙니다.