[llvm-commits] [llvm] r61576 - /llvm/trunk/unittests/ADT/ImmutableSetTest.cpp
Bill Wendling
isanbard at gmail.com
Fri Jan 2 15:11:37 PST 2009
On Jan 2, 2009, at 6:37 AM, Misha Brukman wrote:
> +static char *ptr; // tmp var
> +struct MyIter {
> + int counter;
> + MyIter() : counter(0) {}
> + void operator()(char c) {
> + *ptr++ = c;
> + ++counter;
> + }
> +};
>
> Global state is frowned upon -- if you don't properly clear it
> between tests, strange bugs will occur, and they will depend on the
> order of the test execution (which aren't guaranteed to execute in
> any particular order). This will lead to strange Heisenbugs.
>
> Instead, you can make another Fixture class, and make this state a
> part of that class. If you set up that state, you'll know you're
> always getting a clean beginning state, and you'll have nothing to
> worry about.
>
Also, the "*ptr++" is writing over memory that's not allocated. I'm
going to get rid of the "++" in there. I think that that's causing
some test failures. But the general "global state" needs to be
addressed.
-bw
More information about the llvm-commits
mailing list