[clang] cbd48b1 - [C99] Claim conformance to "conversion of array to pointer not limited to lvalues"

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 1 11:54:15 PDT 2024


Author: Aaron Ballman
Date: 2024-04-01T14:54:03-04:00
New Revision: cbd48b184eca1ca73e6f20575501d94ad30fbd58

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

LOG: [C99] Claim conformance to "conversion of array to pointer not limited to lvalues"

We don't have a document number for this, but the change was called out
explicitly in the editor's comments in the C99 foreword.

Added: 
    clang/test/C/C99/array-lvalue.c

Modified: 
    clang/www/c_status.html

Removed: 
    


################################################################################
diff  --git a/clang/test/C/C99/array-lvalue.c b/clang/test/C/C99/array-lvalue.c
new file mode 100644
index 00000000000000..4e963b4f74fc32
--- /dev/null
+++ b/clang/test/C/C99/array-lvalue.c
@@ -0,0 +1,38 @@
+/* RUN: %clang_cc1 -verify -pedantic -std=c99 %s
+   RUN: %clang_cc1 -verify=c89 -pedantic -std=c89 %s
+   expected-no-diagnostics
+ */
+
+/* WG14 ???: Yes
+ * Conversion of array to pointer not limited to lvalues
+ *
+ * NB: the original paper number is unknown, this was gleaned from the editor's report
+ * in the C99 foreword. The C99 rationale document did not shed much light on
+ * the situation either, mostly talking about user confusion between lvalue and
+ * modifiable lvalue. However, the crux of the change was C89 changing:
+ *
+ * C89 3.2.2.1: Except when it is the operand of ..., an lvalue that has type
+ * 'array of type' is converted to an expression that has type 'pointer to
+ * type' that points to the initial element of the array object and is not an
+ * lvalue.
+ *
+ * C99 6.3.2.1p3: Except when it is the operand of ..., an expression that has
+ * type 'array of type' is converted to an expression with type 'pointer to
+ * type' that points to the initial element of the array object and is not an
+ * lvalue.
+ */
+
+struct S {
+  char arr[100];
+};
+
+struct S f(void);
+
+void func(void) {
+  char c;
+  /* The return from f() is an rvalue, so this code is not valid in C89, but is
+   * valid in C99.
+   */
+  c = f().arr[10]; /* c89-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
+}
+

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 123897593e5d84..803dce8e29fc04 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -360,7 +360,7 @@ <h2 id="c99">C99 implementation status</h2>
     <tr>
       <td>conversion of array to pointer not limited to lvalues</td>
       <td>Unknown</td>
-      <td class="unknown" align="center">Unknown</td>
+      <td class="full" align="center">Yes</td>
     </tr>
     <tr>
       <td>relaxed constraints on aggregate and union initialization</td>


        


More information about the cfe-commits mailing list