SunCC std::allocator and size_type max_size(size_type) const member function?

206 views Asked by At

We use a custom allocator that zeroizes memory. There's not much to it. It has the types and member functions described at std::allocator.

I recently used the custom allocator for a std::vector<T, A> (with A the allocator), which is a new application of the custom allocator. It tested OK on AIX, BSD, Linux, OSX, and Windows.

Testing on Solaris caused a compile failure. It looks like SunCC expects a size_type max_size(size_type) const member function:

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

And from the same file, there is a 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);
    }
};

I'm not finding useful hits when searching for information on the Sun allocator.

My first question is, where did this member function come from? Is it SunCC specific? Is it a vestige of an early Rogue Wave implementation? Or maybe something else?

My second question is, should this member function be added for just SunCC? Or should we be using an option to disable it for portability? Or maybe something else?


Here's what the compile looks like with Sun Studio 12.3 and 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.

Here's what the compile looks like with Sun Studio 12.5 and 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

There are 0 answers