Hi,
I have encountered an error while using source_location. Here is an simple example:
#include <iostream>
#include <source_location>
void printSourceLocation()
{
auto location = std::source_location::current();
std::cout << "FileName: " << location.file_name() << std::endl;
}
int main()
{
printSourceLocation();
}
When compiling with GCC 11.3 or 12.1 I get this error:
$ nvcc -ccbin g++ -std=c++20 test.cu -o test
test.cu(6): error: call to consteval function "std::source_location::current" did not produce a valid constant expression
auto location = std::source_location::current();
^
/usr/include/c++/12/source_location(59): note #2703-D: cannot call non-constexpr function "__builtin_source_location" (declared implicitly)
current(__builtin_ret_type __p = __builtin_source_location()) noexcept
^
1 error detected in the compilation of "test.cu".
Similarly when using Clang 15:
$ nvcc -ccbin clang++-15 -std=c++20 test.cu -o test
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/source_location(53): error: identifier "__builtin_source_location" is undefined
using __builtin_ret_type = decltype(__builtin_source_location());
^
1 error detected in the compilation of "test.cu".
Same story with NVC++. When not using NVCC, all compilers have no problem with this code.
Thanks.
David