C++20's source_location compilation error when using NVCC 12.1

Ran into the same problem, was able to work around it at least for host code. Might also work for device code, but I didn’t look into that.

// workaround cuda compiler bug #4173735.
// https://forums.developer.nvidia.com/t/c-20s-source-location-compilation-error-when-using-nvcc-12-1/258026
#ifdef __CUDACC__
#pragma push_macro("__cpp_consteval")
#pragma push_macro("_NODISCARD")
#pragma push_macro("__builtin_LINE")

#define __cpp_consteval 201811L

#ifdef _NODISCARD
    #undef _NODISCARD
    #define _NODISCARD
#endif

#define consteval constexpr

#include <source_location>

#undef consteval
#pragma pop_macro("__cpp_consteval")
#pragma pop_macro("_NODISCARD")
#else
#include <source_location>
#endif

The source_location as implemented in MSVC uses the new C++20 consteval specifier to construct the current location at compile time but it doesn’t seem require it correctness, might just be a performance optimisation.