-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix gcc 7 warning #844
Fix gcc 7 warning #844
Conversation
Under gcc 7 with -std=c++11, compilation results in several of the following warnings: In file included from /home/jagerman/src/pybind11/tests/test_sequences_and_iterators.cpp:13:0: /home/jagerman/src/pybind11/include/pybind11/operators.h: In function ‘pybind11::detail::op_<(pybind11::detail::op_id)0, (pybind11::detail::op_type)0, pybind11::detail::self_t, pybind11::detail::self_t> pybind11::detail::operator+(const pybind11::detail::self_t&, const pybind11::detail::self_t&)’: /home/jagerman/src/pybind11/include/pybind11/operators.h:78:76: warning: inline declaration of ‘pybind11::detail::op_<(pybind11::detail::op_id)0, (pybind11::detail::op_type)0, pybind11::detail::self_t, pybind11::detail::self_t> pybind11::detail::operator+(const pybind11::detail::self_t&, const pybind11::detail::self_t&)’ follows declaration with attribute noinline [-Wattributes] inline op_<op_##id, op_l, self_t, self_t> op(const self_t &, const self_t &) { \ ^ /home/jagerman/src/pybind11/include/pybind11/operators.h:109:1: note: in expansion of macro ‘PYBIND11_BINARY_OPERATOR’ PYBIND11_BINARY_OPERATOR(add, radd, operator+, l + r) ^~~~~~~~~~~~~~~~~~~~~~~~ In file included from /home/jagerman/src/pybind11/include/pybind11/cast.h:15:0, from /home/jagerman/src/pybind11/include/pybind11/attr.h:13, from /home/jagerman/src/pybind11/include/pybind11/pybind11.h:36, from /home/jagerman/src/pybind11/tests/pybind11_tests.h:2, from /home/jagerman/src/pybind11/tests/test_sequences_and_iterators.cpp:11: /home/jagerman/src/pybind11/include/pybind11/descr.h:116:36: note: previous definition of ‘pybind11::detail::descr pybind11::detail::operator+(pybind11::detail::descr&&, pybind11::detail::descr&&)’ was here PYBIND11_NOINLINE descr friend operator+(descr &&d1, descr &&d2) { ^~~~~~~~ This appears to be happening because gcc is considering implicit construction of `descr` in some places using addition of two `descr`-compatible arguments in the `descr.h` c++11 fallback code. There's no particular reason that this operator needs to be a friend function: this commit changes it to an rvalue-context member function operator, which avoids the warning.
cab8382
to
430166b
Compare
This seems a pretty straightforward change. Does anyone see a potential issue I've overlooking with the friend function -> member operator change? |
Why is this even a warning? GCC 7 bug? Those are completely unrelated declarations. |
I know, I found it rather odd as well, and it definitely smells like a bug—but this is in the final GCC 7.1 stable release, so the workaround seems warranted. The patch also doesn't actually even "work around" anything, but rather just slightly tightens up the contexts where This same warning may be triggered in other places as well, but we disable |
LGTM. |
Under gcc 7 with -std=c++11, compilation results in several of the following warnings:
This appears to be happening because gcc is considering implicit construction of
descr
in some places using addition of twodescr
-compatible arguments in thedescr.h
c++11 fallback code. There's no particular reason that this operator needs to be a friend function: this commit changes it to an rvalue-context member function operator, which avoids the warning.