blob: 39c445ca0f996ec70a62ce550c05845fe2bb64af [file] [log] [blame]
Gabor Greif4d99a3d2010-08-28 12:12:45 +00001// RUN: %clang %s -S -emit-llvm -o - | grep -e "define linkonce_odr.*_ZlsR11std_ostreamRK8StreamerI3FooE"
Gabor Greifab297ac2010-08-30 21:10:05 +00002// RUN: %clang %s -S -emit-llvm -o - -DPROTOTYPE | grep -e "define linkonce_odr.*_ZlsR11std_ostreamRK8StreamerI3FooE"
Gabor Greifd304fe62010-08-30 21:45:06 +00003// RUN: %clang %s -S -emit-llvm -o - -DINSTANTIATE | grep -e "define linkonce_odr.*_ZlsR11std_ostreamRK8StreamerI3FooE"
4// RUN: %clang %s -S -emit-llvm -o - -DPROTOTYPE -DINSTANTIATE | grep -e "define linkonce_odr.*_ZlsR11std_ostreamRK8StreamerI3FooE"
Chandler Carruthf56017f2010-11-13 10:19:35 +00005// RUN: %clang_cc1 %s -DREDEFINE -verify
6// RUN: %clang_cc1 %s -DPROTOTYPE -DREDEFINE -verify
Gabor Greif4d99a3d2010-08-28 12:12:45 +00007// PR8007: friend function not instantiated, reordered version.
8// Corresponds to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38392
Gabor Greif4d99a3d2010-08-28 12:12:45 +00009
10struct std_ostream
11{
12 int dummy;
13};
14
15std_ostream cout;
16
17template <typename STRUCT_TYPE>
18struct Streamer;
19
20typedef struct Foo {} Foo;
21
22std_ostream& operator << (std_ostream&, const Streamer<Foo>&);
Gabor Greifab297ac2010-08-30 21:10:05 +000023
Gabor Greif4d99a3d2010-08-28 12:12:45 +000024void test(const Streamer<Foo>& foo)
25{
26 cout << foo;
27}
28
29template <typename STRUCT_TYPE>
30struct Streamer
31{
32 friend std_ostream& operator << (std_ostream& o, const Streamer& f) // expected-error{{redefinition of 'operator<<'}}
33 {
34 Streamer s(f);
35 s(o);
36 return o;
37 }
38
39 Streamer(const STRUCT_TYPE& s) : s(s) {}
40
41 const STRUCT_TYPE& s;
42 void operator () (std_ostream&) const;
43};
44
Gabor Greifab297ac2010-08-30 21:10:05 +000045#ifdef PROTOTYPE
46std_ostream& operator << (std_ostream&, const Streamer<Foo>&);
47#endif
48
49#ifdef INSTANTIATE
50template struct Streamer<Foo>;
51#endif
52
53#ifdef REDEFINE
54std_ostream& operator << (std_ostream& o, const Streamer<Foo>&) // expected-note{{is here}}
55{
56 return o;
57}
58#endif
59
Gabor Greifd304fe62010-08-30 21:45:06 +000060#ifndef INSTANTIATE
Gabor Greif4d99a3d2010-08-28 12:12:45 +000061template <>
62void Streamer<Foo>::operator () (std_ostream& o) const // expected-note{{requested here}}
63{
64}
Gabor Greifd304fe62010-08-30 21:45:06 +000065#endif
Gabor Greif4d99a3d2010-08-28 12:12:45 +000066
67int main(void)
68{
69 Foo foo;
70 test(foo);
71}
72