[PATCH] D106431: [clang-tidy] Fix cppcoreguidelines-init-variables with enum judgement

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 22 06:57:20 PDT 2021


aaron.ballman added a comment.

In D106431#2896206 <https://reviews.llvm.org/D106431#2896206>, @whisperity wrote:

> The problem with enums is that translating //zero// (0, 0.0, nullptr, etc...) to the enum case is not always apparent. A warning **should** always be given. And //if// you can find a zero member in the enum, we can report an automated suggestion for that.

I think we shouldn't give any fix-it for enumerations. Zero doesn't always mean "the right default value" -- for example, another common idiom is for the *last* member of the enumeration to be a sentinel value.



================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp:103
+  // Expect no warning given here.
+  Color color;
+  // Expect no warning given here.
----------------
MTC wrote:
> steven.zhang wrote:
> > Technical speaking, we should warn about such case, ad the color is undefined now. Can we initialize it to the lowerest value of the enum type ?
> Good point! However, which value should be chosen as automatic fix is a problem worth discussing.
FWIW, I'd expect a warning but no fix-it for these.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106431



More information about the cfe-commits mailing list