Skip to content

Commit 40ee5a0

Browse files
committed
[C2y] Claim conformance to WG14 N3481
This paper made it a constraint violation to have an incomplete type during lvalue conversion. Previously, this was undefined behavior. Clang has always diagnosed this for non-void incomplete types. However, Clang does allow derefencing a void pointer (with a diagnostic, so we still meet the conformance requirements), but not for a value computation.
1 parent 8da48b4 commit 40ee5a0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

clang/test/C/C2y/n3481.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clang_cc1 -verify -std=c2y %s
2+
// RUN: %clang_cc1 -verify -std=c23 %s
3+
4+
/* WG14 N3481: Yes
5+
* Slay Some Earthly Demons XVI
6+
*
7+
* It was previously UB to use a non-array lvalue with an incomplete type in a
8+
* context which required the value of the object. Clang has always diagnosed
9+
* this as an error, except when the incomplete type is void. Then we allow the
10+
* dereference, but not for a value computation.
11+
*/
12+
13+
struct f *p; // expected-note {{forward declaration of 'struct f'}}
14+
void g(void) {
15+
(void)*p; // expected-error {{incomplete type 'struct f' where a complete type is required}}
16+
}
17+
18+
void h(void *ptr) {
19+
(void)*ptr; // expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}
20+
(*ptr)++; /* expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}
21+
expected-error {{cannot increment value of type 'void'}}
22+
*/
23+
}

clang/www/c_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ <h2 id="c2y">C2y implementation status</h2>
309309
<tr>
310310
<td>Slay Some Earthly Demons XVI</td>
311311
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3481.pdf">N3481</a></td>
312-
<td class="unknown" align="center">Unknown</td>
312+
<td class="full" align="center">Yes</td>
313313
</tr>
314314
<tr>
315315
<td>Slay Some Earthly Demons XVII</td>

0 commit comments

Comments
 (0)