| 1 | // { dg-do run { target c++17 } } |
| 2 | |
| 3 | #include <map> |
| 4 | #include <cstdlib> |
| 5 | |
| 6 | bool oom = false; |
| 7 | |
| 8 | void* operator new(std::size_t n) |
| 9 | { |
| 10 | if (oom) |
| 11 | throw std::bad_alloc(); |
| 12 | return std::malloc(n); |
| 13 | } |
| 14 | |
| 15 | void operator delete(void* p) noexcept |
| 16 | { |
| 17 | std::free(p); |
| 18 | } |
| 19 | |
| 20 | void operator delete(void* p, std::size_t) noexcept |
| 21 | { |
| 22 | std::free(p); |
| 23 | } |
| 24 | |
| 25 | int main() |
| 26 | { |
| 27 | std::map<int, int> m; |
| 28 | int i = 0; |
| 29 | (void) m[i]; |
| 30 | oom = true; |
| 31 | m.emplace(i, 1); |
| 32 | m.emplace(i, 2L); |
| 33 | const int c = 3; |
| 34 | m.emplace(i, c); |
| 35 | m.emplace((long)i, 4); |
| 36 | } |