Skip to content

Commit 309729e

Browse files
authored
[C2y] Claim nonconformance to WG14 N3348 (#166966)
This paper allows use of * in a multidimensional array extent within a _Generic selection association, as a wildcard for any array extent. Clang does not currently support this feature, so this is just some initial test coverage along with an update to the conformance site.
1 parent 2705951 commit 309729e

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

clang/test/C/C2y/n3348.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
}

clang/www/c_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ <h2 id="c2y">C2y implementation status</h2>
324324
<tr>
325325
<td>Matching of Multi-Dimensional Arrays in Generic Selection Expressions</td>
326326
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3348.pdf">N3348</a></td>
327-
<td class="unknown" align="center">Unknown</td>
327+
<td class="none" align="center">No</td>
328328
</tr>
329329
<tr>
330330
<td>The __COUNTER__ predefined macro</td>

0 commit comments

Comments
 (0)