[clang] [DiagnosticInfo] Allow std::string_view in DiagnosticBuilder operator<<. (PR #190374)

via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 3 10:48:17 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Jackson Stogel (jtstogel)

<details>
<summary>Changes</summary>

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;
      |     ~~ ^  ~
```

---
Full diff: https://github.com/llvm/llvm-project/pull/190374.diff


1 Files Affected:

- (modified) clang/include/clang/Basic/Diagnostic.h (+6) 


``````````diff
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);

``````````

</details>


https://github.com/llvm/llvm-project/pull/190374


More information about the cfe-commits mailing list