summaryrefslogtreecommitdiffstats
path: root/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /tools/clang-tidy/test/readability-implicit-bool-conversion.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/clang-tidy/test/readability-implicit-bool-conversion.cpp')
-rw-r--r--tools/clang-tidy/test/readability-implicit-bool-conversion.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp b/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp
new file mode 100644
index 0000000000..c30089a126
--- /dev/null
+++ b/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp
@@ -0,0 +1,55 @@
+
+#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) {}
+
+ char* ptr;
+ // Shouldn't trigger a checker warning since we are using AllowPointerConditions
+ if (ptr) {}
+}