[llvm] [Testing] Use is_detected for StringMapEntry ostream check (NFC) (PR #159954)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 20 16:16:12 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From 2c1cbe6649d1bdff339aa7967690a4043ab269f9 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 16 Sep 2025 22:30:23 -0700
Subject: [PATCH] [Testing] Use is_detected for StringMapEntry ostream check
(NFC)
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.
---
llvm/include/llvm/Testing/ADT/StringMapEntry.h | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
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