[clang] 40ee5a0 - [C2y] Claim conformance to WG14 N3481

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 7 06:37:24 PST 2025


Author: Aaron Ballman
Date: 2025-03-07T09:37:15-05:00
New Revision: 40ee5a0bcc333f2df5427bfaba73f2dc83c0ae19

URL: https://github.com/llvm/llvm-project/commit/40ee5a0bcc333f2df5427bfaba73f2dc83c0ae19
DIFF: https://github.com/llvm/llvm-project/commit/40ee5a0bcc333f2df5427bfaba73f2dc83c0ae19.diff

LOG: [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.

Added: 
    clang/test/C/C2y/n3481.c

Modified: 
    clang/www/c_status.html

Removed: 
    


################################################################################
diff  --git a/clang/test/C/C2y/n3481.c b/clang/test/C/C2y/n3481.c
new file mode 100644
index 0000000000000..1088b62dd8085
--- /dev/null
+++ b/clang/test/C/C2y/n3481.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -verify -std=c2y %s
+// RUN: %clang_cc1 -verify -std=c23 %s
+
+/* WG14 N3481: Yes
+ * Slay Some Earthly Demons XVI
+ *
+ * It was previously UB to use a non-array lvalue with an incomplete type in a
+ * context which required the value of the object. Clang has always diagnosed
+ * this as an error, except when the incomplete type is void. Then we allow the
+ * dereference, but not for a value computation.
+ */
+
+struct f *p;  // expected-note {{forward declaration of 'struct f'}}
+void g(void) {
+  (void)*p; // expected-error {{incomplete type 'struct f' where a complete type is required}}
+}
+
+void h(void *ptr) {
+  (void)*ptr; // expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}
+  (*ptr)++;   /* expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}
+                 expected-error {{cannot increment value of type 'void'}}
+               */
+}

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index b198053ece041..b72b96dd598b5 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -309,7 +309,7 @@ <h2 id="c2y">C2y implementation status</h2>
     <tr>
       <td>Slay Some Earthly Demons XVI</td>
       <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3481.pdf">N3481</a></td>
-      <td class="unknown" align="center">Unknown</td>
+      <td class="full" align="center">Yes</td>
 	</tr>
     <tr>
       <td>Slay Some Earthly Demons XVII</td>


        


More information about the cfe-commits mailing list