userver-framework / userver

Production-ready C++ Asynchronous Framework with rich functionality
https://userver.tech
Apache License 2.0
2.38k stars 276 forks source link

Double template instantiation of `struct convert<std::string_view>` #371

Closed rtkid-nik closed 1 year ago

rtkid-nik commented 1 year ago

Error

string_view_support.hpp:11:8 error: redefinition of 'convert<std::string_view>'
struct convert<std::string_view> {
       ^~~~~~~~~~~~~~~~~~~~~~~~~
/opt/homebrew/include/yaml-cpp/node/convert.h:98:8: note: previous definition is here
struct convert<std::string_view> {

yaml-cpp

#if __cplusplus >= 201703L
template <>
struct convert<std::string_view> {
  static Node encode(std::string_view rhs) { return Node(std::string(rhs)); }

  static bool decode(const Node& node, std::string_view& rhs) {
    if (!node.IsScalar())
      return false;
    rhs = node.Scalar();
    return true;
  }
};
#endif

userver

template <>
struct convert<std::string_view> {
  static Node encode(const std::string_view& rhs) {
    return Node(std::string{rhs});
  }

  static bool decode(const Node& node, std::string_view& rhs) {
    if (!node.IsScalar()) return false;
    rhs = node.Scalar();
    return true;
  }
};

Solution: remove from userver template instantiation or add #if __cplusplus < 201703L

apolukhin commented 1 year ago

Many thanks for the bug report!