48 lines · cpp
1// RUN: rm -rf %t2// RUN: mkdir -p %t3// RUN: split-file %s %t4//5// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm6// RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t -fsyntax-only -verify7 8// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-reduced-module-interface -o %t/A.pcm9// RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t -fsyntax-only -verify10 11//--- placement.h12namespace std {13 using size_t = decltype(sizeof(0));14}15void *operator new(std::size_t, void *p) { return p; }16 17//--- A.cppm18module;19#include "placement.h"20export module A;21export template<class T>22struct A {23 A(void *p) : ptr(new (p) T(43)) {}24private:25 void *ptr;26};27 28export struct B {29 B(void *p) : ptr(new (p) int(43)) {}30private:31 void *ptr;32};33 34// The use of operator new in the current module unit is only in the non-inline35// function definitions. So it may be optimized out.36using ::operator new;37 38//--- Use.cpp39// expected-no-diagnostics40import A;41void bar(int *);42void foo(void *ptr) {43 A<int> a(nullptr); // Good. It should be OK to construct A.44 B b(nullptr);45 void *p = ::operator new(sizeof(int), ptr); // Bad. The placement allocation in module A is not visible.46 void *q = new (ptr) int(43); // Good. We don't call the placement allocation function directly.47}48