@@ -11308,6 +11308,32 @@ static const IntegerLiteral *getIntegerLiteral(Expr *E) {
11308
11308
return IL;
11309
11309
}
11310
11310
11311
+ static void CheckConditionalWithEnumTypes(Sema &S, SourceLocation Loc,
11312
+ Expr *LHS, Expr *RHS) {
11313
+ QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
11314
+ QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
11315
+
11316
+ const auto *LHSEnumType = LHSStrippedType->getAs<EnumType>();
11317
+ if (!LHSEnumType)
11318
+ return;
11319
+ const auto *RHSEnumType = RHSStrippedType->getAs<EnumType>();
11320
+ if (!RHSEnumType)
11321
+ return;
11322
+
11323
+ // Ignore anonymous enums.
11324
+ if (!LHSEnumType->getDecl()->hasNameForLinkage())
11325
+ return;
11326
+ if (!RHSEnumType->getDecl()->hasNameForLinkage())
11327
+ return;
11328
+
11329
+ if (S.Context.hasSameUnqualifiedType(LHSStrippedType, RHSStrippedType))
11330
+ return;
11331
+
11332
+ S.Diag(Loc, diag::warn_conditional_mixed_enum_types)
11333
+ << LHSStrippedType << RHSStrippedType << LHS->getSourceRange()
11334
+ << RHS->getSourceRange();
11335
+ }
11336
+
11311
11337
static void DiagnoseIntInBoolContext(Sema &S, Expr *E) {
11312
11338
E = E->IgnoreParenImpCasts();
11313
11339
SourceLocation ExprLoc = E->getExprLoc();
@@ -11799,6 +11825,8 @@ static void CheckConditionalOperator(Sema &S, ConditionalOperator *E,
11799
11825
bool Suspicious = false;
11800
11826
CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious);
11801
11827
CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);
11828
+ CheckConditionalWithEnumTypes(S, E->getBeginLoc(), E->getTrueExpr(),
11829
+ E->getFalseExpr());
11802
11830
11803
11831
if (T->isBooleanType())
11804
11832
DiagnoseIntInBoolContext(S, E);
0 commit comments