-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix clang vla problems #3281
Fix clang vla problems #3281
Conversation
Remove variable length array (unsupported in C++).
Handle case when no components are found.
…ng argument. Remove variable length array (unsupported in C++).
Add safeguard against zero (or negative) length array allocation.
IMO in 2025 it is a bug to use naked "new" in C++. Isn't it possible to use std::unique_ptr and std::make_unique? something like |
You are probably right. However std::vector is unlikely to work considering the way the rest of the code works. I will look into the alternatives. |
std::vector always allocates a contiguous array, it is kind of auto-resizing dynamic array. when constructing with size it should do only one allocation. So it should be possible to get the pointer to first element and leave the code more or less unchanged. I will take a look. Better solution would be something like dynamic std::array, but that doesn't seem to exist in standard C++. Maybe std::valarray? Sometime in the future. We should put comment there why it's done like that, sometime in the future either val arrays will come to C++ or prober stack-allocated std::array with at-construction size (vs. at-compile size as it is now). |
Yes, but I was thinking about string handling, not generic arrays. There you need the terminating NUL for C-string compatibility. Luckily, the string class keeps the array NUL terminated since C++11. Anyway, it should now be resolved with the commit. Please review. |
I like that much better, LGTM. |
Variable length arrays (vla) are a feature of C and are not in the C++ standard. Both gcc and clang have fixes for this, but they remain non-standard and result in a warning in clang.
This PR removes the use of vla and replaces it with new[]/delete[]. This is all non-RT code, so that is no problem. In the process it uncovered some subtle and less subtle problems in the code: