SunCC std :: allocator和size_type max_size(size_type)const成员函数?

时间:2019-01-01 22:33:40

标签: c++ solaris allocator sunstudio suncc

我们使用custom allocator将内存归零。没什么。它具有std::allocator中所述的类型和成员函数。

我最近将自定义分配器用于std::vector<T, A>(分配器与A),这是自定义分配器的新应用。它在AIX,BSD,Linux,OSX和Windows上测试了OK。

在Solaris上进行测试导致编译失败。看起来SunCC需要一个size_type max_size(size_type) const成员函数:

//
// /opt/developerstudio12.5/lib/compilers/include/CC/Cstd/memory
//
size_type max_size ()  const
{
  return alloc_.max_size(sizeof(_Tt));
}

在同一文件中,有一个size_type max_size (size_type) const

//
// Alternate allocator uses an interface class (allocator_interface)
// to get type safety.
//
template <class _Tt>
class allocator
{
public:
    ...
    size_type max_size (size_type size) const
    {
      return 1 > UINT_MAX/size ? size_type(1) : size_type(UINT_MAX/size);
    }
};

在Sun分配器上搜索信息时,找不到有用的信息。

我的第一个问题是,该成员函数来自哪里?它是SunCC专用的吗?它是早期Rogue Wave实施的遗迹吗?也许还有其他东西?

我的第二个问题是,是否仅为SunCC添加此成员函数?还是我们应该使用一个选项将其禁用以实现可移植性?也许还有其他东西?


这是Sun Studio 12.3和12.4的编译形式:

$ CXX=/opt/solarisstudio12.3/bin/CC gmake xed25519.o
/opt/solarisstudio12.3/bin/CC -DNDEBUG -g -xO3 -DCRYPTOPP_DISABLE_AVX2 -template=no%extdef -c xed25519.cpp
"/opt/solarisstudio12.3/prod/include/CC/Cstd/memory", line 479: Error: Too many arguments in call to "CryptoPP::AllocatorBase<unsigned char>::max_size() const".
"/opt/solarisstudio12.3/prod/include/CC/Cstd/vector", line 387:     Where: While instantiating "std::allocator_interface<CryptoPP::AllocatorWithCleanup<unsigned char, 0>, unsigned char>::max_size() const".
"/opt/solarisstudio12.3/prod/include/CC/Cstd/vector", line 387:     Where: Instantiated from std::vector<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, 0>>::max_size() const.
"/opt/solarisstudio12.3/prod/include/CC/Cstd/vector", line 397:     Where: Instantiated from non-template code.
1 Error(s) detected.

这是使用Sun Studio 12.5和12.6进行编译的样子:

$ CXX=/opt/developerstudio12.6/bin/CC gmake xed25519.o
/opt/developerstudio12.6/bin/CC -DNDEBUG -g -xO3 -template=no%extdef -c xed25519.cpp
"/opt/developerstudio12.6/lib/compilers/include/CC/Cstd/memory", line 479: Error: Too many arguments in call to "CryptoPP::AllocatorBase<unsigned char>::max_size() const".
"/opt/developerstudio12.6/lib/compilers/include/CC/Cstd/vector", line 387:     Where: While instantiating "std::allocator_interface<CryptoPP::AllocatorWithCleanup<unsigned char, 0>, unsigned char>::max_size() const".
"/opt/developerstudio12.6/lib/compilers/include/CC/Cstd/vector", line 387:     Where: Instantiated from std::vector<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, 0>>::reserve(unsigned).
"xed25519.h", line 280:     Where: Instantiated from non-template code.
 >> Assertion:   (../lnk/v2vtable.cc, line 49)
    while processing xed25519.cpp at line 0.
gmake: *** [xed25519.o] Error 2

0 个答案:

没有答案