Conflict between namespace and non-namespace function definitions
14:39 20 Jan 2026

In a header of an external library I'm using there is a definition of the lerp function as follows:

SUTIL_INLINE SUTIL_HOSTDEVICE float lerp(const float a, const float b, const float t)
{
  return a + t*(b-a);
}

When compiling with GCC 15.2.1 and -std=c++20 I get the following error:

In file included from /home/mori/software/KM3/eic-opticks/sysrap/sphoton.h:183,
                 from /home/mori/software/KM3/eic-opticks/sysrap/storch.h:37,
                 from /home/mori/software/KM3/eic-opticks/src/config.h:8,
                 from /home/mori/software/KM3/eic-opticks/src/config.cpp:14:
/home/mori/software/KM3/eic-opticks/sysrap/scuda.h:130:85: error: 'float lerp(float, float, float)' conflicts with a previous declaration
  130 | SUTIL_INLINE SUTIL_HOSTDEVICE float lerp(const float a, const float b, const float t)
      |                                                                                     ^
In file included from /usr/include/c++/15.2.1/valarray:41,
                 from /home/mori/software/install/cpp20/NLOHMANNJSON_v3.11.3/include/nlohmann/detail/conversions/from_json.hpp:21,
                 from /home/mori/software/install/cpp20/NLOHMANNJSON_v3.11.3/include/nlohmann/adl_serializer.hpp:14,
                 from /home/mori/software/install/cpp20/NLOHMANNJSON_v3.11.3/include/nlohmann/json.hpp:34,
                 from /home/mori/software/KM3/eic-opticks/src/config.cpp:9:
/usr/include/c++/15.2.1/cmath:3857:3: note: previous declaration 'constexpr float std::lerp(float, float, float)'
 3857 |   lerp(float __a, float __b, float __t) noexcept
      |   ^~~~

From what I understand there is a conflict with std::lerp, which is defined in the standard cmath header under the std:: namespace and guarded as:

#ifdef __cpp_lib_interpolate // C++ >= 20
  // linear interpolation

   . . .

  constexpr float
  lerp(float __a, float __b, float __t) noexcept
  { return std::__lerp(__a, __b, __t); }

so that it is available only with C++20 (and actually compiling with C++17 the error vanishes).

What I don't understand here is why a function in the global namespace conflicts with another in the std:: namespace, even in the same translation unit. I need to compile with C++20 so any help/insight would be appreciated.

c++