C++20 user defined literals in nvcc 12.0 bug

Using user-defined literal in C++20 form results in next error:

❯ cat main.cu
template <std::size_t N> struct fixed_string {
  constexpr fixed_string(const char *) {
  }
};

template <fixed_string Str> constexpr auto operator""_a();


int main ()
{
    return 0;
}
❯ nvcc --std=c++20 main.cu
main.cu(6): error: a literal operator template must have a template parameter list equivalent to "<char ...>"

1 error detected in the compilation of "main.cu".
❯ ln -s main.cu main.cpp
❯ g++ --std=c++20 main.cpp
❯ echo $?
0
❯ clang++ --std=c++20 main.cpp
❯ echo $?
0

While g++ and clang++ succeeds.
Same problem occurs compiling spdlog/fmtlib (1.11.0 / 9.1.0) in .cu files.

Compiler info
❯ g++ --version
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

❯ clang++ --version
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
❯ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Mon_Oct_24_19:12:58_PDT_2022
Cuda compilation tools, release 12.0, V12.0.76
Build cuda_12.0.r12.0/compiler.31968024_0
2 Likes

Same issue with nvc++ 22.11 Compiler Explorer

The issue will be fixed in a future CUDA 12.x version . Thanks for reporting this !

Is there any status on the progress of this fix?

As of January 20, 2023, the current version is 12.1. As I can say, the bug persists.

CUDA 12.2 also does not fix this issue.

2 Likes

This reported issue should be fixed in 12.2 . If any new failure you still see with latest CUDA version . Please file a bug ticket referring to the pinned topics of this forum sub entry .

yni@node2:~/yni/Customerbug/3955782$ /usr/local/cuda-12.2/bin/nvcc -x cu main.cu  --std=c++20
yni@node2:~/yni/Customerbug/3955782$ 
yni@node2:~/yni/Customerbug/3955782$ cat main.cu 
template <std::size_t N> struct fixed_string {
  constexpr fixed_string(const char *) {
  }
};

template <fixed_string Str> constexpr auto operator""_a();


int main ()
{
    return 0;
}
yni@node2:~/yni/Customerbug/3955782$ /usr/local/cuda-12.2/bin/nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Jul_11_02:20:44_PDT_2023
Cuda compilation tools, release 12.2, V12.2.128
Build cuda_12.2.r12.2/compiler.33053471_0
yni@node2:~/yni/Customerbug/3955782$ 

Yea looks like this works. FMT however is still very broken and cannot be used by nvcc in c++20 mode.