"mathieu" <[EMAIL PROTECTED]> writes:

>   Just to be sure I am double-checking here.
>   Is there a way to make gcc produce a warning when a code is
> dereferencing an end iterator ? Or does this involve too much static
> analysis ?

The latter. 
You can however ask newer versions of g++ to catch this at runtime:

$ cat junk.cc
#include <vector>

typedef std::vector<int> VI;

int main()
{
    VI v(10);
    VI::iterator it = v.begin();
    while (*it == 0 && it != v.end()) ++it;
    return 0;
}

$ /usr/local/gcc-3.4.6/bin/g++ -g junk.cc && ./a.out && echo ok
ok
$ /usr/local/gcc-3.4.6/bin/g++ -g junk.cc -D_GLIBCXX_DEBUG && ./a.out
/usr/local/gcc-3.4.6/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../../include/c++/3.4.6/debug/safe_iterator.h178:
    error: attempt to dereference a past-the-end iterator.

Objects involved in the operation:
iterator "this" @ 0x0xbfffdc60 {
type = 
N11__gnu_debug14_Safe_iteratorIN9__gnu_cxx17__normal_iteratorIPiN10__gnu_norm6vectorIiSaIiEEEEEN15__gnu_debug_def6vectorIiS6_EEEE
 (mutable iterator);
  state = past-the-end;
  references sequence with type `N15__gnu_debug_def6vectorIiSaIiEEE' @ 
0x0xbfffdc60
}
Aborted (core dumped)

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to