Bug 1253844 - Enable the readability-implicit-bool-conversion checker r=andi
authorSylvestre Ledru <sledru@mozilla.com>
Wed, 03 Oct 2018 16:30:29 +0000
changeset 495375 6fe284f84898c89846f765ae0746967789ecbe16
parent 495374 67c81aab154d1f3e2f54a4141beae04ca7995144
child 495376 ec06f75313deec2dd3acf1d29b9cb3661a9bcc16
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersandi
bugs1253844
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1253844 - Enable the readability-implicit-bool-conversion checker r=andi Differential Revision: https://phabricator.services.mozilla.com/D7606
tools/clang-tidy/config.yaml
tools/clang-tidy/test/readability-implicit-bool-conversion.cpp
tools/clang-tidy/test/readability-implicit-bool-conversion.json
--- a/tools/clang-tidy/config.yaml
+++ b/tools/clang-tidy/config.yaml
@@ -108,16 +108,17 @@ clang_checkers:
   - name: performance-type-promotion-in-math-fn
   - name: performance-unnecessary-copy-initialization
   - name: performance-unnecessary-value-param
   - name: readability-braces-around-statements
   # Note: this can be loosened up by using the ShortStatementLines option
   - name: readability-container-size-empty
   - name: readability-delete-null-pointer
   - name: readability-else-after-return
+  - name: readability-implicit-bool-conversion
   - name: readability-inconsistent-declaration-parameter-name
   - name: readability-misleading-indentation
   - name: readability-non-const-parameter
   - name: readability-redundant-control-flow
   - name: readability-redundant-smartptr-get
   - name: readability-redundant-string-cstr
   - name: readability-redundant-string-init
   - name: readability-static-accessed-through-instance
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp
@@ -0,0 +1,51 @@
+
+#define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))
+
+void takesChar(char);
+void takesShort(short);
+void takesInt(int);
+void takesLong(long);
+
+void takesUChar(unsigned char);
+void takesUShort(unsigned short);
+void takesUInt(unsigned int);
+void takesULong(unsigned long);
+
+struct InitializedWithInt {
+  MOZ_IMPLICIT InitializedWithInt(int);
+};
+
+void f() {
+  bool b = true;
+  char s0 = b;
+  short s1 = b;
+  int s2 = b;
+  long s3 = b;
+
+  unsigned char u0 = b;
+  unsigned short u1 = b;
+  unsigned u2 = b;
+  unsigned long u3 = b;
+
+  takesChar(b);
+  takesShort(b);
+  takesInt(b);
+  takesLong(b);
+  takesUChar(b);
+  takesUShort(b);
+  takesUInt(b);
+  takesULong(b);
+
+  InitializedWithInt i = b;
+  (InitializedWithInt(b));
+
+  bool x = b;
+
+  int exp = (int)true;
+
+  if (x == b) {}
+  if (x != b) {}
+
+  if (b == exp) {}
+  if (exp == b) {}
+}
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-implicit-bool-conversion.json
@@ -0,0 +1,1 @@
+[["warning", "implicit conversion bool -> 'char'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'short'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'long'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned char'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned short'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned long'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'char'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'short'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'long'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned char'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned short'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned long'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"]]
\ No newline at end of file