Skip to content

[BUG]: Compilation failure with GCC 10.2 on pybind11 2.13.0 (typing.h, line 209) #5201

Closed
@zhqrbitee

Description

@zhqrbitee

Required prerequisites

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

2.13.0

Problem description

Environment:

Compiler: GCC 10.2
C++ Language Dialect: C++20 (std=c++20)

Error Message:

In file included from my_venv/include/pybind11/pybind11.h:19,
                 from my_venv/include/pybind11/numpy.h:12
my_venv/include/pybind11/typing.h:219:49: error: class template argument deduction failed:
  219 | struct handle_type_name<typing::Literal<Literals...>> {
      |                                                 ^~~
compilation terminated due to -Wfatal-errors.

It seems the error just comes from including pybind11 headers and it comes after upgrading to 2.13.

#if defined(__cpp_nontype_template_parameter_class)
template <typing::StringLiteral... Literals>
struct handle_type_name<typing::Literal<Literals...>> {
    static constexpr auto name = const_name("Literal[")
                                 + pybind11::detail::concat(const_name(Literals.name)...)
                                 + const_name("]");
};
template <typing::StringLiteral StrLit>
struct handle_type_name<typing::TypeVar<StrLit>> {
    static constexpr auto name = const_name(StrLit.name);
};
#endif

I see it tries to use the macro __cpp_nontype_template_parameter_class to enable some template codes. However not sure why the macro check is success, but GCC 10.2 fails to compile the codes.

Reproducible example code

No response

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

2.12.0

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