[clang] [Clang][Sema] Preserve bit-field info in conditional operator (PR #169480)

Mitch Briles via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 25 21:55:56 PST 2025


================
@@ -4247,6 +4247,13 @@ FieldDecl *Expr::getSourceBitField() {
     if (UnOp->isPrefix() && UnOp->isIncrementDecrementOp())
       return UnOp->getSubExpr()->getSourceBitField();
 
+  if (const ConditionalOperator *Cond = dyn_cast<ConditionalOperator>(E)) {
+    if (FieldDecl *FD = Cond->getTrueExpr()->getSourceBitField())
+      return FD;
+    if (FieldDecl *FD = Cond->getFalseExpr()->getSourceBitField())
+      return FD;
+  }
----------------
MitchBriles wrote:

I think if the operands differ in that way, it's handled in `Sema::CXXCheckConditionalOperands`. If folks can agree on the expected behavior, I'll make sure my patch is correct before marking it as ready.

https://github.com/llvm/llvm-project/pull/169480


More information about the cfe-commits mailing list