fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
20.43k stars 2.45k forks source link

Error when using cuda 12.1 in c++20 mode #3394

Closed SadiinsoSnowfall closed 1 year ago

SadiinsoSnowfall commented 1 year ago

Hi, I have some troubles compiling fmtlib with CudaToolkit 12.1 using C++20

Even with a simple hello world I get the following error:

include/fmt/format.h(4600): error: a literal operator template must have a template parameter list equivalent to "<char ...>"
  template <detail_exported::fixed_string Str> constexpr auto operator""_a() {
                                                              ^

The error points to the following snippet :

#  if FMT_USE_NONTYPE_TEMPLATE_ARGS
template <detail_exported::fixed_string Str> constexpr auto operator""_a() {
  using char_t = remove_cvref_t<decltype(Str.data[0])>;
  return detail::udl_arg<char_t, sizeof(Str.data) / sizeof(char_t), Str>();
}
#  else
constexpr auto operator"" _a(const char* s, size_t) -> detail::udl_arg<char> {
  return {s};
}
#  endif

I tried forcing the FMT_USE_NONTYPE_TEMPLATE_ARGS to be disable, but I then got the following error:

include/fmt/core.h: In function ‘constexpr bool fmt::v9::detail::is_constant_evaluated(bool)’:
include/fmt/core.h:315:14: error: call to non-‘constexpr’ function ‘void fmt::v9::detail::ignore_unused(const T& ...) [with T = {bool}]’
  315 |   ignore_unused(default_value);

Fmtlib does compile when using the C++17 mode, so this problem only affects cuda 12 if using -std=c++20

PS: nvcc version:

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Feb__7_19:32:13_PST_2023
Cuda compilation tools, release 12.1, V12.1.66
Build cuda_12.1.r12.1/compiler.32415258_0
vitaut commented 1 year ago

Looks like a bug in the cuda compiler, please report to NVIDIA. A PR with a workaround would be welcome too.

jwmelto commented 11 months ago

https://forums.developer.nvidia.com/t/c-20-user-defined-literals-in-nvcc-12-0-bug/240367/3