pybind / pybind/pybind11

[BUG]: XCode compilation error in pybind11 v12.2.0 (pybind11.h, line 1145)

Open
#5,114 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

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

2.12.0

Problem description

Environment:

Xcode Version: 15.3
Compiler: Apple clang (default)
C++ Language Dialect: C++17 (std=c++17)
Description:

A compilation error occurs when using pybind11 version 12.2.0. The error originates from line 1145 of pybind11.h. There is no issue in 2.11.1 and before.

Error Message:

Loop variable 'kwarg' binds to a temporary value produced by a range of type 'pybind11::dict'

Code Snippet:

static PyObject *dispatcher(PyObject *self, PyObject *args_in, PyObject *kwargs_in) {
...
                    for (const auto &kwarg : kwargs) { // Compiler error (line 1145 of pybind11.h)
                        if (first) {
                            first = false;
                        } else {
                            msg += ", ";
                        }
                        msg += pybind11::str("{}=").format(kwarg.first);
                        try {
                            msg += pybind11::repr(kwarg.second);
                        } catch (const error_already_set &) {
                            msg += "<repr raised Error>";
                        }
                    }
...
}
Reproducible example code

No response

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

2.11.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at pybind11.h line 1145 and reproduce the reported diagnostic with Xcode 15.3, Apple clang, and C++17. Compare the behavior with pybind11 2.11.1, then verify that the kwargs formatting path compiles and retains the shown message-building behavior in 2.12.0.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.