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

Florin Iucha via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 19 15:00:47 PDT 2018


0x8000-0000 marked 3 inline comments 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]
----------------
aaron.ballman wrote:
> 0x8000-0000 wrote:
> > 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.
> Tests need to be hermetic and cannot rely on STL headers or other system headers. Basically, you have to replicate the contents of <vector> (or whatever) within the test file for whatever you're trying to test.
Ok - we have that already and there's nothing magic about std::vector or std::array.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114





More information about the cfe-commits mailing list