Details
- Reviewers
JonasToth aaron.ballman alexfh
Diff Detail
Event Timeline
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp | ||
---|---|---|
49 | Turns out it is needed. /home/florin/tools/llvm-project/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:48:38: error: use of undeclared identifier 'FieldDecl'; did you mean 'fieldDecl'? const auto *AsFieldDecl = Node.get<FieldDecl>(); ^~~~~~~~~ fieldDecl |
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp | ||
---|---|---|
49 | I think the function should be made static and put into the clang namespace below (the same is true of the previous function in the anonymous namespace as well, but that doesn't need to be changed as part of this patch). | |
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h | ||
48 | I feel like there should be an assertion/unreachable in here -- there's no way for a bit-field width to be specified with a floating literal. | |
clang-tools-extra/docs/clang-tidy/checks/readability-magic-numbers.rst | ||
118 | Is the default false because you want to preserve existing functionality? Or do you think bit-field widths as integer literals really are magic numbers? |
clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers.cpp | ||
---|---|---|
88 | Can you also add a test for unsigned int: 0; to make sure it does not warn about this value? IMO it shouldn't warn since it is a special case with a well defined behaviour. |
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h | ||
---|---|---|
48 | This follows the pattern with isSyntheticValue. It allows the checkBoundMatch template to be called with either. It is a hack (to keep most of the checks aligned between ints and float), that is getting close to the end of its useful life. But I'll break up that function on the next change. | |
clang-tools-extra/docs/clang-tidy/checks/readability-magic-numbers.rst | ||
118 | The default is false to preserve the old behavior. I don't think the old behavior is that great so if somebody really wants it flipped I could easily go for it. The bit fields as integer literals are magic, but I am not sure of the value of warning over them in code that accesses hardware directly and makes use of generated files. I would prefer people to use this check for the regular code, and not be scared away by many warnings that they can't fix anyway because it is vendor code. | |
clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers.cpp | ||
88 | 0 is a special value anyway, but I will add the test. |
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp | ||
---|---|---|
49 | Done |
Flipped the default to ignore bit fields. Moved static functions out of the anonymous namespace into the clang namespace.
clang-tools-extra/docs/clang-tidy/checks/readability-magic-numbers.rst | ||
---|---|---|
118 | Flipped to ignore bit field widths by default. |
Thank you Aaron. I don't have commit privileges so I'll need your help to integrate this.
Will you make the small fixes before commit, or would you like me to upload a new diff?
florin
I'd appreciate if you could do the tweaks and upload a new patch. I'll try to apply sometime today.
Thanks for the patch, I've commit on your behalf in 6dcb1003f2022cba36e9f5a6d39648c3a3a213a0
I feel like there should be an assertion/unreachable in here -- there's no way for a bit-field width to be specified with a floating literal.