Skip to content

Commit 11518ee

Browse files
committed
[Clang][Backport] Demote mixed enumeration arithmetic error to a warning (llvm#131811)
In C++, defaulted to an error. C++ removed these features but the removal negatively impacts users. Fixes llvm#92340
1 parent 0fcfeac commit 11518ee

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ C++ Language Changes
299299
- The builtin type alias ``__builtin_common_type`` has been added to improve the
300300
performance of ``std::common_type``.
301301

302+
- In C++26 mode, arithmetic conversion errors between mixed enumeration types can
303+
be disabled with ``-Wno-enum-enum-conversion`` (#GH92340).
304+
302305
C++2c Feature Support
303306
^^^^^^^^^^^^^^^^^^^^^
304307

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 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,8 @@ static void checkEnumArithmeticConversions(Sema &S, Expr *LHS, Expr *RHS,
15181518
unsigned DiagID;
15191519
// In C++ 26, usual arithmetic conversions between 2 different enum types
15201520
// are ill-formed.
1521-
if (S.getLangOpts().CPlusPlus26)
1522-
DiagID = diag::err_conv_mixed_enum_types_cxx26;
1521+
if (getLangOpts().CPlusPlus26)
1522+
DiagID = diag::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)