TL DR
The selection occurs at compile time, but this does not mean that other (not selected) code is discarded. It still needs to be valid, and that means ...
If the default value is not used, and none of the type names is compatible with the type of the control expression, the program will not compile.
(Source)
It was amazing:
Without a default case for "first Y":
#define test(X, Y, c) \ _Generic((X), \ double: _Generic((Y), \ double * : test_double \ ), \ int: _Generic((Y), \ int * : test_int, \ default: test_default \ ) \ ) (X, Y, c)
I get this error:
prog.c: 6:30: error: selector "_Generic" of type "int *" is incompatible with any association
Note that it complains about int * , which is incompatible! What for? Take a good look at the reported line:
int a2 = test(i, s, 1);
X is of type int and Y type int * .
Now comes the important part: breaks occur unconditionally . Therefore, even if X is of type int , the first association for X (when it is of type double ) must be a well-formed program. Thus, with Y being int * , the following should be well formed:
_Generic((Y), \ double * : test_double \ ), \
And since int * not double * , everything breaks here.
I was just looking at the standard (actually N1570) and could not find anything that actually indicates exactly this behavior. I assume that in this case it is possible to report a defect, the standard is too vague about it. I'm trying to do it now.