https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80711
--- Comment #8 from David Binderman <dcb314 at hotmail dot com> --- (In reply to Jonathan Wakely from comment #7) > struct indirect_cmp { > static int counter; > bool operator()(const X* l, const X* r) { > ++counter; > return *l < *r; > } > }; > > int indirect_cmp::counter = 0; > > So the pure attribute isn't the right property. I tried your code on cppcheck and much to my surprise it found the problem: $ /home/dcb/cppcheck/trunk//cppcheck --enable=all --inconclusive may9a.cc may9a.cc:4:8: style:inconclusive: Technically the member function 'indirect_cmp::operator()' can be const. [functionConst] bool operator()(const X* l, const X* r) { ^ $ My working assumption had been that cppcheck was looking for C++ member functions that consist of a return statement only but clearly it is doing more than that. If there is any interest, I could probably figure out the pattern of C++ code it is looking for. My opinion is that a first approximation at implementation in gcc would merely look for C++ member functions that are return statements only. More fancy things could be done later in a second version.