inject-templated-friend.cpp revision 65cf05d21ca22320deef11862f93f9a85ec62bb9
1// RUN: %clang %s -S -emit-llvm -o - | grep -e "define linkonce_odr.*_ZlsR11std_ostreamRK8StreamerI3FooE" 2// RUN: %clang_cc1 %s -DREDEFINE -verify 3// PR8007: friend function not instantiated. 4 5struct std_ostream 6{ 7 int dummy; 8}; 9 10std_ostream cout; 11 12template <typename STRUCT_TYPE> 13struct Streamer 14{ 15 friend std_ostream& operator << (std_ostream& o, const Streamer& f) // expected-error{{redefinition of 'operator<<'}} 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 28typedef struct Foo {} Foo; 29 30std_ostream& operator << (std_ostream&, const Streamer<Foo>&); 31#ifdef REDEFINE 32std_ostream& operator << (std_ostream& o, const Streamer<Foo>&) // expected-note{{is here}} 33{ 34 // Sema should flag this as a redefinition 35 return o; 36} 37#endif 38 39template <> 40void Streamer<Foo>::operator () (std_ostream& o) const // expected-note{{requested here}} 41{ 42} 43 44int main(void) 45{ 46 Foo foo; 47 cout << foo; 48} 49