[Bug libstdc++/78030] Lambda capture expression (different results than Clang & MSVC)
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Oct 19 01:22:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78030
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |libstdc++
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I don't think this is a front-end bug but possible a library bug.
Take a look at the implementation:
template<typename _ForwardIterator, typename _Predicate>
_ForwardIterator
__remove_if(_ForwardIterator __first, _ForwardIterator __last,
_Predicate __pred)
{
__first = std::__find_if(__first, __last, __pred);
if (__first == __last)
return __first;
_ForwardIterator __result = __first;
++__first;
for (; __first != __last; ++__first)
if (!__pred(__first))
{
*__result = std::move(*__first);
++__result;
}
return __result;
}
Notice how we call __find_if, it makes a copy of __pred which means we get a
new copy of s for the lambda.
This effect can be seen if we add:
print(s);
to the lambda:
1
1 2
1 2 4
1
1 4
1 4 5
1 4 5
1 4 5
1 4 5
1 4 5
1 3 4 5
----- CUT -----
The question now becomes is your lambda a valid Predicate function.
I think no.
More information about the Gcc-bugs
mailing list