Skip to content

Commit 070cf62

Browse files
cor3ntintstellar
authored andcommitted
[Clang] Demote mixed enumeration arithmetic error to a warning (#131811)
In C++, defaulted to an error. C++ removed these features but the removal negatively impacts users. Fixes #92340
1 parent a169f5c commit 070cf62

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ C++2c Feature Support
314314

315315
- Implemented `P3176R1 The Oxford variadic comma <https://wg21.link/P3176R1>`_
316316

317+
- The error produced when doing arithmetic operations on enums of different types
318+
can be disabled with ``-Wno-enum-enum-conversion``. (#GH92340)
319+
317320
C++23 Feature Support
318321
^^^^^^^^^^^^^^^^^^^^^
319322
- Removed the restriction to literal types in constexpr functions in C++23 mode.

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
75677567
"%sub{select_arith_conv_kind}0 "
75687568
"different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
75697569
InGroup<DeprecatedEnumEnumConversion>;
7570-
def err_conv_mixed_enum_types_cxx26 : Error<
7570+
7571+
def err_conv_mixed_enum_types: Error <
75717572
"invalid %sub{select_arith_conv_kind}0 "
75727573
"different enumeration types%diff{ ($ and $)|}1,2">;
7574+
def zzzz_warn_conv_mixed_enum_types_cxx26 : Warning <
7575+
err_conv_mixed_enum_types.Summary>,
7576+
InGroup<EnumEnumConversion>, DefaultError;
75737577

75747578
def warn_arith_conv_mixed_anon_enum_types : Warning<
75757579
warn_arith_conv_mixed_enum_types.Summary>,

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ static void checkEnumArithmeticConversions(Sema &S, Expr *LHS, Expr *RHS,
15191519
// In C++ 26, usual arithmetic conversions between 2 different enum types
15201520
// are ill-formed.
15211521
if (S.getLangOpts().CPlusPlus26)
1522-
DiagID = diag::err_conv_mixed_enum_types_cxx26;
1522+
DiagID = diag::zzzz_warn_conv_mixed_enum_types_cxx26;
15231523
else if (!L->castAs<EnumType>()->getDecl()->hasNameForLinkage() ||
15241524
!R->castAs<EnumType>()->getDecl()->hasNameForLinkage()) {
15251525
// If either enumeration type is unnamed, it's less likely that the
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify -triple %itanium_abi_triple
1+
// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both,expected
2+
// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both -Wno-enum-enum-conversion
23

34
enum E1 { e };
45
enum E2 { f };
56
void test() {
6-
int b = e <= 3.7; // expected-error {{invalid comparison of enumeration type 'E1' with floating-point type 'double'}}
7+
int b = e <= 3.7; // both-error {{invalid comparison of enumeration type 'E1' with floating-point type 'double'}}
78
int k = f - e; // expected-error {{invalid arithmetic between different enumeration types ('E2' and 'E1')}}
89
int x = 1 ? e : f; // expected-error {{invalid conditional expression between different enumeration types ('E1' and 'E2')}}
910
}

0 commit comments

Comments
 (0)