I tried to compile the following code:
#include <iostream>
#include <algorithm>
template<std::size_t N>
struct StaticString {
constexpr StaticString(const char (&str)[N]){
std::copy(str, str + N, value);
}
constexpr static std::size_t size() {
return N;
}
constexpr auto name() const {
return value;
}
char value[N];
};
template<StaticString TName = "">
struct Launcher {
constexpr auto name(){
return TName.value;
}
static std::size_t size(){
return TName.size();
}
};
int main(int argc, char **argv){
std::cout << Launcher{}.size() << "\n";
std::cout << Launcher<"">{}.size() << "\n";
std::cout << Launcher<"Kernel">{}.size() << "\n";
return 0;
}
I get the following error message:
$ nvcc -std=c++20 reproducer.cu -o rep_nvcc
nvcc warning : Support for offline compilation for architectures prior to '<compute/sm/lto>_75' will be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
reproducer.cu(25): error: expression must have class type but it has type "const char *"
return TName.size();
^
detected during instantiation of "std::size_t Launcher<TName>::size() [with TName=""]" at line 30
1 error detected in the compilation of "reproducer.cu".
The error is produced by the line std::cout << Launcher{}.size() << "\n";
. If I remove it, it works. Looks like it deduce TName
false and the compiler think it has the type of an C-String instead the StaticString
. The code works with g++ 14.1 and clang 17.1. Also if I compile the file with file extension .cpp
instead .cu
. So it looks like the splitter pass wrong code to the host compiler.
I used nvcc V12.8.61 and g++ 14.1. The compile command is nvcc -std=c++20 reproducer.cu
.