Fix https://github.com/llvm/llvm-project/issues/56532 Effectively, this reverts behavior introduced in https://reviews.llvm.org/D117087, which did two things: 1. Change delayed to early conversion of return object. 2. Introduced RVO possibilities because of early conversion. This patches fixes (1) and removes (2). I already worked on a follow up for (2) in a separated patch. I believe it's important to split these two because if the RVO causes any problems we can explore reverting (2) while maintaining (1). Notes on some testcase changes: - `pr59221.cpp` changed to `-O1` so we can check that the front-end honors the value checked for. Sounds like `-O3` without RVO is more likely to work with LLVM optimizations... - Comment out delete members `coroutine-no-move-ctor.cpp` since behavior now requires copies again. Differential Revision: https://reviews.llvm.org/D145639
62 lines
1.2 KiB
C++
62 lines
1.2 KiB
C++
// RUN: %clang_cc1 -std=c++20 %s -fcxx-exceptions -fsyntax-only -Wexceptions -verify -fdeclspec
|
|
|
|
#include "Inputs/std-coroutine.h"
|
|
|
|
// expected-no-diagnostics
|
|
|
|
template <typename T>
|
|
struct promise;
|
|
|
|
template <typename T>
|
|
struct task {
|
|
using promise_type = promise<T>;
|
|
|
|
explicit task(promise_type& p) { throw 1; p.return_val = this; }
|
|
|
|
T value;
|
|
};
|
|
|
|
template <typename T>
|
|
struct promise {
|
|
task<T> get_return_object() { return task{*this}; }
|
|
|
|
std::suspend_never initial_suspend() const noexcept { return {}; }
|
|
|
|
std::suspend_never final_suspend() const noexcept { return {}; }
|
|
|
|
template <typename U>
|
|
void return_value(U&& val) { return_val->value = static_cast<U&&>(val); }
|
|
|
|
void unhandled_exception() { throw 1; }
|
|
|
|
task<T>* return_val;
|
|
};
|
|
|
|
task<int> a_ShouldNotDiag(const int a, const int b) {
|
|
if (b == 0)
|
|
throw b;
|
|
|
|
co_return a / b;
|
|
}
|
|
|
|
task<int> b_ShouldNotDiag(const int a, const int b) noexcept {
|
|
if (b == 0)
|
|
throw b;
|
|
|
|
co_return a / b;
|
|
}
|
|
|
|
const auto c_ShouldNotDiag = [](const int a, const int b) -> task<int> {
|
|
if (b == 0)
|
|
throw b;
|
|
|
|
co_return a / b;
|
|
};
|
|
|
|
const auto d_ShouldNotDiag = [](const int a, const int b) noexcept -> task<int> {
|
|
if (b == 0)
|
|
throw b;
|
|
|
|
co_return a / b;
|
|
};
|