This fixes a dangling-reference issue with views::split and other multi-argument adaptors that may take its extra arguments by reference. When creating the _RangeAdaptorClosure in _RangeAdaptor::operator(), we currently capture all provided arguments by value. When we then use the _RangeAdaptorClosure and call it with a range, as in e.g. v = views::split(p)(range), we forward the range and the captures to the underlying adaptor routine. But then when the temporary _RangeAdaptorClosure goes out of scope, the by-value captures get destroyed and the references to these captures in the resulting view become dangling. This patch fixes this problem by capturing lvalue references by reference in _RangeAdaptorClosure::operator(), and then forwarding the captures appropriately to the underlying adaptor routine. libstdc++-v3/ChangeLog: * include/std/ranges (views::__adaptor::__maybe_refwrap): New utility function. (views::__adaptor::_RangeAdaptor::operator()): Add comments. Use __maybe_refwrap to capture lvalue references by reference, and then use unwrap_reference_t to forward the by-reference captures as references. * testsuite/std/ranges/adaptors/split.cc: Augment test. * testsuite/std/ranges/adaptors/split_neg.cc: New test.
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
config | Loading commit data... | |
doc | Loading commit data... | |
include | Loading commit data... | |
libsupc++ | Loading commit data... | |
po | Loading commit data... | |
python | Loading commit data... | |
scripts | Loading commit data... | |
src | Loading commit data... | |
testsuite | Loading commit data... | |
ChangeLog | Loading commit data... | |
ChangeLog-1998 | Loading commit data... | |
ChangeLog-1999 | Loading commit data... | |
ChangeLog-2000 | Loading commit data... | |
ChangeLog-2001 | Loading commit data... | |
ChangeLog-2002 | Loading commit data... | |
ChangeLog-2003 | Loading commit data... | |
ChangeLog-2004 | Loading commit data... | |
ChangeLog-2005 | Loading commit data... | |
ChangeLog-2006 | Loading commit data... | |
ChangeLog-2007 | Loading commit data... | |
ChangeLog-2008 | Loading commit data... | |
ChangeLog-2009 | Loading commit data... | |
ChangeLog-2010 | Loading commit data... | |
ChangeLog-2011 | Loading commit data... | |
ChangeLog-2012 | Loading commit data... | |
ChangeLog-2013 | Loading commit data... | |
ChangeLog-2014 | Loading commit data... | |
ChangeLog-2015 | Loading commit data... | |
ChangeLog-2016 | Loading commit data... | |
ChangeLog-2017 | Loading commit data... | |
ChangeLog-2018 | Loading commit data... | |
ChangeLog-2019 | Loading commit data... | |
Makefile.am | Loading commit data... | |
Makefile.in | Loading commit data... | |
README | Loading commit data... | |
acinclude.m4 | Loading commit data... | |
aclocal.m4 | Loading commit data... | |
config.h.in | Loading commit data... | |
configure | Loading commit data... | |
configure.ac | Loading commit data... | |
configure.host | Loading commit data... | |
crossconfig.m4 | Loading commit data... | |
fragment.am | Loading commit data... | |
linkage.m4 | Loading commit data... |