nvcc bug: Variable template arithmetics in class scope triggers nvcc internal error

I suspect this is a nvcc bug. Consider the following:

#include <cstdio>

struct A {
  static constexpr std::size_t rank = 3;
  static constexpr std::size_t rank_dynamic = 2;
struct B {
  static constexpr std::size_t rank = 2;
  static constexpr std::size_t rank_dynamic = 1;

struct C {

  template < class T >
  static constexpr std::size_t rank = T::rank;

  template < class T >
  static constexpr std::size_t rank_dynamic = T::rank_dynamic;

  template < class T >
  static constexpr std::size_t rankStatic = rank<T> - rank_dynamic<T>;


template < class T >
constexpr std::size_t C::rank;

template < class T >
constexpr std::size_t C::rank_dynamic;

template < class T >
constexpr std::size_t C::rankStatic;

int main(int argc, char* argv[]) {

This compiles and runs fine with gcc or clang that supports c++14. But nvcc test.cpp -o test -x cu -std=c++14 triggers:

../test.cpp(21): internal error: assertion failed at: "/dvs/p4/build/sw/rel/gpu_drv/r396/r396_00/drivers/compiler/edg/EDG_4.14/src/class_decl.c", line 3919

1 catastrophic error detected in the compilation of "/tmp/tmpxft_000204b9_00000000-4_test.cpp4.ii".
Compilation aborted.
nvcc error   : 'cudafe++' died due to signal 6 
nvcc error   : 'cudafe++' core dumped

This is legit non-odr use of variable template as static member of a class. I’d suggest add support for this feature.

Replacing line 21 with

static constexpr std::size_t rankStatic = T::rank - T::rank_dynamic;

would work. I’m guessing that nvcc fails to replace the two variable templates with literal in this case.

Internal errors should never happen. I would suggest filing a bug report with NVIDIA at the registered developer website:


Thanks for reporting it. I’m able to reproduce the issue and have filed an internal bug at NVIDIA. You’re welcome to file your own bug of course. I don’t have any further information at this time.

Thank you for reporting the bug. Is there a link to the bug report you file for me to keep track of it?

In order to keep information in bug reports confidential, NVIDIA’s bug reporting systems limits access to bug reports to the filer and relevant NVIDIA personnel.

If you would like to track progress on the resolution of this issue, you would want to file your own bug.

Hi Robert, could you tell me if the latest CUDA 10 release has a fix for this issue?

As far as I know, the fix is not in CUDA 10.0. I believe it should be in the next public numbered release after CUDA 10.0