char c[64];
};
+bool started = false;
+
void*
operator new(size_t n) THROW(std::bad_alloc)
{
- static bool first = true;
- if (!first)
- throw std::bad_alloc();
- first = false;
+ if (started)
+ {
+ static bool first = true;
+ if (!first)
+ throw std::bad_alloc();
+ first = false;
+ }
+
return std::malloc(n);
}
+void
+operator delete(void* p) throw()
+{
+ if (p)
+ std::free(p);
+}
+
// http://gcc.gnu.org/ml/libstdc++/2004-10/msg00098.html
void test01()
{
int main()
{
+ started = true;
test01();
+ started = false;
}
counter& cntr = get();
cntr._M_increments = cntr._M_decrements = 0;
}
+
+ struct scope
+ {
+ scope() : _M_count(counter::count())
+ { counter::get()._M_count = 0; }
+ ~scope()
+ { counter::get()._M_count = _M_count; }
+
+ private:
+ std::size_t _M_count;
+
+#if __cplusplus >= 201103L
+ scope(const scope&) = delete;
+ scope& operator=(const scope&) = delete;
+#else
+ scope(const scope&);
+ scope& operator=(const scope&);
+#endif
+ };
};
template<typename Alloc, bool uses_global_new>
bool
check_new(Alloc a = Alloc())
{
+ __gnu_test::counter::scope s;
__gnu_test::counter::exceptions(false);
(void) a.allocate(10);
const bool __b((__gnu_test::counter::count() > 0) == uses_global_new);