lmi-commits
[Top][All Lists]
Advanced

[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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]