[PATCH] D156565: Diagnose use of VLAs in C++ by default

Tom Honermann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 3 07:38:42 PDT 2023


tahonermann added inline comments.


================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:147-149
+def ext_vla_cxx_static_assert : ExtWarn<
+  "variable length arrays in C++ are a Clang extension; did you mean to use "
+  "'static_assert'?">, InGroup<VLAUseStaticAssert>;
----------------
aaron.ballman wrote:
> tahonermann wrote:
> > I find the "did you mean to use 'static_assert'" phrasing awkward here since it is highly unlikely that someone intended to write `static_assert(x)` and instead wrote `int my_assert[x ? 1 : -1]`. Perhaps something like this?
> > 
> > "variable length arrays in C++ are a Clang extension; 'static_assert' can be used in this case".
> Eh, I'm on the fence. We're consistent about asking users "did you mean X?" in our diagnostics and this follows the same pattern. "Did you mean to use X" is not "is this a typo for X?" but "were you aware you could do X instead?" So yeah, the wording is a bit awkward, but it's consistent with other diagnostics and not really wrong either. Do you have strong feelings?
No, I don't have strong feelings on this.

I did recognize use of the widely used "did you mean" pattern, but my impression with those has been that they are generally employed in situations where similar syntax is involved (e.g., misspelled name, `.` vs `->`, `return` vs `co_return`, etc...) or where there might be some missing syntax (e.g., `()` following a function name or a missing `;`); cases where the programmer is likely to response "oh, yes I did!". This feels different since it is suggesting use of a distinct feature.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156565/new/

https://reviews.llvm.org/D156565



More information about the cfe-commits mailing list