[PATCH] D38455: [clang-tidy] new cppcoreguidelines-narrowing-conversions check.

Aaron Ballman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 18 06:17:22 PDT 2018


aaron.ballman added inline comments.


================
Comment at: clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp:35
+                                      hasSourceExpression(IsFloatExpr),
+                                      unless(hasParent(castExpr())))
+                         .bind("cast"),
----------------
I believe this code will not diagnose under this check -- is that intended as a way to silence the check?
```
i += (double)0.5;
```


================
Comment at: docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst:10-11
+
+This rule is part of the "Expressions and statements" profile of the C++ Core
+Guidelines, corresponding to rule ES.46. See
+
----------------
More exposition is needed because this is only a very small part of the core guideline. You should be explicit about where we deviate (or what we support, depending on which is the clearest exposition).


================
Comment at: test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp:81
+
+}  // namespace floats
----------------
What should happen in cases like the following:
```
template <typename T1, typename T2>
void f(T1 one, T2 two) {
  one += two;
}

void g() {
  f(1, 2);
  f(1, .5);
}

#define DERP(i, j) (i += j)

void h() {
  int i = 0;
  DERP(1, 2);
  DERP(i, .5);
}
```


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38455





More information about the llvm-commits mailing list