https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78030
Bug ID: 78030 Summary: Lambda capture expression (different results than Clang & MSVC) Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sthlm58 at gmail dot com Target Milestone: --- The following code is supposed to remove non-unique elements from the vector (i.e. already existing in a set 's' (which is captured by value for the lambda purposes)) Problem is: it produces different results than Clang and MSVC, which seem to be correct. #include <algorithm> #include <iostream> #include <set> #include <vector> template <typename T> void print(T c) { for (auto e : c) std::cout << e << " "; std::cout << std::endl; } int main() { std::vector<int> elements { 1, 2, 4, 2, 1, 4, 5, 4, 4, 5, 1, 3, 0 }; elements.erase(std::remove_if(elements.begin(), elements.end(), [s = std::set<int>()](intc) mutable { return !s.insert(c).second; }), elements.end()); print(elements); } OUTPUT: 1 2 4 1 4 5 3 0 // GCC 4.x / 5.x / 6.x / 7.0 REQUIRED OUTPUT: 1 2 4 5 3 0 // Clang 3.4 - 4.0, Lastest MSVC Shown here: http://melpon.org/wandbox/permlink/h68S9ZKLYZqw4kvP