tests/lint: show bug in conditional expression (since 2021-07-15)
Since cgram.y 1.325 from 2021-07-15, conditional expressions did not accept a comma-expression in the then-branch anymore. In practice, this is an edge case though since comma expressions are rare.
This commit is contained in:
parent
51b2be3c67
commit
3120116ed3
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: expr_precedence.c,v 1.5 2021/07/26 17:27:22 rillig Exp $ */
|
||||
/* $NetBSD: expr_precedence.c,v 1.6 2021/07/26 18:06:43 rillig Exp $ */
|
||||
# 3 "expr_precedence.c"
|
||||
|
||||
/*
|
||||
|
@ -51,3 +51,27 @@ assignment_associativity(int arg)
|
|||
|
||||
left = arg;
|
||||
}
|
||||
|
||||
void
|
||||
conditional_associativity(_Bool cond1, _Bool cond2, int a, int b, int c)
|
||||
{
|
||||
/* The then-expression can be an arbitrary expression. */
|
||||
var = cond1 ? cond2 ? a : b : c;
|
||||
var = cond1 ? (cond2 ? a : b) : c;
|
||||
|
||||
/* The then-expression can even be a comma-expression. */
|
||||
/* expect+1: error: syntax error ',' [249] *//* FIXME */
|
||||
var = cond1 ? cond2 ? a, b : (b, a) : c;
|
||||
|
||||
var = cond1 ? a : cond2 ? b : c;
|
||||
/*
|
||||
* In almost all programming languages, '?:' is right-associative,
|
||||
* which allows for easy chaining.
|
||||
*/
|
||||
var = cond1 ? a : (cond2 ? b : c);
|
||||
/*
|
||||
* In PHP, '?:' is left-associative, which is rather surprising and
|
||||
* requires more parentheses to get the desired effect.
|
||||
*/
|
||||
var = (cond1 ? a : cond2) ? b : c;
|
||||
}
|
||||
|
|
|
@ -2,3 +2,4 @@ expr_precedence.c(15): error: syntax error '4' [249]
|
|||
expr_precedence.c(18): error: non-constant initializer [177]
|
||||
expr_precedence.c(35): error: 'var' undefined [99]
|
||||
expr_precedence.c(35): error: syntax error '=' [249]
|
||||
expr_precedence.c(64): error: syntax error ',' [249]
|
||||
|
|
Loading…
Reference in New Issue