1 // Tests that the implicit declared allocation functions
2 // are attached to the global module fragment.
5 // RUN: split-file %s %t
7 // RUN: %clang_cc1 -std=c++20 %t/foo.cppm -fsyntax-only -verify
8 // RUN: %clang_cc1 -std=c++20 %t/foo2.cppm -fsyntax-only -verify
12 export void alloc_wrapper() {
13 void *a = ::operator new(32);
14 // [basic.stc.dynamic.general]Note2
15 // The implicit declarations do not introduce the names std, std::size_t,
16 // std::align_val_t, ..., However, referring to std or std::size_t or
17 // std::align_val_t is ill-formed unless a standard library declaration
18 // ([cstddef.syn], [new.syn], [std.modules]) of that name precedes
19 // ([basic.lookup.general]) the use of that name.
20 void *b = ::operator new((std::size_t)32); // expected-error {{use of undeclared identifier 'std'}}
21 void *c = ::operator new((std::size_t)32, // expected-error {{use of undeclared identifier 'std'}}
22 (std::align_val_t)64); // expected-error {{use of undeclared identifier 'std'}}
25 ::operator delete(b, (std::size_t)32); // expected-error {{use of undeclared identifier 'std'}}
26 ::operator delete(c, (std::size_t)32, // expected-error {{use of undeclared identifier 'std'}}
27 (std::align_val_t)64); // expected-error {{use of undeclared identifier 'std'}}
32 using size_t = decltype(sizeof(0));
33 enum class align_val_t : size_t {};
36 [[nodiscard]] void *operator new(std::size_t);
37 [[nodiscard]] void *operator new(std::size_t, std::align_val_t);
38 [[nodiscard]] void *operator new[](std::size_t);
39 [[nodiscard]] void *operator new[](std::size_t, std::align_val_t);
40 void operator delete(void*) noexcept;
41 void operator delete(void*, std::size_t) noexcept;
42 void operator delete(void*, std::align_val_t) noexcept;
43 void operator delete(void*, std::size_t, std::align_val_t) noexcept;
44 void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
45 void operator delete[](void*, std::size_t) noexcept;
46 void operator delete[](void*, std::align_val_t) noexcept;
47 void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
50 // expected-no-diagnostics
54 export void alloc_wrapper() {
55 void *a = ::operator new(32);
56 void *b = ::operator new((std::size_t)32);
57 void *c = ::operator new((std::size_t)32,
58 (std::align_val_t)64);
61 ::operator delete(b, (std::size_t)32);
62 ::operator delete(c, (std::size_t)32,
63 (std::align_val_t)64);