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

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 11 13:55:10 PDT 2018


Quuxplusone added inline comments.


================
Comment at: docs/clang-tidy/checks/readability-magic-numbers.rst:11
+
+   double circleArea = 3.1415926535 * radius * radius;
+
----------------
0x8000-0000 wrote:
> Eugene.Zelenko wrote:
> > JonasToth wrote:
> > > This example is good, but right now the code only checks for integer literals. Maybe an integer example would be better?
> > Please use .. code-block:: c++. Same for good example.
> @JonasToth I raked my brain but I just can't come up with a short and effective example. I haven't given up yet.
A common "magic number" in real code would be something like
```
int get_answer() {
    if (cond) return x;
    return -1;  // FILENOTFOUND
}
```


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114





More information about the cfe-commits mailing list