https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/131811

>From 72a2a45c52508510c9d43152fa5f2e533222dce8 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinja...@gmail.com>
Date: Tue, 18 Mar 2025 15:35:43 +0100
Subject: [PATCH 1/2] [Clang] Demote mixed enumeration arithmertic error to a
 warning

In C++, defaulted to an error.

C++ removed these features but the removal negatively impact
users.

Fixes #92340
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +++++-
 clang/lib/Sema/SemaChecking.cpp                  | 2 +-
 clang/lib/Sema/SemaExpr.cpp                      | 2 +-
 clang/test/SemaCXX/cxx2c-enum-compare.cpp        | 5 +++--
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a88af192fb2a4..6996e7ec1cb29 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7639,9 +7639,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
   "%sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
   InGroup<DeprecatedEnumEnumConversion>;
-def err_conv_mixed_enum_types_cxx26 : Error<
+
+def err_conv_mixed_enum_types: Error <
   "invalid %sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2">;
+def warn_conv_mixed_enum_types_cxx26 : Warning <
+  err_conv_mixed_enum_types.Summary>,
+  InGroup<EnumEnumConversion>, DefaultError;
 
 def warn_arith_conv_mixed_anon_enum_types : Warning<
   warn_arith_conv_mixed_enum_types.Summary>,
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index c6feb35efce85..fc8994c65659f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -15323,7 +15323,7 @@ static bool checkBuiltinVectorMathMixedEnums(Sema &S, 
Expr *LHS, Expr *RHS,
            R = RHS->getEnumCoercedType(S.Context);
   if (L->isUnscopedEnumerationType() && R->isUnscopedEnumerationType() &&
       !S.Context.hasSameUnqualifiedType(L, R)) {
-    return S.Diag(Loc, diag::err_conv_mixed_enum_types_cxx26)
+    return S.Diag(Loc, diag::err_conv_mixed_enum_types)
            << LHS->getSourceRange() << RHS->getSourceRange()
            << /*Arithmetic Between*/ 0 << L << R;
   }
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e19136b394800..3ff372bdc9d0c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1533,7 +1533,7 @@ void Sema::checkEnumArithmeticConversions(Expr *LHS, Expr 
*RHS,
     // In C++ 26, usual arithmetic conversions between 2 different enum types
     // are ill-formed.
     if (getLangOpts().CPlusPlus26)
-      DiagID = diag::err_conv_mixed_enum_types_cxx26;
+      DiagID = diag::warn_conv_mixed_enum_types_cxx26;
     else if (!L->castAs<EnumType>()->getDecl()->hasNameForLinkage() ||
              !R->castAs<EnumType>()->getDecl()->hasNameForLinkage()) {
       // If either enumeration type is unnamed, it's less likely that the
diff --git a/clang/test/SemaCXX/cxx2c-enum-compare.cpp 
b/clang/test/SemaCXX/cxx2c-enum-compare.cpp
index f47278a60725e..1a7363ecf0be4 100644
--- a/clang/test/SemaCXX/cxx2c-enum-compare.cpp
+++ b/clang/test/SemaCXX/cxx2c-enum-compare.cpp
@@ -1,9 +1,10 @@
-// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify -triple 
%itanium_abi_triple
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both,expected
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both,nowarn 
-Wno-enum-enum-conversion
 
 enum E1 { e };
 enum E2 { f };
 void test() {
-    int b = e <= 3.7; // expected-error {{invalid comparison of enumeration 
type 'E1' with floating-point type 'double'}}
+    int b = e <= 3.7; // both-error {{invalid comparison of enumeration type 
'E1' with floating-point type 'double'}}
     int k = f - e; // expected-error {{invalid arithmetic between different 
enumeration types ('E2' and 'E1')}}
     int x = 1 ? e : f; // expected-error {{invalid conditional expression 
between different enumeration types ('E1' and 'E2')}}
 }

>From 8157b2086af015619eb268f0d21238066f9d7be5 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinja...@gmail.com>
Date: Tue, 18 Mar 2025 15:56:16 +0100
Subject: [PATCH 2/2] remove unused label

---
 clang/test/SemaCXX/cxx2c-enum-compare.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/cxx2c-enum-compare.cpp 
b/clang/test/SemaCXX/cxx2c-enum-compare.cpp
index 1a7363ecf0be4..96fbd368b1696 100644
--- a/clang/test/SemaCXX/cxx2c-enum-compare.cpp
+++ b/clang/test/SemaCXX/cxx2c-enum-compare.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both,expected
-// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both,nowarn 
-Wno-enum-enum-conversion
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both 
-Wno-enum-enum-conversion
 
 enum E1 { e };
 enum E2 { f };

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to