[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Having at semantic for []
From: |
Paul Pluzhnikov |
Subject: |
Re: Having at semantic for [] |
Date: |
Mon, 14 May 2007 09:12:18 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
Marc Boyer <Marc.Boyer@enseeiht.yahoo.fr.invalid> writes:
> is there a way to ask g++ to give the semantics of
> vector::at() (ie checking bounds) to vector::operator[]
> in some 'debug mode'.
For recent versions of g++ (3.4.0 and above), -D_GLIBCXX_DEBUG
finds this error (and many others):
$ cat junk.cc
#include <vector>
typedef std::vector<int> VI;
int main() {
VI vi; vi.push_back(1);
int x = vi[1]; // bug
}
$ /usr/local/gcc-3.4.6/bin/g++ -g junk.cc -D_GLIBCXX_DEBUG && ./a.out
/usr/local/gcc-3.4.6/include/c++/3.4.6/debug/vector:192:
error: attempt to subscript container with out-of-bounds index 1, but
container only holds 1 elements.
Objects involved in the operation:
sequence "this" @ 0x0xbfffdf90 {
type = N15__gnu_debug_def6vectorIiSaIiEEE;
}
Aborted (core dumped)
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.