Open
Description
src/transformer.cpp:48:20: error: variable length arra
ys in C++ are a Clang extension [-Werror,-Wvla-cxx-ext
ension]
┆48 | int buffer[spec.headerSize];
┆ ┆ | ^~~~~~~~~~~~~~~
src/transformer.cpp:48:20: note: read of non-constexpr
variable 'spec' is not allowed in a constant expressi
on
src/transformer.cpp:13:21: note: declared here
┆13 | TransformerSpec spec;
┆ ┆ | ^
1 error generated.
Description
Currently, the code uses a variable length array (VLA) in C++:
int buffer[spec.headerSize];
However, VLAs are not part of the C++ standard and are only supported as a Clang extension. This causes compilation errors with -Werror,-Wvla-cxx-extension enabled.
To ensure portability and compliance with the C++ standard, we should replace VLAs with a more standard-compliant approach, such as:
std::vector
std::unique_ptr<int[]>
A fixed-size array with a maximum limit
Steps to Reproduce
-
Compile the code with Clang and -Werror,-Wvla-cxx-extension enabled.
-
Observe the compilation failure due to the use of a variable length array.
Expected Behavior
The code should compile without relying on Clang-specific extensions.
Proposed Fix
Replace VLAs with a dynamic allocation approach like std::vector.
Metadata
Assignees
Labels
No labels