nvc++ yields "error: expression must have a constant value" while g++ and clang++ do not

Viewed 100

I am writing some software (C++20) in which many things are evaluated during compile time. Using g++ (version > 9) or clang++ (version > 10) the software compiles just fine on Ubuntu 22.04. However, when trying to compile it using nvc++ (version 22.5-0) I receive several identical errors.

A minimal code example is a file test.cxx containing

#include <array>
#include <iostream>

static constexpr std::array<std::array<double, 7>, 5> make_array()
{
  std::array<std::array<double, 7>, 5> result;

  for (unsigned int fct = 0; fct < 5; ++fct)
    for (unsigned int pt = 0; pt < 7; ++pt)
      result[fct][pt] = 2.;

  return result;
}

static constexpr std::array<std::array<double, 7>, 5> const_array = make_array();

int main()
{
  std::cout << const_array[3][4] << std::endl;
  return 0;
}

Running g++-10 -std=gnu++20 test.cxx -o test; ./test gives an output 2, and clang++-11 -std=gnu++20 test.cxx -o test; ./test also yields 2. However, using nvc++ -std=gnu++20 test.cxx -o test; ./test with nvc++ version 22.5-0 yields

"test.cxx", line 15: error: expression must have a constant value
  static constexpr std::array<std::array<double, 7>, 5> const_array = make_array();
                                                                      ^
"test.cxx", line 12: note: access to uninitialized object
    return result;
           ^

Why does it not compile using nvc++ and can one fix this somehow?

UPDATES:

  • I have tested the very same setup on Ubuntu 20.04, and observed the same errors.
  • I have tried the compile flags -std=c++2a and -std=c++20, and observed the same errors.
0 Answers
Related