Skip to content

Commit e4d910e

Browse files
authored
[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 e8f79eb commit e4d910e

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7639,9 +7639,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
76397639
"%sub{select_arith_conv_kind}0 "
76407640
"different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
76417641
InGroup<DeprecatedEnumEnumConversion>;
7642-
def err_conv_mixed_enum_types_cxx26 : Error<
7642+
7643+
def err_conv_mixed_enum_types: Error <
76437644
"invalid %sub{select_arith_conv_kind}0 "
76447645
"different enumeration types%diff{ ($ and $)|}1,2">;
7646+
def warn_conv_mixed_enum_types_cxx26 : Warning <
7647+
err_conv_mixed_enum_types.Summary>,
7648+
InGroup<EnumEnumConversion>, DefaultError;
76457649

76467650
def warn_arith_conv_mixed_anon_enum_types : Warning<
76477651
warn_arith_conv_mixed_enum_types.Summary>,

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15323,7 +15323,7 @@ static bool checkBuiltinVectorMathMixedEnums(Sema &S, Expr *LHS, Expr *RHS,
1532315323
R = RHS->getEnumCoercedType(S.Context);
1532415324
if (L->isUnscopedEnumerationType() && R->isUnscopedEnumerationType() &&
1532515325
!S.Context.hasSameUnqualifiedType(L, R)) {
15326-
return S.Diag(Loc, diag::err_conv_mixed_enum_types_cxx26)
15326+
return S.Diag(Loc, diag::err_conv_mixed_enum_types)
1532715327
<< LHS->getSourceRange() << RHS->getSourceRange()
1532815328
<< /*Arithmetic Between*/ 0 << L << R;
1532915329
}

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ void Sema::checkEnumArithmeticConversions(Expr *LHS, Expr *RHS,
15331533
// In C++ 26, usual arithmetic conversions between 2 different enum types
15341534
// are ill-formed.
15351535
if (getLangOpts().CPlusPlus26)
1536-
DiagID = diag::err_conv_mixed_enum_types_cxx26;
1536+
DiagID = diag::warn_conv_mixed_enum_types_cxx26;
15371537
else if (!L->castAs<EnumType>()->getDecl()->hasNameForLinkage() ||
15381538
!R->castAs<EnumType>()->getDecl()->hasNameForLinkage()) {
15391539
// 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)