Fixed errors in the conditional operator "? :" parser.

This commit is contained in:
acqn 2022-11-02 13:56:55 +08:00
parent ad7c5a6617
commit d84cc2d122
3 changed files with 18 additions and 8 deletions

View File

@ -3869,9 +3869,9 @@ static void hieQuest (ExprDesc* Expr)
ED_FinalizeRValLoad (&Expr2);
} else {
/* Constant boolean subexpression could still have deferred inc/
** dec operations, so just flush their side-effects at this
** sequence point.
/* Constant subexpression could still have deferred inc/dec
** operations, so just flush their side-effects at this sequence
** point.
*/
DoDeferred (SQP_KEEP_NONE, &Expr2);
}
@ -3907,7 +3907,7 @@ static void hieQuest (ExprDesc* Expr)
/* Parse third expression. Remember for later if it is a NULL pointer
** expression, then load it into the primary.
*/
ExprWithCheck (hie1, &Expr3);
ExprWithCheck (hieQuest, &Expr3);
Expr3IsNULL = ED_IsNullPtr (&Expr3);
if (!IsTypeVoid (Expr3.Type) &&
ED_YetToLoad (&Expr3) &&
@ -3920,9 +3920,9 @@ static void hieQuest (ExprDesc* Expr)
ED_FinalizeRValLoad (&Expr3);
} else {
/* Constant boolean subexpression could still have deferred inc/
** dec operations, so just flush their side-effects at this
** sequence point.
/* Constant subexpression could still have deferred inc/dec
** operations, so just flush their side-effects at this sequence
** point.
*/
DoDeferred (SQP_KEEP_NONE, &Expr3);
}
@ -4036,6 +4036,8 @@ static void hieQuest (ExprDesc* Expr)
} else {
*Expr = Expr3;
}
/* The result expression is always an rvalue */
ED_MarkExprAsRVal (Expr);
}
/* Setup the target expression */

View File

@ -752,7 +752,7 @@ static void PPhieQuest (PPExpr* Expr)
/* Parse third expression */
PPExprInit (&Expr3);
PPhie1 (&Expr3);
PPhieQuest (&Expr3);
/* Set the result */
Expr->IVal = Expr->IVal ? Expr2.IVal != 0 : Expr3.IVal != 0;

8
test/err/bug1893.c Normal file
View File

@ -0,0 +1,8 @@
/* bug #1893 - Compiler accepts a ternary expression where it shouldn't */
int main(void)
{
int a, b, c;
a == 1? b : c = 3;
return 0;
}