[llvm] [Diagnostics] Return rvalue reference from temporary argument (PR #127400)
Jakub Kuderski via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 12 11:39:56 PDT 2025
================
@@ -613,93 +613,47 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
/// common base class. This allows returning the result of the insertion
/// directly by value, e.g. return OptimizationRemarkAnalysis(...) << "blah".
template <class RemarkT>
-RemarkT &
-operator<<(RemarkT &R,
- std::enable_if_t<
- std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
- StringRef>
- S) {
+decltype(auto) operator<<(
+ RemarkT &&R,
+ std::enable_if_t<std::is_base_of<DiagnosticInfoOptimizationBase,
+ std::remove_reference_t<RemarkT>>::value,
+ StringRef>
+ S) {
R.insert(S);
- return R;
+ return std::forward<RemarkT>(R);
}
-/// Also allow r-value for the remark to allow insertion into a
-/// temporarily-constructed remark.
template <class RemarkT>
-RemarkT &&
-operator<<(RemarkT &&R,
- std::enable_if_t<
- std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
- StringRef>
- S) {
- R.insert(S);
- return std::move(R);
-}
-
-template <class RemarkT>
-RemarkT &
-operator<<(RemarkT &R,
- std::enable_if_t<
- std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
- DiagnosticInfoOptimizationBase::Argument>
- A) {
- R.insert(A);
- return R;
-}
-
-template <class RemarkT>
-RemarkT &&
-operator<<(RemarkT &&R,
- std::enable_if_t<
- std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
- DiagnosticInfoOptimizationBase::Argument>
- A) {
+decltype(auto) operator<<(
+ RemarkT &&R,
+ std::enable_if_t<std::is_base_of<DiagnosticInfoOptimizationBase,
+ std::remove_reference_t<RemarkT>>::value,
+ DiagnosticInfoOptimizationBase::Argument>
+ A) {
R.insert(A);
- return std::move(R);
+ return std::forward<RemarkT>(R);
}
template <class RemarkT>
-RemarkT &
-operator<<(RemarkT &R,
- std::enable_if_t<
- std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
- DiagnosticInfoOptimizationBase::setIsVerbose>
- V) {
+decltype(auto) operator<<(
+ RemarkT &&R,
+ std::enable_if_t<std::is_base_of<DiagnosticInfoOptimizationBase,
+ std::remove_reference_t<RemarkT>>::value,
+ DiagnosticInfoOptimizationBase::setIsVerbose>
+ V) {
R.insert(V);
- return R;
-}
-
-template <class RemarkT>
-RemarkT &&
-operator<<(RemarkT &&R,
- std::enable_if_t<
- std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
- DiagnosticInfoOptimizationBase::setIsVerbose>
- V) {
- R.insert(V);
- return std::move(R);
-}
-
-template <class RemarkT>
-RemarkT &
-operator<<(RemarkT &R,
- std::enable_if_t<
- std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
- DiagnosticInfoOptimizationBase::setExtraArgs>
- EA) {
- R.insert(EA);
- return R;
+ return std::forward<RemarkT>(R);
}
template <class RemarkT>
-RemarkT &&
-operator<<(RemarkT &&R,
- std::enable_if_t<
- std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
- DiagnosticInfoOptimizationBase::setExtraArgs>
- EA) {
+decltype(auto) operator<<(
+ RemarkT &&R,
+ std::enable_if_t<std::is_base_of<DiagnosticInfoOptimizationBase,
+ std::remove_reference_t<RemarkT>>::value,
----------------
kuhar wrote:
```suggestion
std::enable_if_t<std::is_base_of_v<DiagnosticInfoOptimizationBase,
std::remove_reference_t<RemarkT>>,
```
https://github.com/llvm/llvm-project/pull/127400
More information about the llvm-commits
mailing list