-
Notifications
You must be signed in to change notification settings - Fork 15
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 reference to local variable. #1060
Conversation
This comment has been minimized.
This comment has been minimized.
Logfiles from GitLab pipeline #149850 (:no_entry:) have been uploaded here! Status and direct links: |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1060 +/- ##
==========================================
- Coverage 69.98% 69.96% -0.03%
==========================================
Files 188 188
Lines 25659 25661 +2
==========================================
- Hits 17957 17953 -4
- Misses 7702 7708 +6
☔ View full report in Codecov by Sentry. |
These functions is covered by tests:
|
0f0c627
to
ea500eb
Compare
It's slightly more complicated. Pybind11 supports returning #define PYBIND11_OVERRIDE_IMPL(ret_type, cname, name, ...) \
do { \
pybind11::gil_scoped_acquire gil; \
pybind11::function override \
= pybind11::get_override(static_cast<const cname *>(this), name); \
if (override) { \
auto o = override(__VA_ARGS__); \
if (pybind11::detail::cast_is_temporary_value_reference<ret_type>::value) { \
static pybind11::detail::override_caster_t<ret_type> caster; \
return pybind11::detail::cast_ref<ret_type>(std::move(o), caster); \
} \
return pybind11::detail::cast_safe<ret_type>(std::move(o)); \
} \
} while (false) https://github.com/pybind/pybind11/blob/master/include/pybind11/pybind11.h#L2829 We can check that: pybind11::detail::cast_is_temporary_value_reference<const std::string&>::value == true but pybind11::detail::cast_is_temporary_value_reference<const std::shared_ptr<T>&>::value == false which explains why the warning point to code that's called via: return pybind11::detail::cast_safe<ret_type>(std::move(o)); \ rather than return pybind11::detail::cast_ref<ret_type>(std::move(o), caster); \ (I've tried adding Given the documented limitations with returning const-references, see |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Just for clarity: PyAst::get_statement_block()
is not a culprit here?
ea500eb
to
cc0d6ef
Compare
Sorry, somehow only a "fixup" commit made it to github (bad rebase or something). The first commit is the important one (that was missing). |
During CI we see the following compiler warning:
e.g. https://app.circleci.com/pipelines/github/neuronsimulator/nrn/5301/workflows/c43f0a31-36ec-4e95-93df-7df650db01d4/jobs/2887?invite=true#step-102-127220_85
If we track the definition of
cast_op
andload_type
we find:and
The suspicion is that
make_caster<T>
will strip the&
and store a copyHowever, then the returned reference does point to a local variable.
We fix this by returning
std::shared_ptr
by value.