2017-05-11 4 views
1

ライブラリがgcc 6.3.1に付属しているシステム(arch linux)上で、clang ++ 4.0.0でカスタムアロケータを使用するとかなりの問題が発生しています。ここでは、最小限の非稼働例です:myallocは、システムstd::allocatorとまったく同じように動作し、カスタムアロケータであることを、そしてmystringstd::stringと同じであるためにそれが使用することを除いて、ここで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)); 
} 

私の意図は明らかです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'から派生していますか?あなたのカスタム文字列は単に 'mystring = std :: basic_string 、myalloc>'を使うべきではないでしょうか? – j6t

+0

実際の文字列クラスにいくつかのコンストラクタを追加する必要があり、例のために単純化しました。 – user3188445

+0

標準では、basic_stringは継承可能でなければならないと主張していません... –

答えて

2

ご最小限例えば最小限の修正はもちろんstruct myalloc

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

にこのメンバーを追加するために最善のstdから継承することではありません::アロケータ(その場合には、あなたが再バインドを必要としない)、およびありません文字列から継承する場合でも、それらのクラスは公的な基盤として意図されていません。

関連する問題