[libcxx-commits] [PATCH] D137804: [libc++][clang-tidy] Enable readability-simplify-boolean-expr

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 20 12:18:05 PST 2022


philnik added a comment.

In D137804#3939919 <https://reviews.llvm.org/D137804#3939919>, @ldionne wrote:

> I am not against this, but it's not clear to me that this really increases readability that much, since 50% of the changes suggested by the tool are not improvements IMO.

I'm actually quite surprised by that, given that I find the second one you commented on basically unreadable in the current state. Maybe I'm just exceptionally bad at reading negations though.



================
Comment at: libcxx/include/charconv:253
         {
-            if (!('0' <= *__p && *__p <= '9'))
+            if ('0' > *__p || *__p > '9')
                 break;
----------------
ldionne wrote:
> I don't find the new one to be more readable. The old one read more naturally as "if `*__p` is not between `'0'` and `'9'`". The new one isn't as clear.
Here I don't care super much, but I'd read the new version as "if *__p is outside `0` to `9`". IMO "outside" is a bit nicer than "not inside", which I'd mentally convert to "outside".


================
Comment at: libcxx/include/fstream:754
         {
-            _LIBCPP_ASSERT ( !(__extbufnext_ == NULL && (__extbufend_ != __extbufnext_)), "underflow moving from NULL" );
+            _LIBCPP_ASSERT (__extbufnext_ != NULL || __extbufend_ == __extbufnext_, "underflow moving from NULL" );
             if (__extbufend_ != __extbufnext_)
----------------
ldionne wrote:
> Here too, I don't find the new formulation more readable.
In this case I find the new version //much// more readable. Instead of "it's not the case that `__extbufnext_` is null and `__extbufend_` is not equal to `__extbufnext_`", it reads to me as "`__extbufnext_` is not null or `__extbufend_` is equal to `__extbufnext_`". In case of the second one I instantly know that the the iterator is non-null or range is empty; IOW check that we don't dereference a nullptr. To get to that conclusion I actually have to DeMorgan the original version in my head.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137804/new/

https://reviews.llvm.org/D137804



More information about the libcxx-commits mailing list