1f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne// RUN: %clang_cc1 -std=c1x -fsyntax-only -verify %s
2f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainarvoid g(void);
487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar
5f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournevoid foo(int n) {
6f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  (void) _Generic(0,
7f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      struct A: 0, // expected-error {{type 'struct A' in generic association incomplete}}
8f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      void(): 0,   // expected-error {{type 'void ()' in generic association not an object type}}
9f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      int[n]: 0);  // expected-error {{type 'int [n]' in generic association is a variably modified type}}
10f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
11f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  (void) _Generic(0,
12f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      void (*)():     0,  // expected-note {{compatible type 'void (*)()' specified here}}
13f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      void (*)(void): 0); // expected-error {{type 'void (*)(void)' in generic association compatible with previously specified type 'void (*)()'}}
14f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
15f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  (void) _Generic((void (*)()) 0, // expected-error {{controlling expression type 'void (*)()' compatible with 2 generic association types}}
16f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      void (*)(int):  0,  // expected-note {{compatible type 'void (*)(int)' specified here}}
17f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      void (*)(void): 0); // expected-note {{compatible type 'void (*)(void)' specified here}}
18f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
19f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  (void) _Generic(0, // expected-error {{controlling expression type 'int' not compatible with any generic association type}}
20f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      char: 0, short: 0, long: 0);
21f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
22f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  int a1[_Generic(0, int: 1, short: 2, float: 3, default: 4) == 1 ? 1 : -1];
23f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  int a2[_Generic(0, default: 1, short: 2, float: 3, int: 4) == 4 ? 1 : -1];
24f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  int a3[_Generic(0L, int: 1, short: 2, float: 3, default: 4) == 4 ? 1 : -1];
25f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  int a4[_Generic(0L, default: 1, short: 2, float: 3, int: 4) == 1 ? 1 : -1];
26f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  int a5[_Generic(0, int: 1, short: 2, float: 3) == 1 ? 1 : -1];
27f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  int a6[_Generic(0, short: 1, float: 2, int: 3) == 3 ? 1 : -1];
2887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar
2987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar  int a7[_Generic("test", char *: 1, default: 2) == 1 ? 1 : -1];
3087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar  int a8[_Generic(g, void (*)(void): 1, default: 2) == 1 ? 1 : -1];
3187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar
3287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar  const int i = 12;
3387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar  int a9[_Generic(i, int: 1, default: 2) == 1 ? 1 : -1];
344967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar
354967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar  // This is expected to not trigger any diagnostics because the controlling
364967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar  // expression is not evaluated.
374967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar  (void)_Generic(*(int *)0, int: 1);
38f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}
39