Skip to content

[BUG]: call of overloaded ‘str(const pybind11::kwargs&)’ is ambiguous #5938

@axxel

Description

@axxel

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

3.0.1

Problem description

void test(const py::kwargs& kwargs)
{
	auto s = py::str(kwargs);
}

fails to compile with gcc with the following (condensed) error:

error: call of overloaded ‘str(const pybind11::kwargs&)’ is ambiguous
  200 |         auto s = py::str(kwargs);
      |                                ^
note: candidate: ‘pybind11::str::str(pybind11::handle)’
 1644 |     explicit str(handle h) : object(raw_str(h.ptr()), stolen_t{}) {
      |              ^~~
note: candidate: ‘pybind11::str::str(const pybind11::bytes&)’
 1774 | inline str::str(const bytes &b) {
      |        ^~~
note: candidate: ‘pybind11::str::str(const pybind11::object&)’
 1596 |     PYBIND11_OBJECT_CVT(str, object, PYBIND11_STR_CHECK_FUN, raw_str)
      |     ^~~~~~~~~~~~~~~~~~~
note: candidate: ‘pybind11::str::str(const pybind11::str&)’
 1594 | class str : public object {
      |       ^~~
note: candidate: ‘pybind11::str::str(pybind11::str&&)’

This fails with at least g++-12 and g++-13 while it works with at least clang-17 and clang-18.

Any suggestion for a specific cast to work around the issue?

Reproducible example code

#include <pybind11/pybind11.h>
namespace py = pybind11;

void test(const py::kwargs& kwargs)
{
	auto s = py::str(kwargs);
}

Is this a regression? Put the last known working version here if it is.

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions