aboutsummaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/coroutine-alloc-4.cpp
blob: 262c163fb17897b105d48911699ee9d88587c86e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Tests that we'll find aligned allocation function properly.
// RUN: %clang_cc1 %s -std=c++20 %s -fsyntax-only -verify -fcoro-aligned-allocation

#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 new(std::size_t); // expected-warning 1+{{under -fcoro-aligned-allocation, the non-aligned allocation function for the promise type 'f' has higher precedence than the global aligned allocation function}}
  };
};

task f() {
    co_return 43;
}

struct task2 {
  struct promise_type {
    auto initial_suspend() { return std::suspend_always{}; }
    auto final_suspend() noexcept { return std::suspend_always{}; }
    auto get_return_object() { return task2{}; }
    void unhandled_exception() {}
    void return_value(int) {}
    void *operator new(std::size_t, std::align_val_t);
  };
};

// no diagnostic expected
task2 f1() {
    co_return 43;
}

struct task3 {
  struct promise_type {
    auto initial_suspend() { return std::suspend_always{}; }
    auto final_suspend() noexcept { return std::suspend_always{}; }
    auto get_return_object() { return task3{}; }
    void unhandled_exception() {}
    void return_value(int) {}
    void *operator new(std::size_t, std::align_val_t) noexcept;
    void *operator new(std::size_t) noexcept;
    static auto get_return_object_on_allocation_failure() { return task3{}; }
  };
};

// no diagnostic expected
task3 f2() {
    co_return 43;
}

struct task4 {
  struct promise_type {
    auto initial_suspend() { return std::suspend_always{}; }
    auto final_suspend() noexcept { return std::suspend_always{}; }
    auto get_return_object() { return task4{}; }
    void unhandled_exception() {}
    void return_value(int) {}
    void *operator new(std::size_t, std::align_val_t, int, double, int) noexcept;
  };
};

// no diagnostic expected
task4 f3(int, double, int) {
    co_return 43;
}

struct task5 {
  struct promise_type {
    auto initial_suspend() { return std::suspend_always{}; }
    auto final_suspend() noexcept { return std::suspend_always{}; }
    auto get_return_object() { return task5{}; }
    void unhandled_exception() {}
    void return_value(int) {}
  };
};

// no diagnostic expected.
// The aligned allocation will be declared by the compiler.
task5 f4() {
    co_return 43;
}

namespace std {
  struct nothrow_t {};
  constexpr nothrow_t nothrow = {};
}

struct task6 {
  struct promise_type {
    auto initial_suspend() { return std::suspend_always{}; }
    auto final_suspend() noexcept { return std::suspend_always{}; }
    auto get_return_object() { return task6{}; }
    void unhandled_exception() {}
    void return_value(int) {}
    static task6 get_return_object_on_allocation_failure() { return task6{}; }
  };
};

task6 f5() { // expected-error 1+{{unable to find '::operator new(size_t, align_val_t, nothrow_t)' for 'f5'}}
    co_return 43;
}

void *operator new(std::size_t, std::align_val_t, std::nothrow_t) noexcept; 

task6 f6() {
    co_return 43;
}