Hi everyone,
I have observed some inconsistent behaviour when compiling code with variable length arrays using nvc++ (HPC SDK 25.1).
All of the examples below are not standard cpp conform, since all of these use a variable length arrays allocated on the stack. Although, some of the examples compile without any error and some produce an internal compiler error. My expectation would be a warning or an error in all cases.
The following code generates an internal compiler error:
#include <complex>
std::complex<float> foo(size_t l) {
std::complex<float> arr[l] = {};
return arr[0];
}
int main() {
foo(42);
return 0;
}
[build] NVC++-F-0000-Internal Compiler Error. process_sptr(): unexpected storage type
A modified version of foo compiles without any errors:
std::complex<float> foo(size_t l) {
std::complex<float> arr[l]; // removed = {};
return arr[0];
}
Primitive data types seem to compile without any errors as well:
int foo(size_t l) {
int arr[l] = {};
return arr[0];
}
In comparison, gcc compiles all examples but always generates a warning ISO C++ forbids variable length array
. Some similar message from nvc++ would be great.
Best regards
Josh