Botan VS2015 compilation error

I have a strange situation here. I'm trying to use the Botan Crypton Library with VS2015 (because some other parts of the project use heavy C ++ 11 code that VS2013 can't compile) and I'm getting a rather long compilation error (see below).

After testing various things, I've come to the conclusion that even if one of the botan headers is included in the compiled C ++ source file, the compiler is throwing the below error. Right now I have one line in the file:

#include <botan/botan.h>

      

and this is the error I am getting:

    C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\xmemory0(876): error C2664: 'Botan::secure_allocator<_Newfirst>::secure_allocator(const Botan::secure_allocator<_Newfirst> &)': cannot convert
argument 1 from 'std::_Wrap_alloc<Botan::secure_allocator<Botan::byte>>' to 'const Botan::secure_allocator<_Newfirst> &'
        with
        [
            _Newfirst=std::_Container_proxy
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\xmemory0(876): note: Reason: cannot convert from 'std::_Wrap_alloc<Botan::secure_allocator<Botan::byte>>' to 'const Botan::secure_allocator<_Ne
wfirst>'
        with
        [
            _Newfirst=std::_Container_proxy
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\xmemory0(876): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(587): note: see reference to function template instantiation 'std::_Wrap_alloc<Botan::secure_allocator<_Newfirst>>::_Wrap_alloc<std::_Wr
ap_alloc<Botan::secure_allocator<Botan::byte>>>(_Other &) noexcept' being compiled
        with
        [
            _Newfirst=std::_Container_proxy,
            _Other=std::_Wrap_alloc<Botan::secure_allocator<Botan::byte>>
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(587): note: see reference to function template instantiation 'std::_Wrap_alloc<Botan::secure_allocator<_Newfirst>>::_Wrap_alloc<std::_Wr
ap_alloc<Botan::secure_allocator<Botan::byte>>>(_Other &) noexcept' being compiled
        with
        [
            _Newfirst=std::_Container_proxy,
            _Other=std::_Wrap_alloc<Botan::secure_allocator<Botan::byte>>
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(585): note: while compiling class template member function 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(void)
'
        with
        [
            _Ty=Botan::byte,
            _Alloc=Botan::secure_allocator<Botan::byte>
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(552): note: see reference to function template instantiation 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(voi
d)' being compiled
        with
        [
            _Ty=Botan::byte,
            _Alloc=Botan::secure_allocator<Botan::byte>
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(679): note: see reference to class template instantiation 'std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>' being compiled
        with
        [
            _Ty=Botan::byte,
            _Alloc=Botan::secure_allocator<Botan::byte>
        ]
c:\Botan\include\botan-1.11\botan/rng.h(43): note: see reference to class template instantiation 'std::vector<Botan::byte,Botan::secure_allocator<Botan::byte>>' being compiled
NMAKE : fatal error U1077: 'C:\PROGRA~1\MICROS~3.0\VC\bin\cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.

      

Since I was able to compile and run the nerd's tests I have the feeling that I was missing something, but have no idea what. Does anyone have experience with this? (BTW: the same code compiles with g ++ 4.9)

+3


source to share


1 answer


Looking at the sources , it Botan::secure_allocator

doesn't seem to provide a form template constructor

template<class U> secure_allocator(const secure_allocator<U>& other);

      

This is required by the Standard. In the current working draft N4527, the corresponding bits are found in [17.6.3.5]. Table 28 - Requirements for the requirement; the example in paragraph 9 is also helpful.

Thus, we cannot blame the standard library implementation that ships with VC 14 for requiring it to compile. The error, in my opinion, is on Botan's side.


A quick fix is ​​to add a definition like this to Botan::secure_allocator

:

template<class U> secure_allocator(const secure_allocator<U>&) BOTAN_NOEXCEPT { }

      

Since there are no non-static data members in instances of this allocator template, the empty body must be exact. However, I am not familiar with the library and we are talking about cryptography here, so before using this to do any serious stuff, please confirm the changes with the authors of the library.




Another possible workaround:

I noticed that the code calling the mixed type constructor seems to be enabled only if iterator debugging is enabled, which is the default in debug mode.

Have you tried compiling in release mode? If my observations are correct, you will no longer get this error as the additional hardware for debugging the iterator will be disabled.

To get the same behavior in debug mode, set the macro _ITERATOR_DEBUG_LEVEL

to 0

globally.

Debug iterators can be useful for catching errors (as long as the performance hit doesn't affect you), so I won't use this as a permanent fix, but it might be useful as a temporary workaround if you don't want to change the Botan header file.

This might also explain why you were able to compile the tests: perhaps they were compiled in release mode, or at any rate with a combination of settings that disables iterator debugging?

+5


source







All Articles