Commit 26963cc3 by Robert Lipe

Addition of a whole slew of "eb" test cases generated from the egcs-bugs mailing lists.

Addition of a whole slew of "eb" test cases generated from the egcs-bugs
mailing lists.     See g++.robertl/README

From-SVN: r20107
parent 5bc80b30
// Special g++ Options: -g
// Internal compiler error on egcs 1.0.1 i586-pc-linux-gnulibc1.
// From: Max Lawson <mlawson@drfmc.ceng.cea.fr>
// Message-Id: <9803091022.AA07520@drfmc.ceng.cea.fr>
typedef unsigned int size_t;
struct dummy { };
struct arrrrrgh { };
template<class Par,class Rand = arrrrrgh>
struct whyyyyyyy { };
template<class T, class S =dummy>
struct grrrrrrrr { };
template<class Par, class Par2 =Par, class Rand =arrrrrgh>
class no_future
{
public:
template<class S>
no_future(const grrrrrrrr<whyyyyyyy<Par,Rand>*,S>& man ) { }
~no_future( ) { }
private:
no_future(const no_future&);
no_future& operator=(const no_future&);
};
int main( )
{
grrrrrrrr<whyyyyyyy<double>*> man;
no_future<double> here(man);
return 0;
}
// float mismatch. Abors on i586-pc-linux-gnulibc1 with egcs 1.0.1
// Should run smoothly. Aborts on i586-pc-linux-gnulibc1
// From: Max Lawson <mlawson@drfmc.ceng.cea.fr>
// Message-Id: <9803091022.AA07520@drfmc.ceng.cea.fr>
#include <cstdlib>
void f(double j, double& v)
{
size_t sz = size_t(2*j+1);
double norm_ = j*(j+1);
double m = j;
int sign_ = -1;
for (size_t c=1;c<=sz;++c)
for (size_t r=1;r<=sz;++r)
if (r+sign_*1 == c)
{
double val = (norm_-m*(m+sign_));
for (size_t k=1;k<2;++k)
val *= (norm_ - (m+sign_*k)*(m+sign_*(k+1)));
v = val;
}
}
int main()
{
double v;
f(1,v);
if (v != 4) abort();
return 0;
}
// Bug: Segfaults on egcs 1.0.1 i586-pc-linux-glibc1
// From: Max Lawson <mlawson@drfmc.ceng.cea.fr>
// Message-Id: <9803091022.AA07520@drfmc.ceng.cea.fr>
class S0
{
public:
S0() { };
virtual ~S0() { }
};
struct S { };
class S1 : public S, public S0
{
public:
S1() { }
};
void test_ptr(void *ctxt)
{
S0 *ctxt1 = static_cast<S0*>(ctxt);
S1* ctxt2 = dynamic_cast<S1*>(ctxt1);
}
int main()
{
S1 *ctxt = new S1();
test_ptr(ctxt);
return 0;
}
// Build don't link:
template <int object_size>
class _fixed_size_allocator
{
private:
struct something { };
static something * asdf;
public:
static void delete_object ();
};
template <class T>
class object_allocator
{
private:
typedef _fixed_size_allocator<sizeof (T)> allocator;
public:
static void deallocate (T * p)
{
allocator::delete_object (reinterpret_cast<void *> (p));
}
};
// Special g++ Options: -Wall
#include <list>
template < class N, class A >
class Base
{
public:
class NN : public N
{
friend Base<N,A>;
friend ostream& operator<<(ostream &os, const NN& n)
{
n.print(os);
return os;
}
public:
void print(ostream &os) const
{
os << "Base<N,A>::print()" << endl;
N::print(os);
}
};
typedef NN* NNPtr;
typedef list<NNPtr> NList;
typedef NList::iterator n_list_iter;
class n_iter : public n_list_iter
{
friend bool operator<(n_iter a, n_iter b)
{
return (a->ind() < b->ind());
}
friend bool operator>(n_iter a, n_iter b)
{
return (a->ind() > b->ind());
}
public:
n_iter() {}
n_iter(n_list_iter i) : n_list_iter(i) {}
NN& operator*()
{ return *n_list_iter::operator*();};
NN* operator->()
{ return n_list_iter::operator*(); }
};
private:
NList ns;
n_iter new_n_aux(NN* nd)
{
ns.push_back(nd);
n_iter nodi = --ns.end();
return (nodi);
}
public:
n_iter new_n()
{
return new_n_aux(new NN());
}
void del_n(n_iter itr)
{
NN* n = itr.operator->();
ns.erase(itr);
delete n;
}
n_iter beg_n() { return (ns.begin()); }
n_iter end_n() { return (ns.end()); }
};
template <class XN, class XA>
class YN : public XN
{
public:
YN() {};
void print(ostream& os) const
{
os << "YN<XN,XA>::print() " << endl;
XN::print(os);
}
friend ostream& operator<< (ostream& os, const YN& wn)
{
wn.print(os);
return os;
}
};
template <class XN, class XA>
class YA : public XA
{
public:
YA() {};
void print(ostream &os) const
{
os << "YA<XN,XA>::print() " << endl;
XA::print(os);
}
friend ostream& operator<<(ostream& os, const YA &wa)
{
wa.print(os);
return os;
}
};
template<class XN, class XA>
class XBase : public Base< YN<XN, XA>, YA<XN, XA> >
{
public:
typedef Base< YN<XN,XA>, YA<XN,XA> > Net;
typedef Net::n_iter n_iter;
XBase() {};
};
class MyClass
{
public:
struct ZN
{
void print(ostream &os) const
{
os << "MyClass::ZN::print()" << endl;
}
inline friend ostream& operator<<(ostream& os, const MyClass::ZN& nd)
{
nd.print(os);
return os;
}
};
struct ZA
{
void print(ostream& os) const
{
os << "MyClass::ZA::print()" << endl;
}
inline friend ostream& operator<<(ostream& os, const MyClass::ZA& ar)
{
ar.print(os);
return os;
}
};
typedef XBase<ZN,ZA> MyXBase;
typedef MyXBase::n_iter my_n_iter;
MyXBase xbase;
};
main ()
{
MyClass mine;
MyClass::my_n_iter n1, n2, n3, n4;
n1 = mine.xbase.new_n();
n2 = mine.xbase.new_n();
n3 = mine.xbase.new_n();
n4 = mine.xbase.new_n();
cout << *n1 << endl;
cout << *n2 << endl;
cout << *n3 << endl;
cout << *n4 << endl;
mine.xbase.del_n(n1);
mine.xbase.del_n(n2);
mine.xbase.del_n(n3);
mine.xbase.del_n(n4);
}
// Error: intenral compiler error on 1998/05/28 snapshot.
#include <stdio.h>
#include <stdlib.h>
void evilRises (void **ptr)
{
int *pi;
pi = new int;
*pi = 0;
*ptr = (void *)pi;
}
int main (int argc, char *argv[])
{
#ifdef WORKAROUND
union foo
#else
union
#endif
{
int a;
int b;
int c;
} *fred, barney;
evilRises((void **)&fred);
barney = *fred;
return EXIT_SUCCESS;
}
// Build don't link:
// Error: Internal compiler error in 2.7.2 & EGCS 1.0.0
template <int nlimb, int i>
inline unsigned f (unsigned* ptr);
template <int nlimb>
inline unsigned f<nlimb,nlimb> (unsigned* ptr)
{
return 1;
}
#include <string.h>
class SomeClass_t {
public:
SomeClass_t () : x (11) {}
protected:
float x;
};
class DynamicOnly_t {
public:
static DynamicOnly_t* create (const char* name = "UNDEF",
const SomeClass_t& somec = *(new SomeClass_t
())) {
return new DynamicOnly_t (name, somec);
}
DynamicOnly_t (const char* name, const SomeClass_t& somec) :
m_somec (somec) {
strncpy (m_Name, name, sizeof (m_Name));
}
private:
SomeClass_t m_somec;
char m_Name[255];
};
int main (int argc, char* argv[]) {
DynamicOnly_t* ptr = DynamicOnly_t::create ();
return 0;
}
// Build don't link:
template< class T >
void sort( T* t, int n )
{
struct
/*line5*/ {
int operator()(T i, T j)
{
return (i < j) ? -1 : ((j < i) ? 1 : 0) ;
}
} c ;
sort(t, n, c, 0) ;
}
// Special g++ Options: -O2 -fPIC
// Build don't link:
struct T
{
char* f1;
int f2;
};
void f(T*);
int g();
extern char a1[];
inline int m(int a, int b) {return b < a ? 2 : 1;}
void
h()
{
T a[10];
int i(0);
bool c;
if (c)
{
a[i++].f1 = "asf";
f(a);
i = 0;
}
a[i].f1 = &a1[1];
a[i].f2 = m(1, g());
i++;
a[i].f1 = "zxv";
a[i].f2 = 0;
}
// Build don't link:
template <class T>
struct X
{
virtual void f(int) const;
};
template <class T>
struct Y: public X<T>
{
virtual void f(int) const;
};
template <class T>
void Y<T>::f(int) const
{
}
template <>
void Y<bool>::f(int) const;
// Build don't link:
class X
{
public:
virtual void f() const = 0;
};
template <class T>
class Y: public X
{
public:
virtual void f() const;
};
template <class T>
void Y<T>::f() const
{
}
template <>
void Y<bool>::f() const;
#include<map>
#include<iostream.h>
#include<vector>
#include<string>
// empty parameter class with a minimal set of operations
// if there are no weights for edges necessary
struct Empty
{
public:
Empty(int=0) {}
bool operator<(const Empty&) const { return true;}
};
inline ostream& operator<<(ostream& os, const Empty&) { return os;}
inline istream& operator>>(istream& is, Empty& ) { return is;}
template<class VertexType, class EdgeType>
class Graph
{
public:
// public type interface
typedef map<int, EdgeType > Successor;
typedef pair<VertexType, Successor> vertex;
typedef vector<vertex> GraphType;
typedef typename GraphType::iterator iterator;
typedef typename GraphType::const_iterator const_iterator;
// a lot of stuff deleted ....
private:
bool directed;
GraphType C; // container
ostream* pOut;
}; // class Graph
// all graph-methods delet
template<class VertexType, class EdgeType>
ostream& operator<<(ostream& os, Graph<VertexType,EdgeType>& G)
{
// display of vertices with successors
for(int i = 0; i < G.size(); ++i)
{
os << G[i].first << " <";
// The compiler does not like this line!!!!!!
typename Graph<VertexType, EdgeType>::Successor::iterator
startN = G[i].second.begin(),
endN = G[i].second.end();
while(startN != endN)
{
os << G[(*startN).first].first << ' ' // vertex
<< (*startN).second << ' '; // edge value
++startN;
}
os << ">\n";
}
return os;
}
int main()
{
// no edge weighting, therefore type Empty:
Graph<string, Empty> V(true); // directed
// ReadGraph(V, "gra1.dat");
// display of vertices with successors
cout << V;
}
// Build don't link:
#define NO_META_MAX
#ifndef NO_META_MAX
template<int N1, int N2>
struct meta_max {
enum { max = (N1 > N2) ? N1 : N2 };
};
#endif
struct X {
enum {
a = 0,
n = 0
};
};
template<class T1, class T2>
struct Y {
enum {
a = T1::a + T2::a,
// NB: if the next line is changed to
// n = (T1::n > T2::n) ? T1::n : T2::n
// the problem goes away.
n = meta_max<T1::n,T2::n>::max
};
};
int z = Y<X,X>::a;
// Build don't link:
class X
{
public:
virtual void f() const = 0;
};
template <class T>
class Y: public X
{
public:
virtual void f() const;
};
template <class T>
void Y<T>::f() const
{
}
template <>
void Y<bool>::f() const;
template <>
void Y<bool>::f() const
{
}
int main() {
for(int i=1; i < 9; i++);
for(int i=1; i < 9; i++);
return 0;
}
// Build don't link:
template <class STRUCT, class MEMBER> inline STRUCT *
setback(MEMBER *bp, MEMBER STRUCT::*offset)
{
// The implementation of this function may be platform dependend
if(!bp) return 0; // NULL pointers remain NULL
union { int i; MEMBER STRUCT::*of; } u; // Switch types. Casting won't
+work.
u.of = offset;
return (STRUCT *) ((int) bp - u.i);
}
// Build don't link:
#include <iostream.h>
class X : public std::streambuf
{
} ;
#include <string.h>
class SomeClass_t {
public:
SomeClass_t () : x (11) {}
protected:
float x;
};
class DynamicOnly_t {
public:
static DynamicOnly_t* create (const char* name = "UNDEF",
const SomeClass_t& somec = *(new SomeClass_t
())) {
return new DynamicOnly_t (name, somec);
}
DynamicOnly_t (const char* name, const SomeClass_t& somec) :
m_somec (somec) {
strncpy (m_Name, name, sizeof (m_Name));
}
private:
SomeClass_t m_somec;
char m_Name[255];
};
int main (int argc, char* argv[]) {
DynamicOnly_t* ptr = DynamicOnly_t::create (); //*
return 0;
}
// Special g++ Options: -O
#include <iostream.h>
#include <typeinfo>
int main() {
int *i1, *i2;
cerr << (typeid(i1)==typeid(i2)) << endl;
}
template <class INT>
class b
{
private:
char a(int x)
{
union {
int i;
char c;
} val;
val.i = x;
return val.c;
};
public:
b() {
}
};
int main() {
b<int> n;
return 0;
}
#include <stdio.h>
#include <assert.h>
struct F {
int i;
};
F f;
int main( int, char** ) {
int F:: *of;
int *i = (int *) &of;
of = &F::i;
F *b = ((F*) ((int) &f.i - *i));
F *a = &f;
printf("%d\n", a-b);
printf("%d\n", b-a);
assert( (a-b) == -(b-a) ); // will fail with egcs-1.0
return 0;
}
#include <iostream.h>
#include <typeinfo>
template <typename T>
class A {
public:
void test ();
};
template <typename T>
void
A<T>::test(){
cerr << "test for " << typeid(*this).name() << endl;
}
// Specialization declaration
void
A<double>::test();
// Specialization definition
void
A<double>::test(){ // ============= LINE 21 ==================
cerr << "specialization for " << typeid(*this).name() << endl;
}
int
main(){
A<int> ai;
A<double> ad;
ai.test();
ad.test();
return 0;
}
template<bool B>
void f()
{
}
int main()
{
f<bool>();
}
// Build don't link:
// Error: Internal Compiler Error in 2.7.2. & egcs 1.0.0
#ifndef NO_META_MAX
template<int N1, int N2>
struct meta_max {
enum { max = (N1 > N2) ? N1 : N2 };
};
#endif
struct X {
enum {
a = 0,
n = 0
};
};
template<class T1, class T2>
struct Y {
enum {
a = T1::a + T2::a,
// NB: if the next line is changed to
// n = (T1::n > T2::n) ? T1::n : T2::n
// the problem goes away.
n = meta_max<T1::n,T2::n>::max
};
};
int z = Y<X,X>::a;
template<double functionToIntegrate(double)>
double integrate(double a, double b, int numSamplePoints)
{
// PRECONDITION(numSamplePoints > 1);
double delta = (b-a) / (numSamplePoints-1);
double sum = 0.;
for (int i=0; i < numSamplePoints; ++i)
sum += functionToIntegrate(a + i*delta);
return sum * (b-a) / numSamplePoints;
}
inline double myFunction(double x)
{
return 1 / (1 + x);
}
// Example use
int main() {
double z = integrate<myFunction>(0.0, 1.0, 50);
return 0 ;
}
// Compiles. Shouldn't.
class A {
private:
int i1_;
public:
void f(int const i1 = 1);
};
void
A::f(int const i1 = 1) // !!! SHOULD TRIGGER AN ERROR !!!
{
i1_ = i1;
}
int
main()
{
A a;
a.f();
return 0;
}
// Build don't link:
template<class foo>
class bar {
public:
void baz() { (({ while( foo::baz() );})); }
};
template<class foo>
void baz() { (({ while( foo::baz() );})); }
// Special g++ OPtions: -O2 -W
// Build don't link:
#include "stdio.h"
void writeNote() throw( int )
{
printf( "hello world\n" );
try { }
catch( int ){ throw; }
}
#include <stdexcept>
#if WORK_AROUND
typedef std::runtime_error std_runtime_error;
class X : public std_runtime_error {};
#else
class X : public std::runtime_error {};
#endif
#include <string.h>
class SomeClass_t {
public:
SomeClass_t () : x (11) {}
protected:
float x;
};
class DynamicOnly_t {
public:
static DynamicOnly_t* create (const char* name = "UNDEF",
const SomeClass_t& somec = *(new SomeClass_t
())) {
return new DynamicOnly_t (name, somec);
}
DynamicOnly_t (const char* name, const SomeClass_t& somec) :
m_somec (somec) {
strncpy (m_Name, name, sizeof (m_Name));
}
private:
SomeClass_t m_somec;
char m_Name[255];
};
int main (int argc, char* argv[]) {
DynamicOnly_t* ptr = DynamicOnly_t::create ();
return 0;
}
#include <vector>
#include<string>
using namespace std;
class ODEsolver
{
private:
void eulerODE(vector<double>& y, double& t, double& dt);
void midpointODE(vector<double>& y, double& t, double& dt);
protected:
void (ODEsolver::*useMethod)(vector<double>&, double&, double&);
void init();
public:
ODEsolver();
void timeloop(vector<double>& y, double ts, double te, double dt);
};
ODEsolver::ODEsolver()
{
init();
}
void ODEsolver::eulerODE(vector<double>& y, double& t, double& dt)
{
y[0] = dt * 2.;
}
void ODEsolver::midpointODE(vector<double>& y, double& t, double& dt)
{
y[0] = dt * 3.;
}
void ODEsolver::init()
{
ODEsolver::useMethod = ODEsolver::midpointODE;
}
void ODEsolver::timeloop(vector<double>& y, double ts, double te, double dt)
{
(ODEsolver::useMethod)(y,ts,dt);
}
int main (int nargs, char** args)
{
ODEsolver solver;
vector<double> y(2); double t_start=5.; double t_end=7.; double dt=2.;
solver.timeloop(y,t_start,t_end,dt);
cout << y[0] << endl;
return(0);
}
// Build don't link:
template<class T>
class Array {
public:
typedef T T_numtype;
};
template<class T_array>
void f(T_array, typename T_array::T_numtype)
{
}
void g()
{
f(Array<float>(), float());
}
template<int N>
struct I {
};
template<class T>
struct A {
int r;
template<class T1, class T2>
void operator()(T1, T2)
{ r = 0; }
template<int N1, int N2>
void operator()(I<N1>, I<N2>)
{ r = 1; }
};
int main()
{
A<float> x;
I<0> a;
I<1> b;
x(a,b);
if (x.r != 1)
abort();
x(float(), double());
if (x.r != 0)
abort();
return 0;
}
// Build don't link:
#include<iostream.h>
struct A {
A() {
cerr<<"A constructing\n";
throw 1;
}
void *operator new(unsigned sz) {
cerr<<"A allocated\n";
return ::operator new(sz);
}
void operator delete (void *p) {
cerr<<"A deleted\n";
::operator delete (p);
}
};
int main() {
try {
new A();
} catch (...) {
}
}
// Build don't link:
template<class T>
struct A {
typedef T T1;
};
template<class T>
struct B : T::T1 { // insert `typename' before T::T1
};
struct C { };
B<A<C> > z;
#include <stdio.h>
class A {
public:
virtual void print();
virtual A * clone();
};
class B : virtual public A {
public:
void print();
B * clone();
};
void A::print()
{
printf("A\n");
}
void B::print()
{
printf("B\n");
}
A * A::clone()
{
return this;
}
B * B::clone()
{
return this;
}
int main()
{
A * a = new B;
B * b = dynamic_cast<B *>(a);
printf("%p\n",b); // (*2*)
b->print();
a = b;
printf("%p\n",a);
a->print();
a = a->clone();
printf("%p\n",a);
a->print(); // (*1*)
return 0;
}
// Build don't link:
class C { };
void foo()
{
C c;
void * v = static_cast<void *>(c);
}
// Build don't link:
#define CRASH 1
#ifdef CRASH
#define VIRTUAL virtual
#else
#define VIRTUAL
#endif
class A {};
class B : public VIRTUAL A {};
template <class Imp> class C : public /*virtual*/ Imp {};
// define CRASH and uncomment here ^^^^^^^^^^^
// and the crash goes away!!!!
template class C<B>;
// Build don't link:
typedef unsigned int size_t;
inline void *operator new(size_t, void *place) throw() { return place; }
struct A
{
A();
~A();
};
void testfunc( void )
{
A* mybuf;
A v[1];
new (mybuf) A();
}
// Error: ICE on 2.7.2.3 and EGCS 1.0.0.
// Build don't link:
template<int N1, int N2>
struct meta_max {
enum { max = (N1 > N2) ? N1 : N2 };
};
struct X {
enum {
a = 0,
n = 0
};
};
template<class T1, class T2, class T3>
struct Y {
enum {
a = T1::a + T2::a + T3::a,
n = meta_max<meta_max<T1::n,T2::n>::max, T3::n>::max
};
};
template<class T>
struct Z {
enum {
a = T::a,
n = T::n
};
};
Z<Y<X,X,X> > z;
#include <vector>
#include <strstream.h>
/*----------------------------------------*/
struct connection_t {
connection_t() {}
};
vector<connection_t> connections;
/*----------------------------------------*/
int
main() {
ostrstream str;
connections.insert(connections.end(), connection_t());
return 0;
}
// Build don't link:
// XFAIL, doesn't.
class MyInt
{
public:
MyInt(int = 0) {}
operator int() const {return 2;}
};
bool operator==(const MyInt& a, const int& b)
{
return (int)a == b;
}
bool operator==(const MyInt& a, const MyInt& b)
{
return (int)a == (int)b;
}
bool f()
{
return 3 == MyInt();
}
// Build don't link:
class foo {
protected:
void __duplicate ();
};
class bar : public virtual foo {
protected:
void __duplicate() {
foo::__duplicate ();
}
};
class oops : public virtual bar {
protected:
void __duplicate() {
foo::__duplicate ();
}
};
// Build don't link:
#include <iostream.h>
template < class T >
class X
{
protected:
union {
int x;
double y;
};
};
template < class T >
class Y : public X<T>
{
public:
using X<T>::x;
void f () { cout << x << endl; }
};
#include <stack>
#include <vector>
int main()
{
priority_queue< int, vector<int>, greater<int> > pq;
return 0;
}
//
// egcs-2.90.06
// cannot declare friend of enclosing class using its scope, works fine
// without scope or for definition of foo::bar::f
//
class foo
{
public:
static int f();
class bar {
friend int foo::f();
// friend int f();
static int x;
public:
static int f() {return foo::f();};
};
};
int foo::f() {
return bar::x;
}
/* bug.cc */
/* simple program to demonstrate the bug with named return values in gcc
*/
/* (w) 4.9.97 by Kurt Garloff <K.Garloff@ping.de> */
#include <iostream.h>
// A simple numerical class
template <class T>
class test
{
T elem;
public:
test () { elem = 0; };
test (const T& a) { elem = a; };
test<T>& operator += (const test<T>& a) { elem += a.elem; return *this; };
friend test<T> operator + (const test<T>&, const test<T>&);
friend ostream& operator << (ostream& os, const test<T>& a)
{ return os << a.elem; };
};
#ifndef NOBUG
// named return value version
template <class T>
test<T> operator + (const test<T>& a, const test<T>& b) return c(a);
{ c += b; };
#else
// equiv. version without named ret val
template <class T>
test<T> operator + (const test<T>& a, const test<T>& b)
{ test<T> c(a); c += b; return c; };
#endif
int main()
{
test<int> x, y;
x += 5; cout << x << endl;
y = x + 2; cout << y << endl;
}
#include <vector.h>
enum s { S };
class a
{
vector<s> vs;
friend class b;
};
class b
{
vector<a> va;
operator vector< vector<s> >()
{
vector< vector<s> > vvs(va.size());
return vvs;
}
};
#include <vector.h>
enum s { S };
class a
{
vector<s> vs;
friend class b;
};
class b
{
vector<a> va;
operator vector< vector<s> >()
{
return vector< vector<s> >(va.size());
}
};
// Build don't link:
#include <complex.h>
template<class T>
class Vec {
public:
Vec() { data = new T; }
Vec<T> split() { Vec<T> tmp; operator=(tmp); return tmp; }
void operator=(const Vec<T> &v) { data = new T; }
T *data;
};
template class Vec<complex<double> >;
// Build don't link:
#include <fstream.h>
class bifstream : public ifstream {
public:
bifstream();
// ~bifstream();
};
void load_bin()
{
bifstream InFile;
if (!InFile)
return;
}
#include<iostream.h>
int main() {
try {
throw 1;
} catch(...) {
try {
throw;
} catch(int) {
}
try {
throw;
} catch(int) {
}
}
return 0;
}
// Build don't link:
class A {
public:
void malloc(unsigned int);
};
void A::malloc(unsigned int) {}
int foo() {
A a;
a.malloc(3); // <-- line 10
}
#include <fstream.h>
#include <stdio.h>
int
main()
{
printf("If you see this, you don't have a problem!\n");
#ifdef EXPOSE_BUG
ifstream a;
#endif
}
// Build don't link:
class Base {
public:
class Bar { public: virtual ~Bar() {}; };
};
class Derived : public Base {
public:
class Bar : public Base::Bar {};
};
template <class T>
class XYZ : public T::Bar {
};
void test() {
XYZ<Base> b;
XYZ<Derived> d;
}
// Build don't link:
class string
{
public:
string();
string(const string& x);
string(const char* t);
~string();
};
void set_status(string message);
class StatusDelay {
private:
string cause;
public:
StatusDelay(const string& c)
: cause(c)
{
set_status(cause);
}
~StatusDelay()
{
set_status(cause);
}
};
static char delay_message[] = "Filtering files";
static void searchRemote()
{
StatusDelay delay(delay_message);
return;
}
#include <vector>
template <typename T=float> class foo {
public:
foo();
foo(vector<int> v);
private:
vector<int> v;
T t;
};
template <typename T=float> foo<T>::foo() :v(), t() {}
template <typename T=float> foo<T>::foo(vector<int> v_) :v(v_), t() {}
foo<float> a;
// Build don't link:
template<class T>
struct A {
typedef T T1;
};
template<class T>
struct B {
typedef T T2;
};
template<class T>
struct C {
};
template<class E>
C<typename E::T2::T1>
foo (E)
{
return C<typename E::T2::T1>();
}
void test()
{
foo(B<A<int> >());
}
// Build don't link:
class string
{
public:
string();
string(const string& x);
string(const char* t);
~string();
};
void set_status(string message);
class StatusDelay {
private:
string cause;
public:
StatusDelay(const string& c)
: cause(c)
{
set_status(cause);
}
~StatusDelay()
{
set_status(cause);
}
};
static char delay_message[] = "Filtering files";
static void searchRemote()
{
StatusDelay delay(delay_message);
return;
}
// Build don't link:
#include <ctype.h>
#include <iostream.h>
// #include <streambuf.h>
#include <libio.h>
#include <strstream.h>
extern bool foo2 (ostream &out, istream &in);
bool
foo1 (ostream &out, const char *in)
{
strstreambuf sb (in, (int) strlen (in));
istream fmt (&sb);
return foo2 (out, fmt);
}
// Error: Internal Compiler Error in GCC 2.7.2 and EGCS 1998/05/28 snapshot.
#include <iostream.h>
class some_base
{
public:
class base_func_args;
virtual void func(base_func_args &) = 0;
};
class some_base::base_func_args
{
public:
int i;
};
class some_derived : public some_base
{
public:
class derived_func_args;
void func(derived_func_args &);
};
class derived_func_args : public some_base::base_func_args
{
public:
float f;
};
class some_derived::func(derived_func_args &a)
{
cout << a.i << ' ' << a.f << endl;
}
int
main()
{
some_derived d;
some_derived::derived_func_args dfa;
some_base *b = &d;
dfa.i = 10;
dfa.f = 20;
b->func(dfs);
return 0;
}
#include <complex>
void foo() {
complex<double> x(0, 0);
complex<double> y = 1.0 + x; // OK
complex<double> z = 1 + x; // line 6: <<<< 1 doesn't match double
}
#include <iostream.h>
#include <iterator.h>
#include <string>
ostream_iterator<string> oo(cout);
int main()
{
*oo = "Hello, ";
++oo;
*oo = "world!\n";
}
#define TEMPLATE 1
#include <vector.h>
#include <algo.h>
template <class T> class Expr
{
public :
Expr(){};
Expr(const T&){};
};
#ifdef TEMPLATE
template <class T >
inline bool compare(const Expr<T> a, const Expr<T> b){ return true; };
#else
inline bool compare(const Expr<int> a, const Expr<int> b){ return true; };
#endif
void main()
{
vector<int> a(3);
sort( a.begin(), a.end(), compare );
}
#include <vector.h>
#include <algo.h>
template <class T> class Expr
{
public :
Expr(){};
Expr(const T&){};
};
#ifdef TEMPLATE
template <class T >
inline bool compare(const Expr<T> a, const Expr<T> b){ return true; };
#else
inline bool compare(const Expr<int> a, const Expr<int> b){ return true; };
#endif
void main()
{
vector<int> a(3);
#if TEMPLATE == 1
sort( a.begin(), a.end(),
static_cast<bool (*)(const Expr<int>,const Expr<int>)>(compare) );
#elif TEMPLATE == 2
sort( a.begin(), a.end(), compare<int> );
#elif TEMPLATE == 3
sort<vector<int>::iterator,
pointer_to_binary_function<const Expr<int>, const Expr<int>, bool> >
( a.begin(), a.end(), compare );
#elif TEMPLATE == 4
sort( a.begin(), a.end(),
ptr_fun<const Expr<int>, const Expr<int>, bool> (compare) );
#elif TEMPLATE == 5
sort( a.begin(), a.end(),
ptr_fun(compare<int>) );
#elif TEMPLATE == 6
sort( a.begin(), a.end(),
pointer_to_binary_function<const Expr<int>, const Expr<int>, bool>(compare) );
#elif TEMPLATE == 7
sort( a.begin(), a.end(),
pointer_to_binary_function<const Expr<int>, const Expr<int>, bool>(compare<int>) );
#elif TEMPLATE == 8
sort( a.begin(), a.end(),
pointer_to_binary_function<const Expr<int>, const Expr<int>, bool>(compare<>) );
#else
sort( a.begin(), a.end(), compare );
#endif
}
// spurious 'const' in error.
#include <stdio.h>
#include <iostream.h>
template <class T>
class Vector
{
friend ostream& operator<< (ostream& out, const Vector<T> & vec);
};
template <class T>
ostream& operator<< (ostream& out, const Vector<T> & vec)
{}
template class Vector<char>;
template ostream& operator<< (ostream& out, const Vector<char> &);
main()
{
Vector<char> vc;
ostream out;
out << vc;
}
// Build don't link:
class A {};
class B : public virtual A {};
template <class Imp> class C : public Imp {};
template class C<B>;
#include <iostream.h>
class A1 {
public:
virtual void foo() {friend class B;};
};
class A2 : public virtual A1 {friend class B;};
class A3 : public virtual A1, private A2 {friend class B;};
class B
{
public:
B(A1* a) : itsA(dynamic_cast<A2*>(a)) {};
A2* itsA;
};
int main()
{
A1* a=new A3;
B b(a);
if (b.itsA) cout << "cast ok" << endl; else cout << "cast failed" << endl;
return 0;
}
/*
* Test program to isolate internal compiler error.
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream.h>
#include <fstream.h>
#include <ctype.h>
#include <vector.h>
class MESSAGE {
public:
int MessNum;
int Size;
// constructors
MESSAGE(int MN, int Sz);
MESSAGE();
};
// Make a message if message rule is triggered by event.
// Returns either a MESSAGE * (if successful) or NULL (if not).
MESSAGE *MakMessage(int ev, int sz);
int main(int argc, char **argv) {
vector<MESSAGE &> Messages;
vector<MESSAGE &>::iterator itMess;
int MN, SZ;
MN=SZ=1;
MESSAGE *Messg=MakMessage(MN,SZ);
if (Messg) Messages.push_back(*Messg);
}
// Build don't link:
char *t1 (const char *s)
{
return const_cast<char *>(s);
}
char *&t1 (const char *&s)
{
return const_cast<char *&>(s);
}
// Build don't link:
// Here we declare ::S
typedef struct s1 *S;
struct s1
{
int s;
};
struct A
{
// Here we declare A::S
typedef struct s1 *S;
};
template<class T, class U> class XX;
template<class T, class U>
class X
{
public:
static T *do_something ();
friend class T;
friend class XX<T, U>;
};
struct N
{
// Here we declare N::S
class S
{
};
// Should use N::S and A::S.
typedef X<S, A::S> X_S;
void bug ();
};
void
N::bug ()
{
// X_S is template class X<N::S, A::S>
// `s' is N::S.
S *s = X_S::do_something ();
}
// Build don't link:
enum { a, b };
class Bug {
int pri:8;
int flags:24;
public:
void bug() {
flags |= a; // this does not work
}
};
void dummy(Bug x) { x.bug(); }
struct foo { };
int f(int a, int b)
{
if (b == 0)
throw foo();
return a / b;
}
int main()
{
try {
f(0, 0);
return 0;
} catch (foo x) {
return 1;
}
}
// Build don't link:
typedef unsigned long Xv_opaque;
class DynaString
{
public:
DynaString();
DynaString( const DynaString& dynaStr );
DynaString( const long n );
~DynaString();
int operator ==( const char* const string ) const;
};
class DDE_Defaults
{
public:
DynaString GetHost();
DynaString GetService();
DynaString GetDatabase();
};
extern DDE_Defaults* ddeDefaults;
void
f()
{
DynaString tempHost, tempService, tempDatabase;
if( (tempHost = ddeDefaults->GetHost()) == 0
|| (tempService = ddeDefaults->GetService()) == 0
|| (tempDatabase = ddeDefaults->GetDatabase()) == 0
)
{
}
}
// Build don't link:
class base {
protected:
virtual void f();
};
class d1 : public virtual base {
protected:
void f();
};
void d1::f()
{
base::f();
}
class dd1 : public virtual d1 {
protected:
void f();
};
void dd1::f()
{
d1::f();
base::f();
}
class d1_and_base : public virtual d1, public virtual base {
protected:
void f();
};
void d1_and_base::f()
{
d1::f();
base::f();
}
#include <list>
main()
{
list<int&> kill_the_compiler_now(1);
}
#include <iomanip.h>
int main()
{
cout << setbase(3) << endl;
exit (0);
}
// Build don't link:
#include <strstream.h>
void
t( char* buf )
{
istrstream str = buf;
}
// Error: Internal compiler error on 1998/05/28 snapshot.
class foo {
typedef int sometype;
};
struct die : public foo::sometype {
};
// Build don't link:
#include <exception>
//using namespace std;
class A {
class B : public std::exception {}
;
};
class A {
public:
A(int i) {}
private:
A( const A & ) {}
};
main()
{
A *list = new A[10](4);
}
#define INC_FUNCTIONAL 1
#define USE_STATIC_CAST 1
#include <vector>
#include <numeric>
#ifdef INC_FUNCTIONAL
#include <functional>
#endif
template<class R> int p( int val, R& r )
{
return val + r;
}
template<class R> void f( vector<R>& v )
{
#ifdef USE_STATIC_CAST
accumulate( v.begin(), v.end(), 0, static_cast<int (*)(int, R&)>(p) );
#else
accumulate( v.begin(), v.end(), 0, p<R> );
#endif
}
main()
{
vector<int> r;
f( r );
}
// Build don't link:
class A {
public:
A() { t=0; }
double t;
};
template <class T>
class B {
public:
void f1() { new T; f2(); }
void f2() { new T; }
};
template class B<A>;
#include <string>
class t {
public:
t(const string& s) : s_(s) {}
string s_;
static t* t_;
};
t* t::t_;
t* makeT()
{
return new t("test");
return t::t_ ? t::t_ :
t::t_ = new t("test");
}
// Build don't link:
void
action0(float& arg1)
{
long cn0 = 1;
arg1 = cn0;
}
#include <vector>
void f(void)
{
vector<int> l(5, 0);
}
#include <stdio.h>
class A {
public:
A(bool b) { abort(); }
A(int a, bool b) { printf("cool\n"); }
};
main() {
A* a;
a = new A[2] = { A(1,false), A(1,false) } ;
a = new A[2](1,false);
}
// Build don't link:
template <class A>
class B:public A {
B(){}
};
template <class A>
class C:public B<A> {
C(){}
};
/*
g++ bugsol.C
bugsol.C:9: Internal compiler error.
bugsol.C:9: Please submit a full bug report to `egcs-bugs@cygnus.com'.
g++ -v
Reading specs from
/home/pierre/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.16/specs
gcc version egcs-2.90.16 971105 (gcc2-970802 experimental)
egcc compiled with gcc version 2.7.2.1 on debian 1.3.1
*/
#include <iterator>
template<size_t n, size_t i> struct PartialDotProduct {
template<class T>
static T Expand(T* a, T* b) { return T(); }
};
const int N = 10;
template<class In1, class In2>
typename iterator_traits<In1>::value_type
dot(In1 f1, In2 f2)
{
return PartialDotProduct<N, 0>::Expand(f1, f2); // line 14
}
int main()
{
double a[N], b[N];
double s = dot(&a[0], &b[0]);
}
#include <assert.h>
#include <iostream.h>
int bar ()
{
throw 100;
}
main ()
{
int i = 0;
try
{
i = bar ();
}
catch (...)
{
}
// cout << "i = " << i << endl;
assert (i == 0) ;
}
// Build don't link:
/*
The 971114 "gcc/cp/parse.y" doesn't properly identify non-aggregate
types used as base classes.
First, the rule:
base_class: base_class_access_list see_typename base_class.1
uses "IS_AGGR_TYPE" instead of "is_aggr_type" to check "base_class.1",
so no error is reported for code like:
*/
typedef int an_int;
class bar : public an_int {};
// Error: Internal Compiler Error.
class foo {
typedef int an_int;
};
class bar : foo::an_int {}; // causes internal compiler error
#include <iostream.h>
struct foo {
foo(int x) { cerr << "foo's int constructor (" << x << ")\n"; };
};
struct bar : foo {
typedef int an_int;
bar() : bar::an_int(3) {}; // will call foo::foo(3)
};
main() { bar b; }
// Build don't link:
#include <vector>
class T
{
public:
T();
};
vector <T> tp;
void f()
{
tp.insert(tp.begin(), 10 , T());
}
// Build don't link:
class X {
public:
inline operator bool() const { return true; }
};
class Y : public X {
private:
inline operator void*() const { return 0; }
};
void f(Y const& y) {
if( bool(y) ) {
}
}
// Build don't link:
typedef unsigned int size_t;
class A {
public:
void operator delete(void*, size_t);
void* operator new(size_t);
};
class B : public A {
friend class D;
B();
unsigned counter;
};
class D {
int ins( B*&);
};
int
D::ins( B*& tempN)
{
unsigned i;
if (i == 10) {
}
else {
}
tempN = new B();
tempN->counter = 20;
return 0;
}
#include <vector>
template <class T>
class TPROGRAM
{
typedef vector< T > ITEMS;
class const_iterator
{
/*typename*/ ITEMS::const_iterator i;
const_iterator(const /*typename*/ ITEMS::const_iterator i2) {
i=i2;
}
};
};
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