[libcxx-commits] [libcxx] [libc++][test] Suppress warning on bitwise shift with `bool` operands in `std::byte` tests for MSVC (PR #212433)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 28 01:45:57 PDT 2026
https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/212433
It was intentional in https://llvm.org/PR204116 that tests for `operator<<`, `operator<<=`, `operator>>`, `operator>>=` used `bool` operands, because `bool` is an integral type and thus satisfies the constraints of these operators.
However, MSVC considers `bool` is unsafe as an operand of bitwise shift operators and emits warning C4804. So this patch suppresses the warning for MSVC.
>From b5917b71d64ea8499c8dcd26e272d38617e11247 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Tue, 28 Jul 2026 16:42:45 +0800
Subject: [PATCH] [libc++][test] Suppress warning on bitwise shift with `bool`
operands in `std::byte` tests for MSVC
It was intentional in https://llvm.org/PR204116 that tests for
`operator<<`, `operator<<=`, `operator>>`, `operator>>=` used `bool`
operands, because `bool` is an integral type and thus satisfies the
constraints of these operators.
However, MSVC considers `bool` is unsafe as an operand of bitwise shift
operators and emits warning C4804. So this patch suppresses the warning
for MSVC.
---
.../support.types/byteops/lshift.assign.pass.cpp | 3 +++
.../std/language.support/support.types/byteops/lshift.pass.cpp | 3 +++
.../support.types/byteops/rshift.assign.pass.cpp | 3 +++
.../std/language.support/support.types/byteops/rshift.pass.cpp | 3 +++
4 files changed, 12 insertions(+)
diff --git a/libcxx/test/std/language.support/support.types/byteops/lshift.assign.pass.cpp b/libcxx/test/std/language.support/support.types/byteops/lshift.assign.pass.cpp
index 2c63be98ad86a..8b1569ab3036e 100644
--- a/libcxx/test/std/language.support/support.types/byteops/lshift.assign.pass.cpp
+++ b/libcxx/test/std/language.support/support.types/byteops/lshift.assign.pass.cpp
@@ -12,6 +12,9 @@
// constexpr byte& operator<<=(byte& b, IntType shift) noexcept;
// Constraints: is_integral_v<IntType> is true.
+// MSVC warning C4804: '<<': unsafe use of type 'bool' in operation
+// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4804
+
#include <cassert>
#include <cstddef>
#include <type_traits>
diff --git a/libcxx/test/std/language.support/support.types/byteops/lshift.pass.cpp b/libcxx/test/std/language.support/support.types/byteops/lshift.pass.cpp
index 86041def46095..2585162880066 100644
--- a/libcxx/test/std/language.support/support.types/byteops/lshift.pass.cpp
+++ b/libcxx/test/std/language.support/support.types/byteops/lshift.pass.cpp
@@ -12,6 +12,9 @@
// constexpr byte operator<<(byte b, IntType shift) noexcept;
// Constraints: is_integral_v<IntType> is true.
+// MSVC warning C4804: '<<': unsafe use of type 'bool' in operation
+// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4804
+
#include <cassert>
#include <cstddef>
#include <type_traits>
diff --git a/libcxx/test/std/language.support/support.types/byteops/rshift.assign.pass.cpp b/libcxx/test/std/language.support/support.types/byteops/rshift.assign.pass.cpp
index 2fd558c1bf544..bbac97bfc1d46 100644
--- a/libcxx/test/std/language.support/support.types/byteops/rshift.assign.pass.cpp
+++ b/libcxx/test/std/language.support/support.types/byteops/rshift.assign.pass.cpp
@@ -12,6 +12,9 @@
// constexpr byte& operator>>=(byte& b, IntType shift) noexcept;
// Constraints: is_integral_v<IntType> is true.
+// MSVC warning C4804: '>>': unsafe use of type 'bool' in operation
+// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4804
+
#include <cassert>
#include <cstddef>
#include <type_traits>
diff --git a/libcxx/test/std/language.support/support.types/byteops/rshift.pass.cpp b/libcxx/test/std/language.support/support.types/byteops/rshift.pass.cpp
index ded075febfc55..b1b91b4e0fe6d 100644
--- a/libcxx/test/std/language.support/support.types/byteops/rshift.pass.cpp
+++ b/libcxx/test/std/language.support/support.types/byteops/rshift.pass.cpp
@@ -12,6 +12,9 @@
// constexpr byte operator>>(byte b, IntType shift) noexcept;
// Constraints: is_integral_v<IntType> is true.
+// MSVC warning C4804: '>>': unsafe use of type 'bool' in operation
+// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4804
+
#include <cassert>
#include <cstddef>
#include <type_traits>
More information about the libcxx-commits
mailing list