pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

[BUG]: Errors in VS 2022 and c++ 20

Open AhmedZero opened this issue 3 years ago • 5 comments

Required prerequisites

  • [X] Make sure you've read the documentation. Your issue may be addressed there.
  • [X] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
  • [X] Consider asking first in the Gitter chat room or in a Discussion.

Problem description

when i build with pybind11, it failed to build i use Visual Studio 2022 and C++ 20

##Errors

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2678	binary '-': no operator found which takes a left-hand operand of type 'const L' (or there is no acceptable conversion)	VTIL-Python	J:\My_Projects\VTIL-Python\external\pybind11\include\pybind11\operators.h	115	
Error	C2672	'pybind11::class_<vtil::symbolic::directive::instance>::def': no matching overloaded function found	VTIL-Python	J:\My_Projects\VTIL-Python\external\pybind11\include\pybind11\operators.h	52	
Error	C2893	Failed to specialize function template 'pybind11::class_<vtil::symbolic::directive::instance> &pybind11::class_<vtil::symbolic::directive::instance>::def(const char *,Func &&,const Extra &...)'	VTIL-Python	J:\My_Projects\VTIL-Python\external\pybind11\include\pybind11\operators.h	47	
Error	C2678	binary '*': no operator found which takes a left-hand operand of type 'const L' (or there is no acceptable conversion)	VTIL-Python	J:\My_Projects\VTIL-Python\external\pybind11\include\pybind11\operators.h	117	
Error	C2088	'*': illegal for struct	VTIL-Python	J:\My_Projects\VTIL-Python\external\pybind11\include\pybind11\operators.h	117	

Reproducible example code

No response

AhmedZero avatar Mar 24 '22 13:03 AhmedZero

Reproducible example code No response

Could you please provide one, ideally in a PR? Without we have to spend a lot of time guessing. We have CI coverage for MSVC 2022 C++20, e.g. (random recent example): https://github.com/pybind/pybind11/runs/5681914694?check_suite_focus=true So all we need is a reproducer.

rwgk avatar Mar 24 '22 19:03 rwgk

do you mean that? https://github.com/AhmedZero/VTIL-Python/runs/5684580465?check_suite_focus=true

AhmedZero avatar Mar 24 '22 23:03 AhmedZero

That's a haystack. What we need is the needle.

rwgk avatar Mar 24 '22 23:03 rwgk

the build is succeeded when I comment on those lines. https://github.com/AhmedZero/VTIL-Python/commit/f551cff3855dc1b8f2b7bf22e24f15e23c243b84

AhmedZero avatar Mar 26 '22 20:03 AhmedZero

That helps a lot narrowing down what the issue is. For easy future reference, it looks like most or all of these cause MSVC 2022 C++20 to fall over:

					//.def( py::self - py::self )
					// .def( py::self | py::self )
					// .def( py::self & py::self )
					// .def( py::self ^ py::self )
					//.def( py::self * py::self )
					//.def( py::self * int64_t() )
					// .def( py::self / py::self )
					// .def( py::self % py::self )

The next step is that someone needs to create a reproducer.

A quick search: we're exercising the operator overloads in:

  • pybind11/tests/test_operator_overloading.cpp — most relevant
  • pybind11/tests/test_sequences_and_iterators.cpp — seems tangential

Those tests are known to work with MSVC 2022 C++20 (GitHub Actions), so something appears to be special about your case, but what?

You have two options:

  1. guess & try adding code to test_operator_overloading.cpp
  2. reduce your code to a minimum that still makes the compiler fall over ("minimal reproducer"), then transfer that to test_operator_overloading.cpp

From past experience, this can take anywhere from 5 minutes to 5 hours, even with a lot of prior knowledge doing such things.

After you have a reproducer that triggers the compiler failure in the GitHub Actions: we will have to find a workaround for the compiler bug (99.99999% certain we're dealing with a compiler bug; MSVC is infamous for those). This can take anywhere from 1 minute to 1 week.

Do you have someone who could help you?

rwgk avatar Mar 27 '22 15:03 rwgk