[llvm] 1cb8afb - [Testing] Use is_detected for StringMapEntry ostream check (NFC) (#159954)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 20 18:42:08 PDT 2025
Author: Kazu Hirata
Date: 2025-09-20T18:42:04-07:00
New Revision: 1cb8afb2587d2fddf8120f98b7646a681da18cff
URL: https://github.com/llvm/llvm-project/commit/1cb8afb2587d2fddf8120f98b7646a681da18cff
DIFF: https://github.com/llvm/llvm-project/commit/1cb8afb2587d2fddf8120f98b7646a681da18cff.diff
LOG: [Testing] Use is_detected for StringMapEntry ostream check (NFC) (#159954)
This patch replaces a std::void_t-based detection of the streaming
(<<) operator with a llvm::is_detected-based detection. This way, we
don't have to roll our own SFINAE logic and fallback mechanism.
Added:
Modified:
llvm/include/llvm/Testing/ADT/StringMapEntry.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Testing/ADT/StringMapEntry.h b/llvm/include/llvm/Testing/ADT/StringMapEntry.h
index 7649c30078181..5fba1dd914d86 100644
--- a/llvm/include/llvm/Testing/ADT/StringMapEntry.h
+++ b/llvm/include/llvm/Testing/ADT/StringMapEntry.h
@@ -9,6 +9,7 @@
#ifndef LLVM_TESTING_ADT_STRINGMAPENTRY_H_
#define LLVM_TESTING_ADT_STRINGMAPENTRY_H_
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringMapEntry.h"
#include "gmock/gmock.h"
#include <ostream>
@@ -17,13 +18,9 @@
namespace llvm {
namespace detail {
-template <typename T, typename = std::void_t<>>
-struct CanOutputToOStream : std::false_type {};
-
template <typename T>
-struct CanOutputToOStream<T, std::void_t<decltype(std::declval<std::ostream &>()
- << std::declval<T>())>>
- : std::true_type {};
+using check_ostream =
+ decltype(std::declval<std::ostream &>() << std::declval<T>());
} // namespace detail
@@ -32,7 +29,8 @@ struct CanOutputToOStream<T, std::void_t<decltype(std::declval<std::ostream &>()
template <typename T>
std::ostream &operator<<(std::ostream &OS, const StringMapEntry<T> &E) {
OS << "{\"" << E.getKey().data() << "\": ";
- if constexpr (detail::CanOutputToOStream<decltype(E.getValue())>::value) {
+ if constexpr (is_detected<detail::check_ostream,
+ decltype(E.getValue())>::value) {
OS << E.getValue();
} else {
OS << "non-printable value";
More information about the llvm-commits
mailing list