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

Florin Iucha via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 17:44:30 PDT 2018


0x8000-0000 created this revision.
0x8000-0000 added reviewers: Wizard, aaron.ballman, alexfh, hokein.
Herald added subscribers: cfe-commits, mgorny.

Add a clang-tidy check for "magic numbers", integers and floating point values embedded in the code instead of using symbols or constants.

Bad example:

  double circleArea = 3.1415926535 * radius * radius;

Good example:

  double circleArea = M_PI * radius * radius;

This version detects and report integers only. If there is interest of merging the tool I can add the functionality for floats as well.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/MagicNumbersCheck.cpp
  clang-tidy/readability/MagicNumbersCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-magic-numbers.rst
  test/clang-tidy/readability-magic-numbers.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49114.154742.patch
Type: text/x-patch
Size: 10674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180710/fc00e6ed/attachment.bin>


More information about the cfe-commits mailing list