|
| 1 | +//type:rp |
| 2 | +//options_all:--gnu_version=150000 --set_flag=no_checking_pragmas |
| 3 | +//options:--g++:--clang |
| 4 | +inline void *operator new(decltype(sizeof 0), void *p) noexcept { return p; } |
| 5 | +int deletes; |
| 6 | +inline void operator delete(void *, void *) noexcept { ++deletes; } |
| 7 | + |
| 8 | +struct A { A(); }; |
| 9 | +// The code generated for Alloc::construct calls setjmp, to call the placement |
| 10 | +// operator delete if the constructor throws. |
| 11 | +struct Alloc { void construct(A *p) { ::new ((void *)p) A(); } }; |
| 12 | +struct Alloc2 { Alloc a; void construct(A *p) { a.construct(p); } }; |
| 13 | + |
| 14 | +[[gnu::always_inline]] inline void tconstruct(Alloc &a, A *p) { |
| 15 | + a.construct(p); |
| 16 | +} |
| 17 | + |
| 18 | +[[gnu::always_inline]] static inline void sconstruct(Alloc &a, A *p) { |
| 19 | + a.construct(p); // Previously gave a gcc error. |
| 20 | +} |
| 21 | + |
| 22 | +[[gnu::always_inline]] static inline void s2construct(Alloc2 &a, A *p) { |
| 23 | + a.construct(p); // Previously gave a gcc error. |
| 24 | +} |
| 25 | + |
| 26 | +void f(Alloc &a, A *p) { tconstruct(a, p); } |
| 27 | +void g(Alloc &a, A *p) { sconstruct(a, p); } |
| 28 | +void h(Alloc2 &a, A *p) { s2construct(a, p); } |
| 29 | + |
| 30 | +A::A() { throw 1; } |
| 31 | + |
| 32 | +int main() { |
| 33 | + alignas(A) unsigned char buf[sizeof(A)]; |
| 34 | + A *p = (A *)buf; |
| 35 | + Alloc a; |
| 36 | + Alloc2 a2; |
| 37 | + try { f(a, p); } catch (int) {} |
| 38 | + try { g(a, p); } catch (int) {} |
| 39 | + try { h(a2, p); } catch (int) {} |
| 40 | + return deletes == 3 ? 0 : 1; |
| 41 | +} |
0 commit comments