[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
This commit is contained in:
parent
a169f5ca4e
commit
070cf62530
@ -314,6 +314,9 @@ C++2c Feature Support
|
||||
|
||||
- Implemented `P3176R1 The Oxford variadic comma <https://wg21.link/P3176R1>`_
|
||||
|
||||
- The error produced when doing arithmetic operations on enums of different types
|
||||
can be disabled with ``-Wno-enum-enum-conversion``. (#GH92340)
|
||||
|
||||
C++23 Feature Support
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
- Removed the restriction to literal types in constexpr functions in C++23 mode.
|
||||
|
@ -7567,9 +7567,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 zzzz_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>,
|
||||
|
@ -1519,7 +1519,7 @@ static void checkEnumArithmeticConversions(Sema &S, Expr *LHS, Expr *RHS,
|
||||
// In C++ 26, usual arithmetic conversions between 2 different enum types
|
||||
// are ill-formed.
|
||||
if (S.getLangOpts().CPlusPlus26)
|
||||
DiagID = diag::err_conv_mixed_enum_types_cxx26;
|
||||
DiagID = diag::zzzz_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
|
||||
|
@ -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 -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')}}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user