Gabor Greif | 19de06b | 2010-08-28 00:45:56 +0000 | [diff] [blame] | 1 | // RUN: %clang %s -S -emit-llvm -o - | grep -e "define linkonce_odr.*_ZlsR11std_ostreamRK8StreamerI3FooE" |
Chandler Carruth | f56017f | 2010-11-13 10:19:35 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 %s -DREDEFINE -verify |
Gabor Greif | bb452e9 | 2010-08-28 00:48:36 +0000 | [diff] [blame] | 3 | // PR8007: friend function not instantiated. |
Gabor Greif | c620ace | 2010-08-27 23:39:49 +0000 | [diff] [blame] | 4 | |
| 5 | struct std_ostream |
| 6 | { |
| 7 | int dummy; |
| 8 | }; |
| 9 | |
| 10 | std_ostream cout; |
| 11 | |
| 12 | template <typename STRUCT_TYPE> |
| 13 | struct Streamer |
| 14 | { |
Gabor Greif | aaafddb | 2010-08-28 02:00:22 +0000 | [diff] [blame] | 15 | friend std_ostream& operator << (std_ostream& o, const Streamer& f) // expected-error{{redefinition of 'operator<<'}} |
Gabor Greif | c620ace | 2010-08-27 23:39:49 +0000 | [diff] [blame] | 16 | { |
| 17 | Streamer s(f); |
| 18 | s(o); |
| 19 | return o; |
| 20 | } |
| 21 | |
| 22 | Streamer(const STRUCT_TYPE& s) : s(s) {} |
| 23 | |
| 24 | const STRUCT_TYPE& s; |
| 25 | void operator () (std_ostream&) const; |
| 26 | }; |
| 27 | |
| 28 | typedef struct Foo {} Foo; |
| 29 | |
Gabor Greif | aaafddb | 2010-08-28 02:00:22 +0000 | [diff] [blame] | 30 | std_ostream& operator << (std_ostream&, const Streamer<Foo>&); |
| 31 | #ifdef REDEFINE |
| 32 | std_ostream& operator << (std_ostream& o, const Streamer<Foo>&) // expected-note{{is here}} |
Gabor Greif | c620ace | 2010-08-27 23:39:49 +0000 | [diff] [blame] | 33 | { |
| 34 | // Sema should flag this as a redefinition |
Gabor Greif | aaafddb | 2010-08-28 02:00:22 +0000 | [diff] [blame] | 35 | return o; |
| 36 | } |
| 37 | #endif |
Gabor Greif | c620ace | 2010-08-27 23:39:49 +0000 | [diff] [blame] | 38 | |
| 39 | template <> |
Gabor Greif | aaafddb | 2010-08-28 02:00:22 +0000 | [diff] [blame] | 40 | void Streamer<Foo>::operator () (std_ostream& o) const // expected-note{{requested here}} |
Gabor Greif | c620ace | 2010-08-27 23:39:49 +0000 | [diff] [blame] | 41 | { |
| 42 | } |
| 43 | |
Gabor Greif | c620ace | 2010-08-27 23:39:49 +0000 | [diff] [blame] | 44 | int main(void) |
| 45 | { |
Gabor Greif | c620ace | 2010-08-27 23:39:49 +0000 | [diff] [blame] | 46 | Foo foo; |
| 47 | cout << foo; |
| 48 | } |