1651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s 2651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - -DPROTOTYPE | FileCheck --check-prefix=CHECK-PROTOTYPE %s 3651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - -DINSTANTIATE | FileCheck --check-prefix=CHECK-INSTANTIATE %s 4651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - -DPROTOTYPE -DINSTANTIATE | FileCheck --check-prefix=CHECK-PROTOTYPE-INSTANTIATE %s 5f56017fd93236bfc34d3e5b5c31b8d40a5d75808Chandler Carruth// RUN: %clang_cc1 %s -DREDEFINE -verify 6f56017fd93236bfc34d3e5b5c31b8d40a5d75808Chandler Carruth// RUN: %clang_cc1 %s -DPROTOTYPE -DREDEFINE -verify 74d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif// PR8007: friend function not instantiated, reordered version. 84d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif// Corresponds to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38392 94d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 10651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE 11651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-PROTOTYPE: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE 12651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-INSTANTIATE: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE 13651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-PROTOTYPE-INSTANTIATE: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE 14651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 154d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greifstruct std_ostream 164d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif{ 174d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif int dummy; 184d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif}; 194d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 204d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greifstd_ostream cout; 214d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 224d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greiftemplate <typename STRUCT_TYPE> 234d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greifstruct Streamer; 244d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 254d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greiftypedef struct Foo {} Foo; 264d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 27651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesinline std_ostream& operator << (std_ostream&, const Streamer<Foo>&); 28ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif 294d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greifvoid test(const Streamer<Foo>& foo) 304d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif{ 314d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif cout << foo; 324d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif} 334d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 344d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greiftemplate <typename STRUCT_TYPE> 354d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greifstruct Streamer 364d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif{ 374d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif friend std_ostream& operator << (std_ostream& o, const Streamer& f) // expected-error{{redefinition of 'operator<<'}} 384d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif { 394d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif Streamer s(f); 404d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif s(o); 414d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif return o; 424d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif } 434d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 444d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif Streamer(const STRUCT_TYPE& s) : s(s) {} 454d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 464d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif const STRUCT_TYPE& s; 474d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif void operator () (std_ostream&) const; 484d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif}; 494d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 50ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif#ifdef PROTOTYPE 51ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greifstd_ostream& operator << (std_ostream&, const Streamer<Foo>&); 52ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif#endif 53ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif 54ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif#ifdef INSTANTIATE 55ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greiftemplate struct Streamer<Foo>; 56ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif#endif 57ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif 58ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif#ifdef REDEFINE 59ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greifstd_ostream& operator << (std_ostream& o, const Streamer<Foo>&) // expected-note{{is here}} 60ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif{ 61ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif return o; 62ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif} 63ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif#endif 64ab297ac4d3f7c078a34c75493b840ef6b5801be3Gabor Greif 65d304fe66c032b6c73028cb45758614904e3c1735Gabor Greif#ifndef INSTANTIATE 664d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greiftemplate <> 674d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greifvoid Streamer<Foo>::operator () (std_ostream& o) const // expected-note{{requested here}} 684d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif{ 694d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif} 70d304fe66c032b6c73028cb45758614904e3c1735Gabor Greif#endif 714d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 724d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greifint main(void) 734d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif{ 744d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif Foo foo; 754d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif test(foo); 764d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif} 774d99a3da7ef08be34131b60b91f16adb3bc5f001Gabor Greif 78