CUDA 11.2 issue - NVCC compiler segfault

Hello,

Through debugging a larger codebase, I have discovered an issue which causes nvcc version 11.2 to encounter a segmentation fault while compiling. nvcc version 10.0 can compile the code successfully without any issues.

main.cu:

#include <iostream>
#include "templateHeader.h"

int main() {
    std::cout << "Test Program" << std::endl;
    return 0;
}

templateHeader.h:

#ifndef TEMPLATE_HEADER
#define TEMPLATE_HEADER

template<int offset> 
class ParentTemplateClass {
    static constexpr int parentTestStaticInt = 0;
};

template<int offset>
class ChildTemplateClass : public ParentTemplateClass<offset+1> {
public:
    static constexpr int childTestStaticInt = 1+ParentTemplateClass<offset+ChildTemplateClass::childTestStaticInt>::parentTestStaticInt;
};

#endif

The problem seems to be that childTestStaticInt is defined recursively in terms of itself. Obviously, this doesn’t really make any sense. However, I believe that the compiler should not segfault as a result.

Your code compiles cleanly for me on CUDA 11.3. I suggest moving forward to a newer CUDA version.

$ cat t141.cu
#include <iostream>
template<int offset>
class ParentTemplateClass {
     static constexpr int parentTestStaticInt = 0;
};

template<int offset>
class ChildTemplateClass : public ParentTemplateClass<offset+1> {
 public:
      static constexpr int childTestStaticInt = 1+ParentTemplateClass<offset+ChildTemplateClass::childTestStaticInt>::parentTestStaticInt;
};
int main() {
     std::cout << "Test Program" << std::endl;
         return 0;
}
$ nvcc -o t141 t141.cu
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0
$

(I don’t have CUDA 11.2 handy, but I can reproduce a seg fault on CUDA 11.1)

Thank you Robert. I can confirm that CUDA 11.3 compiles the code, as well as the larger codebase. Thanks for your help.