[clang] [C] Handle comma operator for implicit int->enum conversions (PR #138752)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed May 7 06:08:10 PDT 2025
================
@@ -12490,6 +12499,17 @@ static void AnalyzeImplicitConversions(
(BO->getOpcode() == BO_And ? "&&" : "||"));
S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
}
+ } else if (BO->isCommaOp() && !S.getLangOpts().CPlusPlus) {
+ /// Analyze the given comma operator. The basic idea behind the analysis
+ /// is to analyze the left and right operands slightly differently. The
+ /// left operand needs to check whether the operand itself has an implicit
+ /// conversion, but not whether the left operand induces an implicit
+ /// conversion for the entire comma expression itself. This is similar to
+ /// how CheckConditionalOperand behaves; it's as-if the correct operand
+ /// were directly used for the implicit conversion check.
+ CheckCommaOperand(S, BO->getLHS(), T, BO->getOperatorLoc(), false);
+ CheckCommaOperand(S, BO->getRHS(), T, BO->getOperatorLoc(), true);
----------------
erichkeane wrote:
```suggestion
CheckCommaOperand(S, BO->getRHS(), T, BO->getOperatorLoc(), /*ExtraCheckForImplicitConversion=*/true);
```
https://github.com/llvm/llvm-project/pull/138752
More information about the cfe-commits
mailing list