[PATCH] D49114: [clang-tidy] Add a check for "magic numbers"

Florin Iucha via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 18 19:18:38 PDT 2018


0x8000-0000 marked an inline comment as done.
0x8000-0000 added inline comments.


================
Comment at: test/clang-tidy/readability-magic-numbers.cpp:16
+void BuggyFunction() {
+  int BadLocalInt = 6;
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: magic number integer literal 6 [readability-magic-numbers]
----------------
0x8000-0000 wrote:
> Quuxplusone wrote:
> > Please add test cases immediately following this one, for
> > 
> >     const int BadLocalConstInt = 6;
> >     constexpr int BadLocalConstexprInt = 6;
> >     static const int BadLocalStaticConstInt = 6;
> >     static constexpr int BadLocalStaticConstexprInt = 6;
> > 
> > (except of course changing "Bad" to "Good" in any cases where 6 is acceptable as an initializer).
> > 
> > Also
> > 
> >     std::vector<int> BadLocalVector(6);
> >     const std::vector<int> BadLocalConstVector(6);
> > 
> > etc. etc.
> Again... all the "const .* (\d)+" patterns should be acceptable. We're initializing a constant. Would you prefer an explicit option?
I have  template and constructor arguments already in the test. I have tried including <vector> but somehow it is not found and the std::vector is reported as an error in itself.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114





More information about the cfe-commits mailing list