[NFC] [Coroutines] Add test for ambiguous allocation functions in

promise_type

Address the post-commit comment in
https://reviews.llvm.org/D125517#inline-1217244
This commit is contained in:
Chuanqi Xu 2022-06-06 14:11:59 +08:00
parent f06abbb393
commit 448995c521
2 changed files with 29 additions and 7 deletions

View File

@ -1324,7 +1324,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
bool PassAlignment = false;
SmallVector<Expr *, 1> PlacementArgs;
bool PromiseContainNew = [this, &PromiseType]() -> bool {
bool PromiseContainsNew = [this, &PromiseType]() -> bool {
DeclarationName NewName =
S.getASTContext().DeclarationNames.getCXXOperatorName(OO_New);
LookupResult R(S, NewName, Loc, Sema::LookupOrdinaryName);
@ -1343,7 +1343,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
// - If no declarations are found in the scope of the promise type, a search
// is performed in the global scope.
Sema::AllocationFunctionScope NewScope =
PromiseContainNew ? Sema::AFS_Class : Sema::AFS_Global;
PromiseContainsNew ? Sema::AFS_Class : Sema::AFS_Global;
S.FindAllocationFunctions(Loc, SourceRange(),
NewScope,
/*DeleteScope*/ Sema::AFS_Both, PromiseType,
@ -1354,7 +1354,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
// We don't expect to call to global operator new with (size, p0, …, pn).
// So if we choose to lookup the allocation function in global scope, we
// shouldn't lookup placement arguments.
if (PromiseContainNew && !collectPlacementArgs(S, FD, Loc, PlacementArgs))
if (PromiseContainsNew && !collectPlacementArgs(S, FD, Loc, PlacementArgs))
return false;
LookupAllocationFunction();
@ -1363,7 +1363,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
// If no viable function is found ([over.match.viable]), overload resolution
// is performed again on a function call created by passing just the amount of
// space required as an argument of type std::size_t.
if (!OperatorNew && !PlacementArgs.empty() && PromiseContainNew) {
if (!OperatorNew && !PlacementArgs.empty() && PromiseContainsNew) {
PlacementArgs.clear();
LookupAllocationFunction();
}
@ -1386,7 +1386,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
}
if (!OperatorNew) {
if (PromiseContainNew)
if (PromiseContainsNew)
S.Diag(Loc, diag::err_coroutine_unusable_new) << PromiseType << &FD;
return false;

View File

@ -19,7 +19,7 @@ struct resumable {
};
};
resumable f1() { // expected-error {{'operator new' provided by 'std::coroutine_traits<resumable>::promise_type' (aka 'resumable::promise_type') is not usable}}
resumable f1() { // expected-error {{'operator new' provided by 'std::coroutine_traits<resumable>::promise_type' (aka 'resumable::promise_type') is not usable with the function signature of 'f1'}}
co_return;
}
@ -37,7 +37,7 @@ resumable f1() { // expected-error {{'operator new' provided by 'std::coroutine_
// The first argument is the amount of space requested, and has type std::size_­t.
// The lvalues p1…pn are the succeeding arguments.
//
// So the acctual type passed to resumable::promise_type::operator new is lvalue
// So the actual type passed to resumable::promise_type::operator new is lvalue
// Allocator. It is allowed to convert a lvalue to a lvalue reference. So the
// following one is valid.
resumable f2(Allocator &&) {
@ -59,3 +59,25 @@ resumable f5(const Allocator) { // expected-error {{operator new' provided by 's
resumable f6(const Allocator &) { // expected-error {{operator new' provided by 'std::coroutine_traits<resumable, const Allocator &>::promise_type' (aka 'resumable::promise_type') is not usable}}
co_return;
}
struct promise_base1 {
void *operator new(std::size_t sz); // expected-note {{member found by ambiguous name lookup}}
};
struct promise_base2 {
void *operator new(std::size_t sz); // expected-note {{member found by ambiguous name lookup}}
};
struct resumable2 {
struct promise_type : public promise_base1, public promise_base2 {
resumable2 get_return_object() { return {}; }
auto initial_suspend() { return std::suspend_always(); }
auto final_suspend() noexcept { return std::suspend_always(); }
void unhandled_exception() {}
void return_void(){};
};
};
resumable2 f7() { // expected-error {{member 'operator new' found in multiple base classes of different types}}
co_return;
}