Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Modules / placement-new-reachable.cpp
blob29263173d78f458e070f41c80f7c22235a324b22
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
4 //
5 // RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
6 // RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
8 //--- placement.h
9 namespace std {
10 using size_t = decltype(sizeof(0));
12 void *operator new(std::size_t, void *p) { return p; }
14 //--- A.cppm
15 module;
16 #include "placement.h"
17 export module A;
18 export template<class T>
19 struct A {
20 A(void *p) : ptr(new (p) T(43)) {}
21 private:
22 void *ptr;
25 export struct B {
26 B(void *p) : ptr(new (p) int(43)) {}
27 private:
28 void *ptr;
31 //--- Use.cpp
32 // expected-no-diagnostics
33 import A;
34 void bar(int *);
35 void foo(void *ptr) {
36 A<int>(nullptr); // Good. It should be OK to construct A.
37 void *p = ::operator new(sizeof(int), ptr); // Bad. The function shouldn't be visible here.
38 void *q = new (ptr) int(43); // Good. We don't call the placement allocation function directly.