[libc-commits] [PATCH] D85790: [libc][NFC] Extend <ASSERT|EXPECT>_STR* macros to compare with nullptr.
Siva Chandra via Phabricator via libc-commits
libc-commits at lists.llvm.org
Wed Aug 12 07:36:27 PDT 2020
sivachandra added inline comments.
================
Comment at: libc/utils/UnitTest/Test.cpp:256
unsigned long Line) {
+ if (LHS == nullptr)
+ LHS = "<nullptr>";
----------------
cgyurgyik wrote:
> So if I'm not mistaken, this will just compare `"<nullptr>"` with the other string, which will (falsely) return true if the other string is also the string literal `"<nullptr>"`? Maybe we can put something else a bit longer, such as `___<nullptr>___` ?
> Or, just simply check here if the other string is actually the string literal `"<nullptr>"` to catch that case.
>
> Just blanket suggestions, please let me know if I'm mistaken here.
No you are not mistaken. And yes, using a "default" string is not perfect. Other things like you suggest (check iff the real string is equal to the actual string) etc can be done but not sure if that is worth it. I would ideally want `llvm::StringRef` to take of this. But, it is very specifically designed to allow equal comparison of null and nullpointer: https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/ADT/StringRef.h#L74
The best solution would be to use a class with has `std::string_view` semantics.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85790/new/
https://reviews.llvm.org/D85790
More information about the libc-commits
mailing list