weidai11 / cryptopp

free C++ class library of cryptographic schemes
https://cryptopp.com
Other
4.87k stars 1.51k forks source link

[C++20] -Wdeprecated-enum-enum-conversion raises many warnings with -std=gnu++20 #1016

Closed stac47 closed 3 years ago

stac47 commented 3 years ago

I am compiling Crypto++ with GCC 11 and -std=gnu++20 and the compilation raises many warnings like the following one:

asn.h:494:37: warning: bitwise operation between different enumeration types 'CryptoPP::ASNTag' and
'CryptoPP::ASNIdFlag' is deprecated [-Wdeprecated-enum-enum-conversion]
  494 |         enum {DefaultTag = SEQUENCE | CONSTRUCTED};
      |                            ~~~~~~~~~^~~~~~~~~~~~~

From the GCC documentation (https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options)

-Wno-deprecated-enum-enum-conversion (C++ and Objective-C++ only)

    Disable the warning about the case when the usual arithmetic conversions are applied on operands where
    one is of enumeration type and the other is of a different enumeration type. This conversion was
    deprecated in C++20. For example:

    enum E1 { e };
    enum E2 { f };
    int k = f - e;

    -Wdeprecated-enum-enum-conversion is enabled by default with -std=gnu++20. In pre-C++20 dialects, this
    warning can be enabled by -Wenum-conversion.

Requested information:

noloader commented 3 years ago

Thanks @stac47,

I can duplicate similar problems on Fedora 33 with Clang. F33 GCC is 10.2, which does not tickle the issue.

A lot of those values are placed in enums to creates a const class value that does not take up space; as opposed to, say, a static int, which would require a memory allocation.

(That's about a useless warning in my naive opinion, but that's a different matter).

What do you recommend?

noloader commented 3 years ago

Cleared at Commit de45ebeec15c and Commit f7e6af6344f2.

Thanks again for the report.