[clang] [DiagnosticInfo] Allow std::string_view in DiagnosticBuilder operator<<. (PR #190374)
Jackson Stogel via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 3 11:28:16 PDT 2026
https://github.com/jtstogel updated https://github.com/llvm/llvm-project/pull/190374
>From 6b8b34a84f1fb8ba66dc0b2f20e3870a43291715 Mon Sep 17 00:00:00 2001
From: jtstogel <jtstogel at google.com>
Date: Fri, 3 Apr 2026 10:31:09 -0700
Subject: [PATCH 1/3] [DiagnosticInfo] Allow std::string_view in
DiagnosticBuilder opeartor<<.
After a68ae7b0cc0922b79114aabe8cf1ec8dc68524d7, calling `<<` with a `std::string_view` gives:
```
clang/include/clang/Basic/Diagnostic.h:1319:8: error: use of overloaded operator '<<' is ambiguous (with operand types 'const StreamingDiagnostic' and 'const std::string_view')
1319 | DB << V;
| ~~ ^ ~
```
---
clang/include/clang/Basic/Diagnostic.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index 5a6f5fd61a5db..6dc2eb040c9ca 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1374,6 +1374,12 @@ inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
return DB;
}
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ std::string_view S) {
+ DB.AddString(S);
+ return DB;
+}
+
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
const std::string &S) {
DB.AddString(S);
>From e1578e5caa8ca7a0090eb1112492e567322497eb Mon Sep 17 00:00:00 2001
From: jtstogel <jtstogel at google.com>
Date: Fri, 3 Apr 2026 11:20:40 -0700
Subject: [PATCH 2/3] Include string_view
---
clang/include/clang/Basic/Diagnostic.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index 6dc2eb040c9ca..c7c98c0a460fb 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -35,6 +35,7 @@
#include <map>
#include <memory>
#include <optional>
+#include <string_view>
#include <string>
#include <type_traits>
#include <utility>
>From e10f38eda2be0daf471b5ccbac6612896a3afa62 Mon Sep 17 00:00:00 2001
From: jtstogel <jtstogel at google.com>
Date: Fri, 3 Apr 2026 11:28:00 -0700
Subject: [PATCH 3/3] Format
---
clang/include/clang/Basic/Diagnostic.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index c7c98c0a460fb..aa05f9d60dadf 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -35,8 +35,8 @@
#include <map>
#include <memory>
#include <optional>
-#include <string_view>
#include <string>
+#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
More information about the cfe-commits
mailing list