| 1 |
// { dg-do assemble } |
| 2 |
// { dg-options "-Wno-deprecated -Wno-return-type" } |
| 3 |
// { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } } |
| 4 |
/* bug.cc */ |
| 5 |
/* simple program to demonstrate the bug with named return values in gcc |
| 6 |
*/ |
| 7 |
/* (w) 4.9.97 by Kurt Garloff <[email protected]> */ |
| 8 |
// 8/28/1998 - This dies in add_conversions from dfs_walk, null CLASSTYPE_METHOD_VEC |
| 9 |
// for the test<T> record_type. This is marked as an expected failure for now, |
| 10 |
// until we actually fix it. |
| 11 |
|
| 12 |
#include <iostream> |
| 13 |
|
| 14 |
template <class T> class test; |
| 15 |
template <class T> test<T> operator + (const test<T>& a, const test<T>& b); |
| 16 |
|
| 17 |
// A simple numerical class |
| 18 |
template <class T> |
| 19 |
class test |
| 20 |
{ |
| 21 |
T elem; |
| 22 |
public: |
| 23 |
test () { elem = 0; }; |
| 24 |
test (const T& a) { elem = a; }; |
| 25 |
test<T>& operator += (const test<T>& a) { elem += a.elem; return *this; }; |
| 26 |
friend test<T> operator + <> (const test<T>&, const test<T>&); |
| 27 |
friend std::ostream& operator << (std::ostream& os, const test<T>& a) |
| 28 |
{ return os << a.elem; }; |
| 29 |
}; |
| 30 |
|
| 31 |
// named return value version |
| 32 |
template <class T> |
| 33 |
test<T> operator + (const test<T>& a, const test<T>& b) return c(a);// { dg-error "" } named return value |
| 34 |
{ c += b; } // { dg-error "" } c undeclared |
| 35 |
|
| 36 |
int main() |
| 37 |
{ |
| 38 |
test<int> x, y; |
| 39 |
x += 5; |
| 40 |
std::cout << x << std::endl; |
| 41 |
y = x + test<int>(2); |
| 42 |
std::cout << y << std::endl; |
| 43 |
return 0; |
| 44 |
} |