This code compiles with g++, no collision is detected, although s is the parameter captured by lambda and the lambda parameter. My compiler is g++.
gcc Version is
gcc (Debian 4.9.2-10+deb8u2) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
and I am using these compilation flags :
-W
-Wall
-ansi
-pedantic
-s
-march=native
-flto
-fwhole-program
-Wfatal-errors
-Wextra
-std=c++1y
-frename-registers
-fipa-pta
-Ofast
-pedantic-errors
-fira-loop-pressure
-fomit-frame-pointer
-fforce-addr
-falign-functions
-fno-cprop-registers
-fstrength-reduce
Code is
#include <vector>
#include <algorithm>
#include <iostream>
int main (int argc, char* argv []) {
int s (0);
std::vector<int> vec ({3, 5, 13, 1});
std::for_each (vec.begin (), vec.end (), [&s] (const int& s) {
s = s>s?s:s;
});
std::cout << "max ox v is " << s << std::endl;
}
Is there a compilation option to detect this kind of error ?