From-SVN: r16629
This commit is contained in:
Jason Merrill 1997-11-20 23:05:13 -05:00
parent 858e4e8cfd
commit e03a602a7d
18 changed files with 282 additions and 10 deletions

View file

@ -1,10 +1,11 @@
// 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;

View file

@ -13,7 +13,7 @@ class B
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>

View file

@ -0,0 +1,22 @@
// 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;
}

View file

@ -0,0 +1,22 @@
// 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;
}

View file

@ -0,0 +1,38 @@
// 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;
}

View file

@ -0,0 +1,38 @@
// 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;
}

View file

@ -0,0 +1,38 @@
// 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;
}

View file

@ -0,0 +1,38 @@
// 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;
}

View file

@ -1,11 +1,11 @@
// 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

View file

@ -11,7 +11,7 @@ void operator+ (int, bar&);
template <class T> class foo
{
public:
friend void operator+ (int, T&);
friend void operator+ <> (int, T&);
};
class baz;

View file

@ -2,6 +2,7 @@
// 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 {

View file

@ -5,7 +5,7 @@ class ostream;
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>

View file

@ -7,8 +7,9 @@
// 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();

View file

@ -1,9 +1,10 @@
#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;
}

View file

@ -1,10 +1,10 @@
// 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;

View file

@ -0,0 +1,26 @@
// 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()
{
}

View file

@ -0,0 +1,26 @@
// 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)
{
}

View file

@ -0,0 +1,20 @@
// 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()
{
}