pybind / pybind/pybind11

[BUG]: error: static assertion failed: char should be cast to either signed char or unsigned char

Open
#4,938 1 comment 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.11.1

Problem description

I'm trying to compile pybind11 tests and compilatoin fails here:

pybind11-2.11.1/tests/test_enum.cpp:95:16: error: static assertion failed: char should be cast to either signed char or unsigned char
   92 |         py::detail::any_of<
      |         ~~~~~~~~~~~~~~~~~~~
   93 |             std::is_same<py::enum_<ScopedCharEnum>::Scalar, signed char>,  // e.g. gcc on x86
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   94 |             std::is_same<py::enum_<ScopedCharEnum>::Scalar, unsigned char> // e.g. arm linux
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   95 |             >::value,
      |             ~~~^~~~~

I think the assertion is wrong since char, unsigned char and signed char are three distinct types.

Reference:
https://en.cppreference.com/w/cpp/language/types
https://stackoverflow.com/questions/2054939/is-char-signed-or-unsigned-by-default

Reproducible example code

No response

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

Not a regression

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 in tests/test_enum.cpp around line 95 and inspect the static assertion for py::enum_::Scalar. Reproduce the test compilation failure, then verify the assertion against the distinct char types described in the issue; done means the tests compile without that failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.