3

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.
  • 2
    Have you tried with the `-std=c++2a` or `-std=c++20` flags, instead of `-std=gnu++20`? Alternatively, assuming it's an issue with incomplete or incorrect C++20 support in nvc, I can provide an equivalent that works under C++17 standards. – Adrian Mole Jun 21 '22 at 12:25
  • @AdrianMole No, the most likely cause is that Ubuntu 22.04 is not supported. In the past i had a very similar issue where the ubuntu version that i was using was not supported. Additionally, in the list linked in my answer it is mentioned that C++20 is supported but Ubuntu 22.04 is not. – Jason Jun 21 '22 at 12:33
  • Thank you very much for your reply. Unfortunately, the alternative compilation flags did not help. I guess that C++20 is not fully supported by nvc at the moment---at least that is the only thing I can imagine right now. It will be great if the same result can be achieved using C++17 only! – Andreas Rupp Jun 25 '22 at 20:01
  • You are right, the [NVC documentation](https://docs.nvidia.com/hpc-sdk/compilers/hpc-compilers-user-guide/index.html) also says it only supports C++17. You can @ people like @AdrianMole to notify them of a response, by default only the author of the question or answer is notified. – sigma Jun 26 '22 at 19:07
  • Thank you, sigma for your remark. Also, thank you @AdrianMole for the comment. It appears to underline the reason. – Andreas Rupp Jun 27 '22 at 20:28
  • Like I said, I *can* provide code that works with the C++17 Standard. However, it would only address the issue(s) posted in your given example, and *may* not be applicable more widely. If you edit your Q to be more specific, I can (maybe) post a helpful(?) answer. (Also, I'm not entirely sure that I can properly explain *why* it would work in C++17, but that your code requires C++20.) – Adrian Mole Jun 27 '22 at 20:37
  • I have the same issue where I tried compiling code using on `boost::hana::filter`. Their code should be C++14, but it yields the exact same error. I highly recommend posting the issue in [their forum](https://forums.developer.nvidia.com/c/accelerated-computing/hpc-compilers/299) which I haven't done as I missed a MRE. – Uchendu Jun 30 '22 at 22:34
  • @AdrianMole Thank you very much! Unfortunately, the program throws many similar errors (in different locations). This is just a significantly simplified example. Thus, I fear that it will be most economic to wait for nvc++ to support C++20. – Andreas Rupp Jul 06 '22 at 08:56

0 Answers0