[AGENT++] src/asn1.cpp:386:5: error: ISO C++17 does not allow 'register' storage class specifier

Isaac Nickaein nickaein.i at gmail.com
Tue Sep 4 08:59:08 CEST 2018


> I have problems to compile snmp++ with newer clang++ compiler
> ../../src/asn1.cpp:386:5: error: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
>     register int header_len;
>     ^~~~~~~~~
> 1 error generated.

I suggest removing the `register` keyword.

Historically, It has been used to hint the compiler to allocate a CPU
register for this variable, but today compilers ignore it and have an
optimization step which make these decisions.

Article by Herb Sutter:
http://www.drdobbs.com/184403859
search for "CPU" in which concludes:
"Never write register. It's exactly as meaningful as whitespace"

More discussion on this:
https://stackoverflow.com/questions/3207018

>
> There are also cppcheck serious warnings:
>
> src/auth_priv.cpp:2046:0: warning: Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'. [useAutoPointerArray]
>     std::auto_ptr<unsigned char> ipad(new unsigned char[block_size]);
> ^
> src/auth_priv.cpp:2047:0: warning: Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'. [useAutoPointerArray]
>     std::auto_ptr<unsigned char> opad(new unsigned char[block_size]);
> ^

This seems to be a misuse of auto_ptr with array. auto_ptr always call
`delete` for freeing memory which is not suitable for arrays (delete[]
must be called instead).
More info: https://stackoverflow.com/questions/6520844

How about using std::vector?


More information about the AGENTPP mailing list