pybind11 warning in O3 optimization with gcc #6103
|
Hello. Similar to #3014 I have the issue that i get a lot of warnings when compiling using gcc. I am not yet beyond the example with using this library, so i am kind of new here. I am compiling my file using Getting warnings like: All of the warnings are Other than that, it compiles just fine. Not sure if this is my fault or a bug. |
Replies: 1 comment 1 reply
|
Short answer: not your fault, and not a bug in your code. It's a GCC false positive, and the code it's complaining about is pybind11's own — new code that landed in 3.0.2. Your module is fine. It's also, as far as I can tell, unreported, so it's worth a proper bug report. What the warning is actually pointing at
Yours decodes cleanly onto pybind11 3.0.x internals:
The chain is Why it's a false positive: the union's tag is read by This is also why it only shows up with optimization — GCC's docs are explicit that Honest caveat: I read the source rather than running GCC 16, so "false positive" is a confident conclusion from the code, not from an observed clean run. If you want actual certainty about your own build, What to do about it1. The one that definitely works — turn the diagnostic off for this build: gcc -O3 -Wall -Wno-maybe-uninitialized -shared -std=c++11 -fPIC \
$(python3-config --includes) -I "$PYBIND11_BASE/include" \
example.cpp -o "example$(python3-config --extension-suffix)"Every warning you pasted is 2. Narrower, worth trying — a pragma around the include, so your own code keeps the warning: #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#include <pybind11/pybind11.h>
#pragma GCC diagnostic popGCC checks Things that look like fixes but aren't:
Downgrading to 3.0.1 would make it go away ( Unrelated, but check it:
|
Short answer: not your fault, and not a bug in your code. It's a GCC false positive, and the code it's complaining about is pybind11's own — new code that landed in 3.0.2. Your module is fine. It's also, as far as I can tell, unreported, so it's worth a proper bug report.
What the warning is actually pointing at
#3014is a different problem (that one is Eigen'sDenseStorage.hinlined into the Eigen type caster; its workaround landed in #5516 and is already in your 3.0.4). Same diagnostic name, same "GCC + optimizer + a pybind11 header" shape, different code.Yours decodes cleanly onto pybind11 3.0.x internals:
used_kwargsis declared in the call dispatcher:include/pybind11/pybind11.h:1100…