[PATCH] D75749: [clang-tidy] extend bugprone-signed-char-misuse check.

Tamás Zolnai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 14 12:20:10 PDT 2020


ztamas added a comment.

In D75749#1912338 <https://reviews.llvm.org/D75749#1912338>, @njames93 wrote:

> LGTM
>
> However, how does this handle cases when the type is written as `char`. They can be signed/unsigned based on what platform is being targeted. But on a platform where `char` is signed, comparison to an `unsigned char` is dangerous and the complimented case is the same. Surely any `char` comparison to `signed char` or `unsigned char` should be warned. But I'm not sure if that's in the scope of this check.


It uses the default signedness what clang specifies for `char` (which depends on the platform). For example, on my Linux x64 system, `char` is equivalent to `signed char` and so this clang-tidy check catches also the `char` <-> `unsigned char` comparisons. This default behavior can be overridden with `-funsigned-char` and `-fsigned-char` compilation options. So for a cross-platform C++ code, it's an option to run the clang-tidy twice, using these two options and so both `char` <-> `unsigned char` and `char` <-> `signed char` comparisons can be caught.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75749





More information about the cfe-commits mailing list