Debian Codegraph @

clang/test/C/C2y/n3348.c

raw
1 // RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s
2
3 /* WG14 N3348: No
4 * Matching of Multi-Dimensional Arrays in Generic Selection Expressions
5 *
6 * This allows use of * in a _Generic association as a placeholder for any size
7 * value.
8 *
9 * FIXME: Clang doesn't yet implement this paper. When we do implement it, we
10 * should expose the functionality in earlier language modes (C89) for
11 * compatibility with GCC.
12 */
13
14 void test(int n, int m) {
15 static_assert(1 == _Generic(int[3][2], int[3][*]: 1, int[2][*]: 0)); /* expected-error {{star modifier used outside of function prototype}}
16 expected-error {{array has incomplete element type 'int[]'}}
17 */
18 static_assert(1 == _Generic(int[3][2], int[*][2]: 1, int[*][3]: 0)); // expected-error {{star modifier used outside of function prototype}}
19 static_assert(1 == _Generic(int[3][n], int[3][*]: 1, int[2][*]: 0)); /* expected-error {{star modifier used outside of function prototype}}
20 expected-error {{array has incomplete element type 'int[]'}}
21 */
22 static_assert(1 == _Generic(int[n][m], int[*][*]: 1, char[*][*]: 0)); /* expected-error 2 {{star modifier used outside of function prototype}}
23 expected-error {{array has incomplete element type 'int[]'}}
24 */
25 static_assert(1 == _Generic(int(*)[2], int(*)[*]: 1)); // expected-error {{star modifier used outside of function prototype}}
26 }
27
28 void questionable() {
29 // GCC accepts this despite the * appearing outside of a generic association,
30 // but it's not clear whether that's intentionally supported or an oversight.
31 // It gives a warning about * being used outside of a declaration, but not
32 // with an associated warning group.
33 static_assert(1 == _Generic(int[*][*], int[2][100]: 1)); /* expected-error 2 {{star modifier used outside of function prototype}}
34 expected-error {{array has incomplete element type 'int[]'}}
35 */
36 // GCC claims this matches multiple associations, so the functionality seems
37 // like it may be intended to work?
38 (void)_Generic(int[*][*], /* expected-error 2 {{star modifier used outside of function prototype}}
39 expected-error {{array has incomplete element type 'int[]'}}
40 */
41 int[2][100]: 1,
42 int[3][1000]: 2,
43 );
44 }