[llvm] [Support] C++26 fixes for P2591 (PR #223284)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 16:23:42 PDT 2026
https://github.com/rdong8 created https://github.com/llvm/llvm-project/pull/223284
[P2591R5](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2591r5.html) (C++26) added `std::string operator+(const std::string &, std::string_view)`. Since `llvm::StringRef` implicitly converts to `std::string_view`, ADL selects this one instead of LLVM's `Twine operator+(const Twine &, const Twine &)`. This causes some issues when compiling with C++26, since `std::string` has no `.str()` method.
>From 1fd8f3fbd7d4f0934d3861a2a4ecef3ef8410844 Mon Sep 17 00:00:00 2001
From: Richard Dong <66289396+rdong8 at users.noreply.github.com>
Date: Sun, 13 Sep 2026 23:18:41 +0000
Subject: [PATCH] [Support] C++26 fixes for P2591
---
llvm/lib/Support/CodeGenCoverage.cpp | 6 +++---
llvm/lib/Support/VirtualFileSystem.cpp | 15 ++++++++++-----
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Support/CodeGenCoverage.cpp b/llvm/lib/Support/CodeGenCoverage.cpp
index 2e35019e12c168..4f665ec9889fff 100644
--- a/llvm/lib/Support/CodeGenCoverage.cpp
+++ b/llvm/lib/Support/CodeGenCoverage.cpp
@@ -13,6 +13,7 @@
#include "llvm/Support/Endian.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Process.h"
@@ -83,9 +84,8 @@ bool CodeGenCoverage::emit(StringRef CoveragePrefix,
// We can handle locking within a process easily enough but we don't want to
// manage it between multiple processes. Use the process ID to ensure no
// more than one process is ever writing to the same file at the same time.
- std::string Pid = llvm::to_string(sys::Process::getProcessId());
-
- std::string CoverageFilename = (CoveragePrefix + Pid).str();
+ std::string CoverageFilename =
+ formatv("{0}{1}", CoveragePrefix, sys::Process::getProcessId()).str();
std::error_code EC;
sys::fs::OpenFlags OpenFlags = sys::fs::OF_Append;
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index 04e2c3cdbcae76..4cf8c0cd9c6ea4 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -31,6 +31,8 @@
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileSystem/UniqueID.h"
+#include "llvm/Support/FormatAdapters.h"
+#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/IOSandbox.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
@@ -708,7 +710,7 @@ class InMemoryFile : public InMemoryNode {
llvm::MemoryBuffer *getBuffer() const { return Buffer.get(); }
std::string toString(unsigned Indent) const override {
- return (std::string(Indent, ' ') + Stat.getName() + "\n").str();
+ return formatv("{0}{1}\n", fmt_repeat(' ', Indent), Stat.getName()).str();
}
static bool classof(const InMemoryNode *N) {
@@ -731,8 +733,9 @@ class InMemoryHardLink : public InMemoryNode {
}
std::string toString(unsigned Indent) const override {
- return std::string(Indent, ' ') + "HardLink to -> " +
- ResolvedFile.toString(0);
+ return formatv("{0}HardLink to -> {1}", fmt_repeat(' ', Indent),
+ ResolvedFile.toString(0))
+ .str();
}
static bool classof(const InMemoryNode *N) {
@@ -750,7 +753,9 @@ class InMemorySymbolicLink : public InMemoryNode {
Stat(Stat) {}
std::string toString(unsigned Indent) const override {
- return std::string(Indent, ' ') + "SymbolicLink to -> " + TargetPath;
+ return formatv("{0}SymbolicLink to -> {1}", fmt_repeat(' ', Indent),
+ TargetPath)
+ .str();
}
Status getStatus(const Twine &RequestedName) const override {
@@ -830,7 +835,7 @@ class InMemoryDirectory : public InMemoryNode {
std::string toString(unsigned Indent) const override {
std::string Result =
- (std::string(Indent, ' ') + Stat.getName() + "\n").str();
+ formatv("{0}{1}\n", fmt_repeat(' ', Indent), Stat.getName()).str();
for (const auto &Entry : Entries)
Result += Entry.second->toString(Indent + 2);
return Result;
More information about the llvm-commits
mailing list