// g++ 1.37.1 bug 900404_04
-// The ANSI C does not allow vacuous statements (i.e. just semicolons)
-// at the file-scope level.
-
-// The current C++ Reference Manual does not indicate whether these should
-// be considered legal or not.
-
-// I am forced to conclude that C++ will follow ANSI C in this regard,
-// and that these are therefore not legal.
+// [dcl.dcl] explains that simple-declarations may omit the
+// init-declarator-list only if the decl-specifier-seq declares a
+// class, i.e. if it contains a class-specifier, an
+// elaborated-type-specifier with class key, or an enum-specifier. The
+// declaration below contains neither.
// g++ fails to flag errors for such usage.
main ()
{
- set_terminate (&eh_terminate);
+ std::set_terminate (&eh_terminate);
eh_test (0);
}
void my_unexp () { throw 42; }
void
-f () throw (char, int, bad_exception)
+f () throw (char, int, std::bad_exception)
{
throw 'a';
}
main ()
{
- set_terminate (my_term);
- set_unexpected (my_unexp);
+ std::set_terminate (my_term);
+ std::set_unexpected (my_unexp);
try
{
{
return 3;
}
- catch (bad_exception)
+ catch (std::bad_exception)
{
return 4;
}
void my_unexp () { throw 42; }
void
-f () throw (int, bad_exception)
+f () throw (int, std::bad_exception)
{
throw 'a';
}
main ()
{
- set_terminate (my_term);
- set_unexpected (my_unexp);
+ std::set_terminate (my_term);
+ std::set_unexpected (my_unexp);
try
{
{
return 0;
}
- catch (bad_exception)
+ catch (std::bad_exception)
{
return 4;
}
void my_unexp () { throw 42; }
void
-f () throw (bad_exception)
+f () throw (std::bad_exception)
{
throw 'a';
}
main ()
{
- set_terminate (my_term);
- set_unexpected (my_unexp);
+ std::set_terminate (my_term);
+ std::set_unexpected (my_unexp);
try
{
{
return 3;
}
- catch (bad_exception)
+ catch (std::bad_exception)
{
return 0;
}
main ()
{
- set_terminate (my_term);
- set_unexpected (my_unexp);
+ std::set_terminate (my_term);
+ std::set_unexpected (my_unexp);
try
{
{
return 3;
}
- catch (bad_exception)
+ catch (std::bad_exception)
{
return 4;
}
#include <iostream.h>
#include <vector>
+
+using std::vector;
class Component {
int george;
exit(0);
}
-template class __malloc_alloc_template<0>;
-template class __default_alloc_template<false, 0>;
+template class std::__malloc_alloc_template<0>;
+template class std::__default_alloc_template<false, 0>;
main() {
double f (int);
- const type_info &r = typeid (f);
+ const std::type_info &r = typeid (f);
cout << typeid(f).name() << endl;
cout << typeid(foo::f).name() << endl;
}
extern "C" int printf( const char *, ...);
-void * operator new(size_t, const nothrow_t&) throw() { FLAG=1; return 0; }
+void * operator new(size_t, const std::nothrow_t&) throw() { FLAG=1; return 0; }
class K {
private:
int main(void)
{
- K * pK = new (nothrow) K( 10);
+ K * pK = new (std::nothrow) K( 10);
if ( FLAG != 1 )
printf ("FAIL\n");
else
B b;
try {
(void)dynamic_cast<D&>(b);
- } catch (bad_cast) {
+ } catch (std::bad_cast) {
return 0;
}
return 1;
try {
void *vp = &dynamic_cast<D&>(*b);
return 1;
- } catch (bad_cast) {
+ } catch (std::bad_cast) {
return 0;
}
return 1;
try {
B b;
x (b);
- } catch (exception& e) {
+ } catch (std::exception& e) {
// If we get a bad_cast, it is wrong.
return 1;
}
}
main() {
- set_terminate (my_terminate);
+ std::set_terminate (my_terminate);
try {
bar();
} catch (...) {
struct A {
A() { }
~A() {
- set_terminate (my_terminate);
+ std::set_terminate (my_terminate);
throw 1; // This throws from EH dtor, should call my_terminate
}
};
foo() throw (int) { throw "Hi"; }
main() {
- set_unexpected (my_unexpected);
+ std::set_unexpected (my_unexpected);
try {
foo();
} catch (int i) {
foo() throw () { throw "Hi"; }
main() {
- set_unexpected (my_unexpected);
+ std::set_unexpected (my_unexpected);
foo();
return 1;
}
} catch (...) {
}
try {
- set_terminate (myterm);
+ std::set_terminate (myterm);
throw;
} catch (...) {
return 1;
// excess errors test - XFAIL a29k-*-* sparc64-*-elf sh-*-* arm-*-pe**-*
#include <exception>
-
+using std::uncaught_exception;
class A {
public:
~A() {
template <class T> int foo(T) throw (int) { throw "Hi"; }
main() {
- set_unexpected (my_unexpected);
+ std::set_unexpected (my_unexpected);
try {
foo(1);
} catch (int i) {
template <class T> int foo(T) throw (T) { throw "Hi"; }
main() {
- set_unexpected (my_unexpected);
+ std::set_unexpected (my_unexpected);
try {
foo(1);
} catch (int i) {
}
int main() {
- set_terminate(my_terminate_handler);
+ std::set_terminate(my_terminate_handler);
throw_an_unexpected_exception();
return 1;
}
-// excess errors test - XFAIL *-*-*
class Foo {
};
// Build don't link:
-// excess errors test - XFAIL *-*-*
namespace N {
struct C {
// Build don't link:
-// excess errors test - XFAIL *-*-*
namespace Jazz {
int horn( int h ) { return 1; }
-// excess errors test - XFAIL *-*-*
namespace Foo {
bar() {
return 0;
--- /dev/null
+namespace foo{
+ int eine_funktion(int)
+ {
+ return 0;
+ }
+}
+
+namespace foo{
+ void eine_funktion(int,int)
+ {}
+}
+
+namespace bar = foo;
+
+int main()
+{
+ return bar::eine_funktion(3);
+}
--- /dev/null
+// Build don't link:
+class ostream;
+extern ostream cout;
+namespace foo
+{
+ struct S
+ {
+ int i;
+ };
+
+ extern ostream &operator<<(ostream &, const S &);
+}
+
+
+void bar(foo::S s)
+{
+ cout << s ;
+}
--- /dev/null
+// Build don't link:
+typedef int __quad_t;
+typedef __quad_t __qaddr_t;
--- /dev/null
+// Build don't link:
+template <class charT>
+struct basic_string
+{
+ charT append (charT c)
+ { return c; }
+};
+typedef char c;
+template class basic_string <char>;
--- /dev/null
+namespace foo{
+ int eine_funktion(int)
+ {
+ return 0;
+ }
+
+ int eine_funktion(int,int)
+ {
+ return 1;
+ }
+}
+
+main(int,char**)
+{
+ return foo::eine_funktion(1);
+}
--- /dev/null
+//Build don't link:
+namespace bb
+{
+ int f(int);
+
+ namespace k
+ {
+ void foo(int bar)
+ {
+ int i=bb:f(bar); // ERROR - namespace
+ }
+ }
+}
--- /dev/null
+// Build don't link
+// Check [namespace.memdef]/2
+
+namespace A{
+ void f(int);
+ void f(int,int);
+ int i; // ERROR - .*
+}
+
+void A::f(){} // ERROR - should have been declared before
+
+namespace B{
+ void A::f(int){} // ERROR - B does not surround A
+}
+
+int A::i; // ERROR - redefinition
+
+void A::f(int,int){} // ok
+
--- /dev/null
+namespace fred
+{
+ int barney();
+ extern int wilma;
+}
+
+int fred::barney()
+{
+ return fred::wilma;
+}
+
+int fred::wilma;
+
+int barney()
+{
+ return 1;
+}
+
+main()
+{
+ return fred::barney();
+}
--- /dev/null
+namespace foo{
+ struct X{
+ int i;
+ void f();
+ static int k1,k2;
+ };
+ void X::f(){}
+ int var;
+ int X::k1;
+}
+
+using namespace foo;
+X zzz;
+int X::k2;
+
+void andere_funktion()
+{
+ zzz.f();
+ var=4;
+}
+
+main(int,char**)
+{
+ andere_funktion();
+ return 0;
+}
--- /dev/null
+// Build don't link:
+namespace foo{
+ void eine_funktion(int)
+ {}
+}
+
+using namespace foo;
+
+namespace foo{
+ void eine_funktion(int,int)
+ {}
+}
+
+void andere_funktion()
+{
+ eine_funktion(3,4);
+}
--- /dev/null
+// Build don't link:
+namespace A{
+ enum foo{a,b,c};
+}
+using A::foo;
+using A::b;
+void g()
+{
+ foo x;
+ x=b;
+}
--- /dev/null
+// Build don't link:
+namespace X{
+ class Y{};
+}
+
+X::Y z;
--- /dev/null
+namespace A{
+ int i;
+ namespace B{
+ void f(){i++;}
+ int i;
+ void g(){i++;}
+ }
+}
+
+main()
+{
+ return A::i-A::B::i;
+}
--- /dev/null
+// Build don't link:
+namespace A{
+ struct X{
+ int i;
+ X(){}
+ X(int j);
+ void operator=(const X&);
+ virtual ~X(){}
+ };
+ void X::operator=(const X&o)
+ {
+ i=o.i;
+ }
+}
+
+A::X::X(int j):i(j){}
+
+namespace A{
+ struct Y:public X{
+ int j;
+ Y(int,int);
+ };
+}
+
+A::Y::Y(int a,int b):X(a),j(b)
+{}
--- /dev/null
+// Build don't link:
+namespace B{
+ void f();
+}
+
+using namespace B;
+
+void g()
+{
+ ::f();
+}
--- /dev/null
+// Build don't link:
+namespace bb
+{
+ int f(int);
+
+ namespace k
+ {
+ void foo(int bar)
+ {
+ return bb:f(bar); //ERROR - syntax error
+ }
+ }
+}
--- /dev/null
+// Unqualified lookup should find all functions.
+// Duplicates are ignored as long as they lose during overload resolution.
+namespace A{
+ int f(){
+ return 1;
+ }
+ int f(double);
+}
+namespace B{
+ int f(int){
+ return 2;
+ }
+ int f(double);
+}
+
+int f(int,int)
+{
+ return 3;
+}
+
+using namespace A;
+using namespace B;
+
+main()
+{
+ if(f() != 1)
+ return 1;
+ if(f(1) != 2)
+ return 1;
+ if(f(0,0) != 3)
+ return 1;
+ return 0;
+}
--- /dev/null
+namespace A{
+ void f(); // ERROR - .*
+}
+
+using namespace A;
+
+void f(); // ERROR - .*
+
+void g()
+{
+ f(); // ERROR - ambiguous, ::f or A::f ?
+}
--- /dev/null
+// Build don't link:
+// Declarations after the first one don't affect the set of used decls.
+
+namespace A{
+ void f(); // ERROR - .*
+}
+
+using A::f;
+
+namespace A{
+ void f(int);
+}
+
+using A::f;
+
+void g()
+{
+ f(4); // ERROR - too many arguments
+}
--- /dev/null
+// Build don't link:
+namespace A{
+ void f(); // ERROR - .*
+}
+
+using A::f;
+void f(); // ERROR - duplicate declaration
+
--- /dev/null
+// Build don't link:
+namespace A{
+ void f(){} // ERROR - previous declaration
+}
+
+using A::f;
+
+void f(int);
+void f(){} // ERROR - conflict
+
+void g()
+{
+ f(4);
+}
--- /dev/null
+// Build don't link:
+namespace foo {
+
+ template <class T>
+ class x {};
+
+}
+
+foo::x<int> y;
--- /dev/null
+//Build don't link:
+//Inheritance from templates which are namespace members
+namespace foo {
+
+ template <class T>
+ struct x {
+ x(){}
+ };
+
+}
+
+class y : public foo::x<int> {};
+
+y r;
--- /dev/null
+// Build don't link:
+using namespace bb; // ERROR - .*
+
--- /dev/null
+// Build don't link:
+void f();
+namespace A{
+ using ::f;
+}
--- /dev/null
+extern "C" int printf(char*, ...);
+
+int c, d;
+class Foo
+{
+public:
+ Foo() { printf("Foo() 0x%08lx\n", (unsigned long)this); ++c; }
+ Foo(Foo const &) { printf("Foo(Foo const &) 0x%08lx\n", (unsigned long)this); }
+ ~Foo() { printf("~Foo() 0x%08lx\n", (unsigned long)this); ++d; }
+};
+
+// Bar creates constructs a temporary Foo() as a default
+class Bar
+{
+public:
+ Bar(Foo const & = Foo()) { printf("Bar(Foo const &) 0x%08lx\n", (unsigned long)this); }
+};
+
+void fakeRef(Bar *)
+{
+}
+
+int main()
+{
+ // Create array of Bar. Will use default argument on constructor.
+ // The old compiler will loop constructing Bar. Each loop will
+ // construct a temporary Foo() but will not destruct the Foo().
+ // The Foo() temporary is destructed only once after the loop
+ // completes. This could lead to a memory leak if the constructor
+ // of Foo() allocates memory.
+ Bar bar[2];
+
+ fakeRef(bar);
+
+ printf("Done\n");
+
+ if (c == d && c == 2)
+ return 0;
+ return 1;
+}
--- /dev/null
+// Build don't link:
+
+template<class X, class Z>
+class foo
+{
+public:
+ typedef X y;
+
+ class bar {
+ public:
+ void blah () { y Y; }
+ };
+};