Skip to content

Avoid assert due to implicit narrowing cast on 32 bit architectures

Mattias Ellert requested to merge ellert/HepMC3:implicit-narrowing into master

Build failure on ix32:

In file included from /builddir/build/BUILD/HepMC3-3.3.0/python/A/../include/pybind11/detail/../attr.h:13,
                 from /builddir/build/BUILD/HepMC3-3.3.0/python/A/../include/pybind11/detail/class.h:12,
                 from /builddir/build/BUILD/HepMC3-3.3.0/python/A/../include/pybind11/pybind11.h:13,
                 from /builddir/build/BUILD/HepMC3-3.3.0/python/src/binders.h:12,
                 from /builddir/build/BUILD/HepMC3-3.3.0/python/src/binders.cpp:1:
/builddir/build/BUILD/HepMC3-3.3.0/python/A/../include/pybind11/detail/../detail/common.h: In instantiation of ‘pybind11::ssize_t pybind11::ssize_t_cast(const IntType&) [with IntType = long long int; ssize_t = int]’:
/builddir/build/BUILD/HepMC3-3.3.0/python/A/../include/pybind11/detail/../detail/../pytypes.h:1651:69:   required from ‘pybind11::bytes::bytes(const char*, const SzType&) [with SzType = long long int; typename std::enable_if<std::is_integral<_Tp>::value, int>::type <anonymous> = 0]’
 1651 |         : object(PYBIND11_BYTES_FROM_STRING_AND_SIZE(c, ssize_t_cast(n)), stolen_t{}) {
      |                                                         ~~~~~~~~~~~~^~~
/builddir/build/BUILD/HepMC3-3.3.0/python/src/pystreambuf.h:269:41:   required from here
  269 |       py::bytes chunk(pbase(), n_written);
      |                                         ^
/builddir/build/BUILD/HepMC3-3.3.0/python/A/../include/pybind11/detail/../detail/common.h:492:35: error: static assertion failed: Implicit narrowing is not permitted.
  492 |     static_assert(sizeof(IntType) <= sizeof(ssize_t), "Implicit narrowing is not permitted.");
      |                   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/HepMC3-3.3.0/python/A/../include/pybind11/detail/../detail/common.h:492:35: note: the comparison reduces to ‘(8 <= 4)’

The variable name py_n_written was chosen to match the name py_n_read used earlier in the file.

Is there an upstream for this file that should be notified?

Merge request reports

Loading