Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Support] add move operations to raw_ostream #85134

Closed
wants to merge 1 commit into from

Conversation

s-mx
Copy link

@s-mx s-mx commented Mar 13, 2024

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);
}

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);
}
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 13, 2024

@llvm/pr-subscribers-llvm-support

Author: Sabianin Maksim (s-mx)

Changes

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);
}


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

1 Files Affected:

  • (modified) llvm/include/llvm/Support/raw_ostream.h (+2)
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();
 

@s-mx s-mx changed the title [Support] add move operators to raw_ostream [Support] add move operations to raw_ostream Mar 13, 2024
@s-mx
Copy link
Author

s-mx commented Mar 13, 2024

My initial desire was to add move operations to raw_fd_ostream. However, I've just realised that my patch is insufficient for that and I need to do it more careful and raw_fd_ostream should have a concrete implementation instead of default one.

@dwblaikie
Copy link
Collaborator

this'll need unit test coverage too, fwiw

@s-mx s-mx closed this Apr 11, 2024
@s-mx s-mx deleted the edit_raw_ostream branch April 11, 2024 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants