OSDN Git Service

update
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.robertl / eb27.C
1 /* bug.cc */
2 /* simple program to demonstrate the bug with named return values in gcc
3 */
4 /* (w) 4.9.97 by Kurt Garloff <K.Garloff@ping.de> */
5 // Special g++ Options:
6 // excess errors test - XFAIL *-*-*
7
8 #include <iostream.h>
9
10 template <class T> class test;
11 template <class T> test<T> operator + (const test<T>& a, const test<T>& b);
12
13 // A simple numerical class
14 template <class T>
15 class test
16 {
17    T elem;
18  public:
19    test ()  { elem = 0; };
20    test (const T& a)  { elem = a; };
21    test<T>& operator += (const test<T>& a)  { elem += a.elem; return *this; };
22    friend test<T> operator + <> (const test<T>&, const test<T>&);
23    friend ostream& operator << (ostream& os, const test<T>& a)
24      { return os << a.elem; };
25 };
26
27 // named return value version
28 template <class T>
29 test<T> operator + (const test<T>& a, const test<T>& b) return c(a);
30 { c += b; };
31
32 int main()
33 {
34    test<int> x, y;
35    x += 5; cout << x << endl;
36    y = x + test<int>(2); cout << y << endl;
37 }