Maxim Yegorushkin wrote: > mathieu wrote: > > > Hi there, > > > > I am looking for a warning in gcc that would warn me about > > potentially dangerous operation, such as the one describe in (*). I > > understand this is perfectly valid operation, but it looks to me like a > > valid warning. > > > > I tried the following so far: > > > > -Wall -Wextra -Wconversion -Wsign-compare > > > > Thanks > > -Mathieu > > > > (*) > > #include <vector> > > > > int main() > > { > > std::vector<int> v; > > int s = 0; > > for(unsigned int i = 0; i < v.size() - 1; ++i) // v.size() == 0 > > { > > s += v[i] * v[i+1]; > > } > > > > return 0; > > } > > You could just change the loop to make it play well when 0 == v.size(): > > for(unsigned int i = 1; i < v.size(); ++i) > { > s += v[i - 1] * v[i]; > }
Not exactly what I was looking for, but the solution is very elegant. Thanks ! -M _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus