[llvm] r210100 - Add operator== and operator!= to compare with nullptr.

David Blaikie dblaikie at gmail.com
Tue Jun 3 08:32:29 PDT 2014


On Tue, Jun 3, 2014 at 8:16 AM, Rafael EspĂ­ndola
<rafael.espindola at gmail.com> wrote:
> On 3 June 2014 11:03, David Blaikie <dblaikie at gmail.com> wrote:
>> Unit tests? (I say this in part because I recall giving Chris Lattner some
>> grief over a similar change (that turned out to be buggy...))
>
> I honestly don't see the point. I am as able to implement a broken
> test as I am to implement a broken ==. The unit test just makes it
> harder to notice what code is dead and to refactor APIs.

In this case the code looks dead in LLVM already - the only use is in
another project (clang). The tests provide the one use in LLVM to
ensure they actually compile/work for those other projects that depend
on it.

(in Chris's case it was worse - his use was internal (though it was
reasonable to have the feature in the public API))

> IMHO Unit tests are incredible valuable when
> * The implementation is not easily accessible from higher level tests.
> * The semantics are much simpler than the implementation. Things like
> removing an element from a set and then checking it is not there.

I agree, but I don't think they lack value in other cases. (I'm going
to go out on a limb and bet that std::shared_ptr has tests for its
op==(nullptr_t), and I'd lack confidence in it as a library if it
didn't)

> In this case as you pointed out in the other thread, the correct fix
> is probably to switch to std::shared_ptr anyway.
>
>> And if you're going to define some operators in terms of others you could do
>> that for all and implement A == nullptr as nullptr == A
>
> I like this one.  r210107.
>
> Cheers,
> Rafael




More information about the llvm-commits mailing list