[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master a5de0ea 6/9: Fix gcc11 -Wdeprecated-enum-enum
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master a5de0ea 6/9: Fix gcc11 -Wdeprecated-enum-enum-conversion in test_coding_rules |
Date: |
Sat, 23 Oct 2021 18:32:44 -0400 (EDT) |
branch: master
commit a5de0ea1f8ddc942c967f0a4adc11128bad194d4
Author: Vadim Zeitlin <vadim@tt-solutions.com>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Fix gcc11 -Wdeprecated-enum-enum-conversion in test_coding_rules
Don't perform bit arithmetic operations between elements of different
enums, as this is not allowed in C++20 any longer.
Simply cast the enum value to its underlying type (i.e. int) to avoid
the warning, while still doing the same thing because we know that this
operation is safe in this particular case.
---
test_coding_rules.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/test_coding_rules.cpp b/test_coding_rules.cpp
index a8e5e66..d50ea97 100644
--- a/test_coding_rules.cpp
+++ b/test_coding_rules.cpp
@@ -41,6 +41,7 @@
#include <sstream>
#include <stdexcept> // runtime_error
#include <string>
+#include <type_traits> // underlying_type_t
#if !defined LMI_POSIX
int try_main(int, char*[])
@@ -261,7 +262,11 @@ bool file::is_of_phylum(enum_phylum z) const
bool file::is_of_phylum(enum_kingdom z) const
{
- return z & phylum();
+ // C++20 forbids bit operations between enums of different types, even
+ // though this is safe here because enum_kingdom only contains combinations
+ // of primitive phyla from enum_phylum, so cast to the underlying type to
+ // avoid warnings/errors about this generally unsafe operation.
+ return static_cast<std::underlying_type_t<enum_kingdom>>(z) & phylum();
}
/// Analyze a file's name to determine its phylum.
- [lmi-commits] [lmi] master updated (03dc638 -> b0c70e0), Greg Chicares, 2021/10/23
- [lmi-commits] [lmi] master bbc5038 2/9: Disable gcc -Wdeprecated-enum-float-conversion, Greg Chicares, 2021/10/23
- [lmi-commits] [lmi] master a5db27e 1/9: Recognize gcc and g++ 11 versions in the makefile, Greg Chicares, 2021/10/23
- [lmi-commits] [lmi] master d810372 3/9: Trade elegance for simplicity, Greg Chicares, 2021/10/23
- [lmi-commits] [lmi] master 33de332 5/9: Prefer 'long int' to 'long', Greg Chicares, 2021/10/23
- [lmi-commits] [lmi] master e908d9e 8/9: Don't disable -Wdeprecated-enum-enum-conversion in configure, Greg Chicares, 2021/10/23
- [lmi-commits] [lmi] master 1cefad6 4/9: Fix LMI_WX_CHILD_DOCUMENT definition to fix g++11 C++20 build, Greg Chicares, 2021/10/23
- [lmi-commits] [lmi] master a5de0ea 6/9: Fix gcc11 -Wdeprecated-enum-enum-conversion in test_coding_rules,
Greg Chicares <=
- [lmi-commits] [lmi] master 97416cf 7/9: Emulate C++23 to_underlying<>(), Greg Chicares, 2021/10/23
- [lmi-commits] [lmi] master b0c70e0 9/9: Update wxWidgets submodule to fix gcc11 -Wshadow warnings, Greg Chicares, 2021/10/23