History

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);`)

Petr Skocik committed 8 years ago

Commit f85b1e31 parent 1e2e5672 files · +6 −0Browse files

Unified · Split

2 files
  1. tccgen.c +3 −0
  2. tests/tests2/94_generic.c +3 −0
tccgen.c+3−0
@@ -5033,13 +5033,16 @@ ST_FUNC void unary(void) · 5032 unmodified lines
50335033 int has_match = 0;
50345034 int learn = 0;
50355035 TokenString *str = NULL;
5036+ int saved_const_wanted = const_wanted;
50365037
50375038 next();
50385039 skip('(');
5040+ const_wanted = 0;
50395041 expr_type(&controlling_type, expr_eq);
50405042 controlling_type.t &= ~(VT_CONSTANT | VT_VOLATILE | VT_ARRAY);
50415043 if ((controlling_type.t & VT_BTYPE) == VT_FUNC)
50425044 mk_pointer(&controlling_type);
5045+ const_wanted = saved_const_wanted;
50435046 for (;;) {
50445047 learn = 0;
50455048 skip(',');
tests/tests2/94_generic.c+3−0
@@ -71,5 +71,8 @@ int main() · 70 unmodified lines
7171
7272 (void)_Generic((int(*)[2]){0}, int(*)[2]:0, int(*)[4]:0); //shouldn't match twice
7373
74+ //should accept ({ }) in the controlling expr of _Generic even in const_wanted contexts
75+ struct { _Bool x_0: _Generic(({0;}),default:1); } my_x;
76+
7477 return 0;
7578 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t