Search code examples
c++crypto++

Crypto++ giving a compiler error in algparam.h


I have the following lines in a rather large file:

#include <sha.h>
#include <hex.h>

Which, when compiled, throws this compiler error:

1>d:\work\app\tools\cryptopp\algparam.h(322): error C2061: syntax error : identifier 'buffer'
1>          d:\work\app\tools\cryptopp\algparam.h(321) : while compiling class template member function 'void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void *) const'
1>          with
1>          [
1>              T=bool
1>          ]
1>          d:\work\app\tools\cryptopp\algparam.h(329) : see reference to class template instantiation 'CryptoPP::AlgorithmParametersTemplate<T>' being compiled
1>          with
1>          [
1>              T=bool
1>          ]

I'm pretty sure I'm forgetting something, but I'm not sure what. If I don't include hex.h, I don't have any problems and I get a SHA256 hash just fine, but when I do include hex.h, the error pops up.

Edit

In case anyone wonders, from algparam.h of Crypto++ toolkit:

void MoveInto(void *buffer) const //<=== line 320
{
    AlgorithmParametersTemplate<T>* p = new(buffer)
    AlgorithmParametersTemplate<T>(*this);
}

CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<bool>; // <== line 329

Edit: Removed unrelated code


Solution

  • I fixed the problem by temporarily undefining new, which was defined as a macro to some extra debugging code.

    #pragma push_macro("new")
    #undef new
    /* #includes for Crypto++ go here */
    #pragma pop_macro("new")