LSC proposal to modernize use of bool literals

27 показвания
Преминаване към първото непрочетено съобщение

Anton Bikineev

непрочетено,
23.01.2022 г., 7:40:0623.01.22 г.
до cxx
Hi all,

I have seen (and written myself) code like:
  bool foo() {
    if (something)
      return 0; // implicit conversion of int literal to bool
  }

This conversion is benign, however it often impairs readability. There is a clang-tidy's check that finds/transforms the integral literals to bool ones - modernize-use-of-bool-literals. Here I'm proposing to apply the check across chromium (and other repos) to fix such uses.

Possible controversial topics:
  • while (1) { ... }. This is quite common and actually idiomatic in C89, where there is no the bool type. According to codesearch, we have more "while (1)" than "while (true)" (5600 vs 3814). I propose to not touch these cases and fix/augment the clang-tidy's check in upstream.
  • some unittest data (here, for example), where the use of integral literals is more representative. There seem to be not many cases like this, so I'd also propose to not rewrite them.
What do you think? 

Peter Kasting

непрочетено,
23.01.2022 г., 10:30:0623.01.22 г.
до Anton Bikineev,cxx
Personally I'd just rewrite both those cases you mention.

PK

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAFd1ZwdWGJgrVYLO4JeVBzGXNoZsVskqgkskE%2BHTpKRgDMeo4g%40mail.gmail.com.

K. Moon

непрочетено,
23.01.2022 г., 14:07:4123.01.22 г.
до Peter Kasting,Anton Bikineev,cxx
I prefer "for (;;)" for infinite loops, anyway.

Anton Bikineev

непрочетено,
24.01.2022 г., 4:40:0224.01.22 г.
до K. Moon,Peter Kasting,cxx
I've applied the check on Chromium (+ V8, pdfium, webrtc and some other repos). In Chromium there are only 75 files changed (CL). Do you think we need an LSC doc for the change?

Nico Weber

непрочетено,
24.01.2022 г., 10:59:3624.01.22 г.
до Anton Bikineev,K. Moon,Peter Kasting,cxx

Anton Bikineev

непрочетено,
24.01.2022 г., 18:04:4824.01.22 г.
до Nico Weber,K. Moon,Peter Kasting,cxx
Thanks! I created a short doc for it.
Отговор до всички
Отговор до автора
Препращане
0 нови съобщения