mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-29 06:10:09 +08:00
Always allow ({ }) in the ctrl-expr of _Generic
tcc would reject e.g., void f(){ struct {_Bool x:_Generic(({0;}),default:1);} my_x; } with `expected constant`. This patch makes it accept it. (The patch also makes tcc's _Generic a little more "generic" than that of gcc and clang in that that tcc now also accepts `struct {_Bool x:_Generic(({0;}),default:1);} my_x;` in file scope while gcc and clang don't, but I think there's no harm in that and gcc and clang might as well accept it in filescope too, given that they have no problem with e.g., `/*filescope:*/int x=1, y=2, z=_Generic(x+y, int:3);`)
This commit is contained in:
parent
1e2e5671f7
commit
f85b1e393f
3
tccgen.c
3
tccgen.c
@ -5033,13 +5033,16 @@ ST_FUNC void unary(void)
|
|||||||
int has_match = 0;
|
int has_match = 0;
|
||||||
int learn = 0;
|
int learn = 0;
|
||||||
TokenString *str = NULL;
|
TokenString *str = NULL;
|
||||||
|
int saved_const_wanted = const_wanted;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
skip('(');
|
skip('(');
|
||||||
|
const_wanted = 0;
|
||||||
expr_type(&controlling_type, expr_eq);
|
expr_type(&controlling_type, expr_eq);
|
||||||
controlling_type.t &= ~(VT_CONSTANT | VT_VOLATILE | VT_ARRAY);
|
controlling_type.t &= ~(VT_CONSTANT | VT_VOLATILE | VT_ARRAY);
|
||||||
if ((controlling_type.t & VT_BTYPE) == VT_FUNC)
|
if ((controlling_type.t & VT_BTYPE) == VT_FUNC)
|
||||||
mk_pointer(&controlling_type);
|
mk_pointer(&controlling_type);
|
||||||
|
const_wanted = saved_const_wanted;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
learn = 0;
|
learn = 0;
|
||||||
skip(',');
|
skip(',');
|
||||||
|
@ -71,5 +71,8 @@ int main()
|
|||||||
|
|
||||||
(void)_Generic((int(*)[2]){0}, int(*)[2]:0, int(*)[4]:0); //shouldn't match twice
|
(void)_Generic((int(*)[2]){0}, int(*)[2]:0, int(*)[4]:0); //shouldn't match twice
|
||||||
|
|
||||||
|
//should accept ({ }) in the controlling expr of _Generic even in const_wanted contexts
|
||||||
|
struct { _Bool x_0: _Generic(({0;}),default:1); } my_x;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user