clang may throw the following warning: include/clang/AST/DeclarationName.h:210:52: error: arithmetic between different enumeration types ('clang::DeclarationName::StoredNameKind' and 'clang::detail::DeclarationNameExtra::ExtraKind') is deprecated when flags -Werror,-Wdeprecated-enum-enum-conversion are on.
Details
Diff Detail
Unit Tests
Event Timeline
The changes here look correct to me, but they complicate the code a reasonable amount. I almost wonder whether we want to add a helper function (perhaps even to STLExtras.h?) along the lines of a cleaned up version of:
template <typename EnumTy1, typename EnumTy2> auto addEnumValues(EnumTy1 LHS, EnumTy2 RHS) { return static_cast<std::underlying_type_t<EnumTy1>>(LHS) + static_cast<std::underlying_type_t<EnumTy2>>(RHS); }
(We'd probably want some enable_if magic to protect the interface a bit more as well). WDYT of something like that? (That change would require some unit testing coverage as well, but this strikes me as something we're likely to want to reuse given that the functionality is deprecated.)
Looks definitely better! How about this slightly changed version protecting the interface?
/// Helper which adds two underlying types of enumeration type. template <typename EnumTy1, typename EnumTy2, typename UT1 = std::enable_if_t<std::is_enum_v<EnumTy1>, std::underlying_type_t<EnumTy1>>, typename UT2 = std::enable_if_t<std::is_enum_v<EnumTy2>, std::underlying_type_t<EnumTy2>>> constexpr auto addEnumValues(EnumTy1 LHS, EnumTy2 RHS) { return static_cast<UT1>(LHS) + static_cast<UT2>(RHS); }
I feel like this is something we may wish to readopt in the future for other similar cases as well (e.g., -Wdeprecated-anon-enum-enum-conversion in Comment.h).
Thanks! This is heading in the right direction. You should also add some test coverage to llvm/unittests/ADT/STLExtrasTests.cpp for the new interface.
llvm/include/llvm/ADT/STLExtras.h | ||
---|---|---|
207–211 ↗ | (On Diff #420458) | Oops, but is_enum_v<> is C++17 and up, and we currently still require only C++14, so this will have to use the long-hand form (precommit CI was failing because of this). |
Fixed the change, and added a new test. Hope the coverage is at a fairly good level now!
llvm/unittests/ADT/STLExtrasTest.cpp | ||
---|---|---|
994 ↗ | (On Diff #420957) | It looks like you need to include <climits> for the macros. |
llvm/unittests/ADT/STLExtrasTest.cpp | ||
---|---|---|
994 ↗ | (On Diff #420957) | Right, saw the CI, fixed, thanks! :) |
LGTM, thank you for the new interface and fixes! (Current Precommit CI failures look unrelated to me.)
Awesome, thank you for reviewing this! PS: I do not have commit access, feel free to close it, if you say.
Ah, thank you for letting me know you don't have commit access. I'm happy to land this on your behalf. What name and email address would you like me to use for patch attribution?
Thank you for the fix! I've landed on your behalf in 7c3d8c8977cfc013254783b85b9fc6026566b35f.