1*67e74705SXin Li // RUN: %clang_cc1 -std=c1x -fsyntax-only -verify %s
2*67e74705SXin Li
3*67e74705SXin Li void g(void);
4*67e74705SXin Li
foo(int n)5*67e74705SXin Li void foo(int n) {
6*67e74705SXin Li (void) _Generic(0,
7*67e74705SXin Li struct A: 0, // expected-error {{type 'struct A' in generic association incomplete}}
8*67e74705SXin Li void(): 0, // expected-error {{type 'void ()' in generic association not an object type}}
9*67e74705SXin Li int[n]: 0); // expected-error {{type 'int [n]' in generic association is a variably modified type}}
10*67e74705SXin Li
11*67e74705SXin Li (void) _Generic(0,
12*67e74705SXin Li void (*)(): 0, // expected-note {{compatible type 'void (*)()' specified here}}
13*67e74705SXin Li void (*)(void): 0); // expected-error {{type 'void (*)(void)' in generic association compatible with previously specified type 'void (*)()'}}
14*67e74705SXin Li
15*67e74705SXin Li (void) _Generic((void (*)()) 0, // expected-error {{controlling expression type 'void (*)()' compatible with 2 generic association types}}
16*67e74705SXin Li void (*)(int): 0, // expected-note {{compatible type 'void (*)(int)' specified here}}
17*67e74705SXin Li void (*)(void): 0); // expected-note {{compatible type 'void (*)(void)' specified here}}
18*67e74705SXin Li
19*67e74705SXin Li (void) _Generic(0, // expected-error {{controlling expression type 'int' not compatible with any generic association type}}
20*67e74705SXin Li char: 0, short: 0, long: 0);
21*67e74705SXin Li
22*67e74705SXin Li int a1[_Generic(0, int: 1, short: 2, float: 3, default: 4) == 1 ? 1 : -1];
23*67e74705SXin Li int a2[_Generic(0, default: 1, short: 2, float: 3, int: 4) == 4 ? 1 : -1];
24*67e74705SXin Li int a3[_Generic(0L, int: 1, short: 2, float: 3, default: 4) == 4 ? 1 : -1];
25*67e74705SXin Li int a4[_Generic(0L, default: 1, short: 2, float: 3, int: 4) == 1 ? 1 : -1];
26*67e74705SXin Li int a5[_Generic(0, int: 1, short: 2, float: 3) == 1 ? 1 : -1];
27*67e74705SXin Li int a6[_Generic(0, short: 1, float: 2, int: 3) == 3 ? 1 : -1];
28*67e74705SXin Li
29*67e74705SXin Li int a7[_Generic("test", char *: 1, default: 2) == 1 ? 1 : -1];
30*67e74705SXin Li int a8[_Generic(g, void (*)(void): 1, default: 2) == 1 ? 1 : -1];
31*67e74705SXin Li
32*67e74705SXin Li const int i = 12;
33*67e74705SXin Li int a9[_Generic(i, int: 1, default: 2) == 1 ? 1 : -1];
34*67e74705SXin Li
35*67e74705SXin Li // This is expected to not trigger any diagnostics because the controlling
36*67e74705SXin Li // expression is not evaluated.
37*67e74705SXin Li (void)_Generic(*(int *)0, int: 1);
38*67e74705SXin Li }
39