Fix false positive in magic number checker
https://bugs.llvm.org/show_bug.cgi?id=40640: cppcoreguidelines-avoid-magic-numbers should not warn about enum class
Test case code reduced by Pavel Kryukov.
Differential D71686
Fix false positive in magic number checker 0x8000-0000 on Dec 18 2019, 8:02 PM. Authored by
Details
Fix false positive in magic number checker https://bugs.llvm.org/show_bug.cgi?id=40640: cppcoreguidelines-avoid-magic-numbers should not warn about enum class Test case code reduced by Pavel Kryukov.
Diff Detail
Event Timeline
Comment Actions My take: this change fixes a user-reported bug, and does not cause any known regressions. I think we should integrate this. Comment Actions I sort of wonder whether we want to document this as a blessed approach to silencing the warning. I'm not certain if it's too obtuse or not, but I notice the check has no documented ways to silence the diagnostic aside from using the correct kind of magic number or adding it to a list of excluded magic numbers. Comment Actions You mean Hyrum's Law is not sufficient? The check can be silenced with the regular NOLINT, or with defining and using a constant/enum. Using this "backdoor" way seems even more cumbersome and confusing than the NOLINT. At least with NOLINT it is clear what you're doing, and somebody else can grep for it and fix it if it is appropriate. Comment Actions My concern is that NOLINT is insufficient. Consider: foo(12, 42, 18); where the 42 is not desired to be warned about due to domain-specific knowledge but the 12 and 18 are. However, I am not convinced that you're wrong either -- casting is cumbersome. But it's also a somewhat well-used workaround to silence warnings (casting to void silencing unused value warnings being a common example). For right now, we can leave it as a bug -- we can decide to bless the approach later. Comment Actions LGTM aside from some minor nits.
Comment Actions @aaron.ballman updated as suggested; please commit/integrate when you have a moment. Thank you! Comment Actions Happy to do so, thank you for the fix! I've commit in c16b3ec597d277b5a7397db308f8ec730f3330a3 |
127-130 are the new lines. The rest were moved about by clang-format. Please let me know if I should revert the format.