Skip to content

C++17 Build Fails Due to Ambiguous std::variant Function Calls #120

@FaresChernii

Description

@FaresChernii

Description

When building the gopher-mcp library with C++17 (or higher) enabled via -DCMAKE_CXX_STANDARD=17, compilation fails due to ambiguous function calls for holds_alternative and get. This occurs because the library enables the std::variant code path (via MCP_USE_STD_OPTIONAL_VARIANT=1), but the compatibility wrappers in include/mcp/core/compat.h conflict with the standard library versions from <variant>.The errors appear in src/transport/ssl_context.cc (and potentially other files using variant types).

Environment

  • OS: macOS (using AppleClang)
  • C++ Standard: C++17
  • CMake Version: 4.x
  • Compiler: AppleClang (Xcode Command Line Tools)

Steps to Reproduce

  1. Configure with C++17:
cmake -B build \
  -DCMAKE_INSTALL_PREFIX=/opt/gopher-mcp \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_C_API=OFF \
  -DBUILD_STATIC_LIBS=OFF \
  -DCMAKE_CXX_STANDARD=17
  1. Build:
cmake --build . -j4

Error Output

/path/to/gopher-mcp/src/transport/ssl_context.cc:81:7: error: call to 'holds_alternative' is ambiguous
   81 |   if (holds_alternative<Error>(result)) {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/variant:1336:38: note: candidate function [with _Tp = mcp::Error, _Types = <std::nullptr_t, mcp::Error>]
 1336 | _LIBCPP_HIDE_FROM_ABI constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
      |                                      ^
/path/to/gopher-mcp/include/mcp/core/compat.h:109:16: note: candidate function [with T = mcp::Error, Types = <std::nullptr_t, mcp::Error>]
  109 | constexpr bool holds_alternative(const variant<Types...>& v) noexcept {
      |                ^

(Similar errors occur for get and multiple locations in ssl_context.cc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions