[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 5 06:35:27 PDT 2024


================
@@ -1741,8 +1741,10 @@ void is_layout_compatible(int n)
   static_assert(!__is_layout_compatible(unsigned char, signed char));
   static_assert(__is_layout_compatible(int[], int[]));
   static_assert(__is_layout_compatible(int[2], int[2]));
-  static_assert(!__is_layout_compatible(int[n], int[2])); // FIXME: VLAs should be rejected
-  static_assert(!__is_layout_compatible(int[n], int[n])); // FIXME: VLAs should be rejected
+  static_assert(!__is_layout_compatible(int[n], int[2]));
+  // expected-error at -1 {{variable length arrays are not supported for '__is_layout_compatible'}}
+  static_assert(!__is_layout_compatible(int[n], int[n]));
----------------
AaronBallman wrote:

I think where we ended up is:

1) Reject incomplete types (still needs to be done)
2) Reject VLAs (done, looks good)
3) FAMs are accepted (no changes needed)

So I think you should implement #1 and add tests for it, then add tests for #3, and I think that finishes this.

https://github.com/llvm/llvm-project/pull/87737


More information about the cfe-commits mailing list