[clang-tools-extra] [clang-tidy] Improved readability redundant casting with enums (PR #111424)

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 19 02:22:26 PST 2024


=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/111424 at github.com>


================
@@ -221,3 +221,16 @@ void testRedundantDependentNTTPCasting() {
   // CHECK-MESSAGES: :[[@LINE-4]]:25: note: source type originates from referencing this non-type template parameter
   // CHECK-FIXES: {{^}}  T a = V;
 }
+
+enum E1 : char {};
+enum class E2 : char {};
+
+void testEnum(E1 e1, E2 e2){
+  char a = static_cast<char>(e1);
----------------
PiotrZSL wrote:

That isn't a redundant cast. Such casts should be done in explicit way. In C++ is even better to use:
std::to_underlying since C++23 or std::underlying_type now.

https://github.com/llvm/llvm-project/pull/111424


More information about the cfe-commits mailing list