Merge pull request #1897 from acqn/TernaryFix
[cc65] Fixed errors in the conditional operator "? :" parser
This commit is contained in:
@@ -3869,9 +3869,9 @@ static void hieQuest (ExprDesc* Expr)
|
|||||||
|
|
||||||
ED_FinalizeRValLoad (&Expr2);
|
ED_FinalizeRValLoad (&Expr2);
|
||||||
} else {
|
} else {
|
||||||
/* Constant boolean subexpression could still have deferred inc/
|
/* Constant subexpression could still have deferred inc/dec
|
||||||
** dec operations, so just flush their side-effects at this
|
** operations, so just flush their side-effects at this sequence
|
||||||
** sequence point.
|
** point.
|
||||||
*/
|
*/
|
||||||
DoDeferred (SQP_KEEP_NONE, &Expr2);
|
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
|
/* Parse third expression. Remember for later if it is a NULL pointer
|
||||||
** expression, then load it into the primary.
|
** expression, then load it into the primary.
|
||||||
*/
|
*/
|
||||||
ExprWithCheck (hie1, &Expr3);
|
ExprWithCheck (hieQuest, &Expr3);
|
||||||
Expr3IsNULL = ED_IsNullPtr (&Expr3);
|
Expr3IsNULL = ED_IsNullPtr (&Expr3);
|
||||||
if (!IsTypeVoid (Expr3.Type) &&
|
if (!IsTypeVoid (Expr3.Type) &&
|
||||||
ED_YetToLoad (&Expr3) &&
|
ED_YetToLoad (&Expr3) &&
|
||||||
@@ -3920,9 +3920,9 @@ static void hieQuest (ExprDesc* Expr)
|
|||||||
|
|
||||||
ED_FinalizeRValLoad (&Expr3);
|
ED_FinalizeRValLoad (&Expr3);
|
||||||
} else {
|
} else {
|
||||||
/* Constant boolean subexpression could still have deferred inc/
|
/* Constant subexpression could still have deferred inc/dec
|
||||||
** dec operations, so just flush their side-effects at this
|
** operations, so just flush their side-effects at this sequence
|
||||||
** sequence point.
|
** point.
|
||||||
*/
|
*/
|
||||||
DoDeferred (SQP_KEEP_NONE, &Expr3);
|
DoDeferred (SQP_KEEP_NONE, &Expr3);
|
||||||
}
|
}
|
||||||
@@ -4036,6 +4036,8 @@ static void hieQuest (ExprDesc* Expr)
|
|||||||
} else {
|
} else {
|
||||||
*Expr = Expr3;
|
*Expr = Expr3;
|
||||||
}
|
}
|
||||||
|
/* The result expression is always an rvalue */
|
||||||
|
ED_MarkExprAsRVal (Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setup the target expression */
|
/* Setup the target expression */
|
||||||
|
|||||||
@@ -752,7 +752,7 @@ static void PPhieQuest (PPExpr* Expr)
|
|||||||
|
|
||||||
/* Parse third expression */
|
/* Parse third expression */
|
||||||
PPExprInit (&Expr3);
|
PPExprInit (&Expr3);
|
||||||
PPhie1 (&Expr3);
|
PPhieQuest (&Expr3);
|
||||||
|
|
||||||
/* Set the result */
|
/* Set the result */
|
||||||
Expr->IVal = Expr->IVal ? Expr2.IVal != 0 : Expr3.IVal != 0;
|
Expr->IVal = Expr->IVal ? Expr2.IVal != 0 : Expr3.IVal != 0;
|
||||||
|
|||||||
8
test/err/bug1893.c
Normal file
8
test/err/bug1893.c
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user