[PATCH] D129570: [clang-tidy] Add new clang-tidy check to find implicit conversions from enum to integer.

Paul Fultz II via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 11 17:18:09 PST 2023


pfultz2 added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/EnumToIntCheck.cpp:45
+  } else {
+    Note << FixItHint::CreateInsertion(MatchedExpr->getBeginLoc(), "(int)");
+  }
----------------
carlosgalvezp wrote:
> I don't think we can assume the type of the enum is `int`, see for example:
> 
> ```
> enum Foo : unsigned int
> {
>     a,
>     b
> };
> 
> 
> void f(unsigned int);
> 
> int main()
> {
>     f(a);
> }
> 
> ```
> 
> Even if there is no explicit underlying type, isn't the underlying type implementation-defined?
Since its an explicit cast then we should probably use the type that the function accepts(since thats what it will be eventually converted to)  rather than the type of the underling enum type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129570



More information about the cfe-commits mailing list