LSC proposal to modernize use of bool literals

瀏覽次數:27 次
跳到第一則未讀訊息

Anton Bikineev

未讀,
2022年1月23日 清晨7:40:062022/1/23
收件者: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

未讀,
2022年1月23日 上午10:30:062022/1/23
收件者: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

未讀,
2022年1月23日 下午2:07:412022/1/23
收件者:Peter Kasting、Anton Bikineev、cxx
I prefer "for (;;)" for infinite loops, anyway.

Anton Bikineev

未讀,
2022年1月24日 凌晨4:40:022022/1/24
收件者: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

未讀,
2022年1月24日 上午10:59:362022/1/24
收件者:Anton Bikineev、K. Moon、Peter Kasting、cxx

Anton Bikineev

未讀,
2022年1月24日 下午6:04:482022/1/24
收件者:Nico Weber、K. Moon、Peter Kasting、cxx
Thanks! I created a short doc for it.
回覆所有人
回覆作者
轉寄
0 則新訊息