blob: f0f287ce144de178fb4a15e9d81a24945d01b6ca [file] [log] [blame]
Hans Wennborgc9bd88e2014-01-14 19:35:09 +00001// RUN: %clang_cc1 %s -emit-llvm -triple %itanium_abi_triple -o - | FileCheck %s
Chandler Carruth456daba2010-11-13 10:19:35 +00002// RUN: %clang_cc1 %s -DREDEFINE -verify
Gabor Greif73ddbc52010-08-28 00:48:36 +00003// PR8007: friend function not instantiated.
Gabor Greifa56984c2010-08-27 23:39:49 +00004
Hans Wennborg9125b082014-01-13 19:48:13 +00005// CHECK: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE
6
Gabor Greifa56984c2010-08-27 23:39:49 +00007struct std_ostream
8{
9 int dummy;
10};
11
12std_ostream cout;
13
14template <typename STRUCT_TYPE>
15struct Streamer
16{
Gabor Greif468aa3b2010-08-28 02:00:22 +000017 friend std_ostream& operator << (std_ostream& o, const Streamer& f) // expected-error{{redefinition of 'operator<<'}}
Gabor Greifa56984c2010-08-27 23:39:49 +000018 {
19 Streamer s(f);
20 s(o);
21 return o;
22 }
23
24 Streamer(const STRUCT_TYPE& s) : s(s) {}
25
26 const STRUCT_TYPE& s;
27 void operator () (std_ostream&) const;
28};
29
30typedef struct Foo {} Foo;
31
David Majnemeree4f4022014-03-30 06:44:54 +000032inline std_ostream& operator << (std_ostream&, const Streamer<Foo>&);
Gabor Greif468aa3b2010-08-28 02:00:22 +000033#ifdef REDEFINE
34std_ostream& operator << (std_ostream& o, const Streamer<Foo>&) // expected-note{{is here}}
Gabor Greifa56984c2010-08-27 23:39:49 +000035{
36 // Sema should flag this as a redefinition
Gabor Greif468aa3b2010-08-28 02:00:22 +000037 return o;
38}
39#endif
Gabor Greifa56984c2010-08-27 23:39:49 +000040
41template <>
Gabor Greif468aa3b2010-08-28 02:00:22 +000042void Streamer<Foo>::operator () (std_ostream& o) const // expected-note{{requested here}}
Gabor Greifa56984c2010-08-27 23:39:49 +000043{
44}
45
Gabor Greifa56984c2010-08-27 23:39:49 +000046int main(void)
47{
Gabor Greifa56984c2010-08-27 23:39:49 +000048 Foo foo;
49 cout << foo;
50}