pybind / pybind/pybind11

[BUG]: trying to catch a py::type_error makes the compilation crash with Clang on Windows

Open
#3,746 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Required prerequisites
Problem description

The compiler Clang v13.0.0 craches at the linking step on Windows when add to following line to my code :

 try {
    auto casted_values = py::cast<std::vector<int32_t>>(values); // Here values is a py::list&.
  } catch (const py::cast_error& e) {
    throw py::type_error("this method expects integers as param");
  }

The error is :

LLVM ERROR: Associative COMDAT symbol '??0builtin_exception@pybind11@@QEAA@PEBD@Z' does not exist.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.

The strange thing is that if I recompile the same code but keep the CMake cache, it works. 🤔
It also works perfectly under Linux with CGG.

Does anyone have an explanation for this?

EDIT : It seems that the problem comes from the try catch but I have no idea why.

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

Reproduce the sample try/catch with Clang 13.0.0 on Windows and inspect the linker error for builtin_exception. Compare a clean CMake configuration with a rebuild that keeps the CMake cache, then determine whether the py::cast_error handling consistently triggers the crash and document the cause or a verified workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.