summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2022-09-06 14:56:58 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2022-09-06 14:57:01 +0800
commitf65f06d63f6a0e40c33a9d77eeb381f1b2a8a524 (patch)
treef6038a795001fddeb2bed1bc620f02f0b690a7fd
parent495419628bbab1a99cfc00d0c44b877bfc8e4a14 (diff)
[NFC] [Coroutines] Add tests for looking up deallocation
According to [dcl.fct.def.coroutine]p12, the program should be ill-formed if the promise_type contains operator delete but none of them are available. But this behavior was not tested before. This commit adds the tests for it.
-rw-r--r--clang/test/SemaCXX/coroutine-dealloc.cpp27
-rw-r--r--clang/test/SemaCXX/coroutine-no-valid-dealloc.cpp26
2 files changed, 53 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/coroutine-dealloc.cpp b/clang/test/SemaCXX/coroutine-dealloc.cpp
new file mode 100644
index 000000000000..6eca1e6f42f8
--- /dev/null
+++ b/clang/test/SemaCXX/coroutine-dealloc.cpp
@@ -0,0 +1,27 @@
+// Tests that the behavior will be good if there are multiple operator delete in the promise_type.
+// RUN: %clang_cc1 %s -std=c++20 %s -fsyntax-only -verify
+// expected-no-diagnostics
+
+#include "Inputs/std-coroutine.h"
+
+namespace std {
+ typedef __SIZE_TYPE__ size_t;
+ enum class align_val_t : size_t {};
+}
+
+struct task {
+ struct promise_type {
+ auto initial_suspend() { return std::suspend_always{}; }
+ auto final_suspend() noexcept { return std::suspend_always{}; }
+ auto get_return_object() { return task{}; }
+ void unhandled_exception() {}
+ void return_value(int) {}
+
+ void operator delete(void *ptr, void *meaningless_placeholder);
+ void operator delete(void *ptr);
+ };
+};
+
+task f() {
+ co_return 43;
+}
diff --git a/clang/test/SemaCXX/coroutine-no-valid-dealloc.cpp b/clang/test/SemaCXX/coroutine-no-valid-dealloc.cpp
new file mode 100644
index 000000000000..a5727d6f003b
--- /dev/null
+++ b/clang/test/SemaCXX/coroutine-no-valid-dealloc.cpp
@@ -0,0 +1,26 @@
+// Test that if the compiler will emit error message if the promise_type contain
+// operator delete but none of them are available. This is required by the standard.
+// RUN: %clang_cc1 %s -std=c++20 %s -fsyntax-only -verify
+
+#include "Inputs/std-coroutine.h"
+
+namespace std {
+ typedef __SIZE_TYPE__ size_t;
+ enum class align_val_t : size_t {};
+}
+
+struct task {
+ struct promise_type {
+ auto initial_suspend() { return std::suspend_always{}; }
+ auto final_suspend() noexcept { return std::suspend_always{}; }
+ auto get_return_object() { return task{}; }
+ void unhandled_exception() {}
+ void return_value(int) {}
+
+ void operator delete(void *ptr, void *meaningless_placeholder); // expected-note {{member 'operator delete' declared here}}
+ };
+};
+
+task f() { // expected-error 1+{{no suitable member 'operator delete' in 'promise_type'}}
+ co_return 43;
+}