[tint] Narrow unsafe buffer suppression
Narrows the suppression in src/tint/utils/bytes/swap.h to just the
function and adds details about how it can be entirely removed in the
future.
Removes the suppression from src/tint/utils/bytes/swap_test.cc
entirely.
Bug: 394825124
Change-Id: I973508abe87b69aa49fd651ca9eb9b5b9fd07a68
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/230514
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/utils/bytes/swap.h b/src/tint/utils/bytes/swap.h
index b4e1090..dcabecf 100644
--- a/src/tint/utils/bytes/swap.h
+++ b/src/tint/utils/bytes/swap.h
@@ -35,12 +35,15 @@
#include "src/tint/utils/macros/compiler.h"
-TINT_BEGIN_DISABLE_WARNING(UNSAFE_BUFFER_USAGE);
namespace tint::bytes {
-/// @return the input integer value with all bytes reversed
-/// @param value the input value
+/// @returns the input value with all bytes reversed
+/// @param value the input value, can be any type that passes std::is_integral
+/// (this includes non-obvious types like wchar_t)
+/// TODO(394825124): Once ranges from C++20 is available this code can be
+/// rewritten to avoid needing to disable warnings.
+TINT_BEGIN_DISABLE_WARNING(UNSAFE_BUFFER_USAGE);
template <typename T>
[[nodiscard]] inline T Swap(T value) {
static_assert(std::is_integral_v<T>);
@@ -53,9 +56,9 @@
memcpy(&out, bytes, sizeof(T));
return out;
}
+TINT_END_DISABLE_WARNING(UNSAFE_BUFFER_USAGE);
} // namespace tint::bytes
-TINT_END_DISABLE_WARNING(UNSAFE_BUFFER_USAGE);
#endif // SRC_TINT_UTILS_BYTES_SWAP_H_
diff --git a/src/tint/utils/bytes/swap_test.cc b/src/tint/utils/bytes/swap_test.cc
index 549d827..5d950c0 100644
--- a/src/tint/utils/bytes/swap_test.cc
+++ b/src/tint/utils/bytes/swap_test.cc
@@ -29,8 +29,6 @@
#include "gtest/gtest.h"
-TINT_BEGIN_DISABLE_WARNING(UNSAFE_BUFFER_USAGE);
-
namespace tint::bytes {
namespace {
@@ -54,5 +52,3 @@
} // namespace
} // namespace tint::bytes
-
-TINT_END_DISABLE_WARNING(UNSAFE_BUFFER_USAGE);