Commit e03a602a by Jason Merrill

tests

From-SVN: r16629
parent 858e4e8c
// GROUPS passed operator-new // GROUPS passed operator-new
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <new>
int pass = 0; int pass = 0;
void *operator new(size_t sz){ void *operator new(size_t sz) throw (std::bad_alloc) {
void *p; void *p;
......
...@@ -13,7 +13,7 @@ class B ...@@ -13,7 +13,7 @@ class B
TP _a; TP _a;
public: public:
B (A &(*f) (A &, TP), TP a) : _f (f), _a (a) {} 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> template <class TP>
......
// 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;
}
// 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;
}
// 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;
}
// 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;
}
// 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;
}
// 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. // 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" int printf (const char *, ...);
extern "C" void *malloc (size_t); extern "C" void *malloc (size_t);
size_t s; size_t s;
void * operator new (size_t siz) { void * operator new (size_t siz) throw (std::bad_alloc) {
if (s == 0) if (s == 0)
s = siz; s = siz;
else else
......
...@@ -11,7 +11,7 @@ void operator+ (int, bar&); ...@@ -11,7 +11,7 @@ void operator+ (int, bar&);
template <class T> class foo template <class T> class foo
{ {
public: public:
friend void operator+ (int, T&); friend void operator+ <> (int, T&);
}; };
class baz; class baz;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Bug: g++ fails to recognize multiple previous instantiations of a function // Bug: g++ fails to recognize multiple previous instantiations of a function
// template. // template.
// Build don't link: // Build don't link:
// Special g++ Options: -fguiding-decls
template <class T> template <class T>
class A { class A {
......
...@@ -5,7 +5,7 @@ class ostream; ...@@ -5,7 +5,7 @@ class ostream;
template <class TP> class smanip { template <class TP> class smanip {
public: public:
friend ostream& operator<<(ostream &o, const smanip<TP>&m); friend ostream& operator<< <>(ostream &o, const smanip<TP>&m);
}; };
template<class TP> template<class TP>
......
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
// Message-ID: <m0n2Vec-0000GrC@rwave.roguewave.com> // Message-ID: <m0n2Vec-0000GrC@rwave.roguewave.com>
#include <stddef.h> #include <stddef.h>
#include <new>
struct Foo { struct Foo {
friend void* operator new(size_t); friend void* operator new(size_t) throw (std::bad_alloc);
friend void operator delete(void*) throw (); friend void operator delete(void*) throw ();
Foo(); Foo();
~Foo(); ~Foo();
......
#include <iostream.h> #include <iostream.h>
#include <stddef.h> #include <stddef.h>
#include <new>
int fail = 1; int fail = 1;
static void *operator new(size_t size) { static void *operator new(size_t size) throw (std::bad_alloc) {
--fail; --fail;
return (void*) 0; return (void*) 0;
} }
......
// It checks to see if you can define your own global new operator. // It checks to see if you can define your own global new operator.
// prms-id: 755 // prms-id: 755
typedef __SIZE_TYPE__ size_t; #include <new>
extern "C" void exit(int); extern "C" void exit(int);
void* operator new(size_t sz) { void* operator new(size_t sz) throw (std::bad_alloc) {
void* p = 0; void* p = 0;
exit(0); exit(0);
return p; return p;
......
// 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()
{
}
// 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)
{
}
// 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()
{
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment