Commit 122d34f6 by Jason Merrill

fix

From-SVN: r20235
parent 47103f59
// 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;
}
// 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);
}
#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;
}
......@@ -3,7 +3,7 @@ class A {
private:
int i1_;
public:
void f(int const i1 = 1); // ERROR -
void f(int const i1 = 1); // ERROR - previous specification
};
void
......@@ -19,4 +19,3 @@ main()
a.f();
return 0;
}
// Gets ICE 40.
#include <vector>
#include<string>
......
......@@ -6,18 +6,23 @@
class foo
{
public:
static int f();
class bar {
friend int foo::f();
// friend int f();
static int x;
public:
static int f();
class bar {
friend int foo::f();
// friend int f();
static int x;
public:
static int f() {return foo::f();};
static int f() {return foo::f();};
};
};
int foo::f() {
return bar::x;
return bar::x;
}
int
main ()
{
return foo::bar::f ();
}
......@@ -2,9 +2,13 @@
/* simple program to demonstrate the bug with named return values in gcc
*/
/* (w) 4.9.97 by Kurt Garloff <K.Garloff@ping.de> */
// Special g++ Options:
#include <iostream.h>
template <class T> class test;
template <class T> test<T> operator + (const test<T>& a, const test<T>& b);
// A simple numerical class
template <class T>
class test
......@@ -14,29 +18,19 @@ class test
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 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;
y = x + test<int>(2); cout << y << endl;
}
#include <vector>
// Build don't link:
template <typename T=float> class foo {
public:
foo();
foo(vector<int> v);
private:
vector<int> v;
T t;
};
#include <vector>
template <typename T=float> foo<T>::foo() :v(), t() {}
template <typename T=float> foo<T>::foo(vector<int> v_) :v(v_), t() {}
template <typename T=float> class foo {
public:
foo();
foo(vector<int> v);
private:
vector<int> v;
T t;
};
foo<float> a;
template <typename T>
foo<T>::foo() :v(), t() {}
template <typename T=float> // ERROR - default parm for member template
foo<T>::foo(vector<int> v_) :v(v_), t() {}
foo<float> a;
#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
}
// Build don't link:
// conversion ops should be treated as coming from the most derived class
// for overload resolution. See [over.match.funcs].
// Build don't link:
class X {
public:
......@@ -11,7 +13,6 @@ private:
};
void f(Y const& y) {
if( bool(y) ) {
}
int f(Y const& y) {
return bool(y);
}
#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;
}
};
};
//Build don't link:
// from include/g++/stl_relops.h
template <class T>
inline bool operator!=(const T& x, const T& y) {
return !(x == y);
}
// the template operator!= interferes. It should be in a namespace.
#include <utility>
enum T {
V1
......
class foo
{
public:
static int f();
class bar {
friend int foo::f();
};
};
int main()
{
return 0;
}
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