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