// GROUPS passed operator-new
#include <stdio.h>
#include <stdlib.h>
+#include <new>
int pass = 0;
-void *operator new(size_t sz){
+void *operator new(size_t sz) throw (std::bad_alloc) {
void *p;
TP _a;
public:
B (A &(*f) (A &, TP), TP a) : _f (f), _a (a) {}
- friend A &operator<< (A &o, const B<TP> &m);
+ friend A &operator<< <>(A &o, const B<TP> &m);
};
template <class TP>
--- /dev/null
+// Test for calling placement delete.
+
+#include <new>
+#include <stddef.h>
+
+int r = 1;
+
+struct A {
+ A() { throw 1; }
+ void operator delete (void *p, int, int) { r = 0; ::operator delete (p); }
+};
+
+void * operator new (size_t size, int, int) { return operator new (size); }
+
+main ()
+{
+ try {
+ A* ap = new (1, 5) A;
+ } catch (...) { }
+
+ return r;
+}
--- /dev/null
+// Test for not calling mismatched placement delete.
+
+#include <new>
+#include <stddef.h>
+
+int r = 0;
+
+struct A {
+ A() { throw 1; }
+ void operator delete (void *p, int, long) { r = 1; ::operator delete (p); }
+};
+
+void * operator new (size_t size, int, int) { return operator new (size); }
+
+main ()
+{
+ try {
+ A* ap = new (1, 5) A;
+ } catch (...) { }
+
+ return r;
+}
--- /dev/null
+// Testing exception specifications.
+// Test 1: the original exception succeeds.
+
+#include <stdlib.h>
+#include <exception>
+
+void my_term () { exit (1); }
+void my_unexp () { throw 42; }
+
+void
+f () throw (char, int, bad_exception)
+{
+ throw 'a';
+}
+
+main ()
+{
+ set_terminate (my_term);
+ set_unexpected (my_unexp);
+
+ try
+ {
+ f ();
+ }
+ catch (char)
+ {
+ return 0;
+ }
+ catch (int)
+ {
+ return 3;
+ }
+ catch (bad_exception)
+ {
+ return 4;
+ }
+ return 5;
+}
--- /dev/null
+// Testing exception specifications.
+// Test 2: the second throw succeeds.
+
+#include <stdlib.h>
+#include <exception>
+
+void my_term () { exit (1); }
+void my_unexp () { throw 42; }
+
+void
+f () throw (int, bad_exception)
+{
+ throw 'a';
+}
+
+main ()
+{
+ set_terminate (my_term);
+ set_unexpected (my_unexp);
+
+ try
+ {
+ f ();
+ }
+ catch (char)
+ {
+ return 2;
+ }
+ catch (int)
+ {
+ return 0;
+ }
+ catch (bad_exception)
+ {
+ return 4;
+ }
+ return 5;
+}
--- /dev/null
+// Testing exception specifications.
+// Test 3: the bad_exception throw succeeds.
+
+#include <stdlib.h>
+#include <exception>
+
+void my_term () { exit (1); }
+void my_unexp () { throw 42; }
+
+void
+f () throw (bad_exception)
+{
+ throw 'a';
+}
+
+main ()
+{
+ set_terminate (my_term);
+ set_unexpected (my_unexp);
+
+ try
+ {
+ f ();
+ }
+ catch (char)
+ {
+ return 2;
+ }
+ catch (int)
+ {
+ return 3;
+ }
+ catch (bad_exception)
+ {
+ return 0;
+ }
+ return 5;
+}
--- /dev/null
+// Testing exception specifications.
+// Test 4: all throws fail, call terminate.
+
+#include <stdlib.h>
+#include <exception>
+
+void my_term () { exit (0); }
+void my_unexp () { throw 42; }
+
+void
+f () throw (short)
+{
+ throw 'a';
+}
+
+main ()
+{
+ set_terminate (my_term);
+ set_unexpected (my_unexp);
+
+ try
+ {
+ f ();
+ }
+ catch (char)
+ {
+ return 2;
+ }
+ catch (int)
+ {
+ return 3;
+ }
+ catch (bad_exception)
+ {
+ return 4;
+ }
+ return 5;
+}
// Bug: new doesn't make sure that the count is an integral value.
-typedef __SIZE_TYPE__ size_t;
+#include <new>
extern "C" int printf (const char *, ...);
extern "C" void *malloc (size_t);
size_t s;
-void * operator new (size_t siz) {
+void * operator new (size_t siz) throw (std::bad_alloc) {
if (s == 0)
s = siz;
else
template <class T> class foo
{
public:
- friend void operator+ (int, T&);
+ friend void operator+ <> (int, T&);
};
class baz;
// Bug: g++ fails to recognize multiple previous instantiations of a function
// template.
// Build don't link:
+// Special g++ Options: -fguiding-decls
template <class T>
class A {
template <class TP> class smanip {
public:
- friend ostream& operator<<(ostream &o, const smanip<TP>&m);
+ friend ostream& operator<< <>(ostream &o, const smanip<TP>&m);
};
template<class TP>
// Message-ID: <m0n2Vec-0000GrC@rwave.roguewave.com>
#include <stddef.h>
+#include <new>
struct Foo {
- friend void* operator new(size_t);
+ friend void* operator new(size_t) throw (std::bad_alloc);
friend void operator delete(void*) throw ();
Foo();
~Foo();
#include <iostream.h>
#include <stddef.h>
+#include <new>
int fail = 1;
-static void *operator new(size_t size) {
+static void *operator new(size_t size) throw (std::bad_alloc) {
--fail;
return (void*) 0;
}
// It checks to see if you can define your own global new operator.
// prms-id: 755
-typedef __SIZE_TYPE__ size_t;
+#include <new>
extern "C" void exit(int);
-void* operator new(size_t sz) {
+void* operator new(size_t sz) throw (std::bad_alloc) {
void* p = 0;
exit(0);
return p;
--- /dev/null
+// Build don't link:
+
+template <class T>
+struct A
+{
+ typedef T A_Type;
+};
+
+
+template <class U>
+struct B : public A<U>
+{
+};
+
+
+template <class U>
+struct C : public B<U>
+{
+ A_Type Func();
+};
+
+
+template <class U>
+C<U>::A_Type C<U>::Func()
+{
+}
--- /dev/null
+// Build don't link:
+
+template <class T>
+struct A
+{
+ typedef T A_Type;
+};
+
+
+template <class U>
+struct B : public A<U>
+{
+};
+
+
+template <class U>
+struct C : public B<U>
+{
+ void Func(A_Type);
+};
+
+
+template <class U>
+void C<U>::Func(A_Type)
+{
+}
--- /dev/null
+// Build don't link:
+
+template <class T>
+struct A
+{
+ typedef T A_Type;
+};
+
+
+template <class U>
+struct B : public A<U>
+{
+ A_Type Func();
+};
+
+
+template <class U>
+A<U>::A_Type B<U>::Func()
+{
+}