[clang] 448995c - [NFC] [Coroutines] Add test for ambiguous allocation functions in
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 5 23:23:59 PDT 2022
Author: Chuanqi Xu
Date: 2022-06-06T14:23:35+08:00
New Revision: 448995c521b5ccef71d063bb80f084138ac9d352
URL: https://github.com/llvm/llvm-project/commit/448995c521b5ccef71d063bb80f084138ac9d352
DIFF: https://github.com/llvm/llvm-project/commit/448995c521b5ccef71d063bb80f084138ac9d352.diff
LOG: [NFC] [Coroutines] Add test for ambiguous allocation functions in
promise_type
Address the post-commit comment in
https://reviews.llvm.org/D125517#inline-1217244
Added:
Modified:
clang/lib/Sema/SemaCoroutine.cpp
clang/test/SemaCXX/coroutine-allocs.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index 55f1c2989578d..a738befdd6cea 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -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;
diff --git a/clang/test/SemaCXX/coroutine-allocs.cpp b/clang/test/SemaCXX/coroutine-allocs.cpp
index 4ffb080c9828f..c9797208e2dc5 100644
--- a/clang/test/SemaCXX/coroutine-allocs.cpp
+++ b/clang/test/SemaCXX/coroutine-allocs.cpp
@@ -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
diff erent types}}
+ co_return;
+}
More information about the cfe-commits
mailing list