[llvm] [Support] add move operators to raw_ostream (PR #85134)

Sabianin Maksim via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 14:33:45 PDT 2024


https://github.com/s-mx created https://github.com/llvm/llvm-project/pull/85134

Copy constructor/operator= were explicitly deleted. Hence, move constructor/operator= were left implicitly deleted. This patch declares them by default and allows the following code to be compiled.

raw_fd_ostream openStream(StringRef Path) {
    std::error_code EC;
    raw_fd_ostream OS(Path, EC);
    // handle errors here
    return std::move(OS);
}

>From 2253ff2fa438611727baaebf6b79dc7208d6318f Mon Sep 17 00:00:00 2001
From: Maksim Sabianin <sabyanin.mx at gmail.com>
Date: Wed, 13 Mar 2024 22:20:13 +0100
Subject: [PATCH] [Support] add move operators to raw_ostream

Copy constructor/operator= were explicitly deleted.
Hence, move constructor/operator= were left implicitly deleted.
This patch declares them by default and allows the following code to be compiled.

raw_fd_ostream openStream(StringRef Path) {
  std::error_code EC;
  raw_fd_ostream OS(Path, EC);
  // handle errors here
  return std::move(OS);
}
---
 llvm/include/llvm/Support/raw_ostream.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 696290a5d99cf5..de6d6f1e0b006c 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -143,6 +143,8 @@ class raw_ostream {
 
   raw_ostream(const raw_ostream &) = delete;
   void operator=(const raw_ostream &) = delete;
+  raw_ostream(raw_ostream &&) = default;
+  raw_ostream &operator=(raw_ostream &&) = default;
 
   virtual ~raw_ostream();
 



More information about the llvm-commits mailing list