[clang] [clang] Improve diagnostics with incompatible VLA types (PR #101261)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 28 11:53:46 PDT 2024


================
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void func(int n) {
+    int grp[n][n];
+    int (*ptr)[n];
+
+    for (int i = 0; i < n; i++)
+        ptr = &grp[i]; // expected-error {{incompatible pointer types assigning to 'int (*)[n]' from 'int (*)[n]'; VLA types differ despite using the same array size expression}}
----------------
AaronBallman wrote:

Some other good tests to add would be:
```
void func(int n, int (&array)[n]) {
  int (&other)[n] = array;
}

template <typename T>
void foo(T &, T &);

void bar(int n) {
  int array[n];
  int other[n];
  foo(array, other);
}

void quux(int n) {
  int (*array)[n];
  int (*array)[n];
}
```
there are probably other good test cases to add (take a look for `%diff` in `DiagnosticSemaKinds.td` for inspiration), if you want to try for more.

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


More information about the cfe-commits mailing list