78 lines · cpp
1// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s2// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - -DPROTOTYPE | FileCheck --check-prefix=CHECK-PROTOTYPE %s3// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - -DINSTANTIATE | FileCheck --check-prefix=CHECK-INSTANTIATE %s4// RUN: %clang_cc1 %s -std=c++98 -triple %itanium_abi_triple -emit-llvm -o - -DPROTOTYPE -DINSTANTIATE | FileCheck --check-prefix=CHECK-PROTOTYPE-INSTANTIATE %s5// RUN: %clang_cc1 %s -DREDEFINE -verify6// RUN: %clang_cc1 %s -DPROTOTYPE -DREDEFINE -verify7// PR8007: friend function not instantiated, reordered version.8// Corresponds to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=383929 10// CHECK: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE11// CHECK-PROTOTYPE: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE12// CHECK-INSTANTIATE: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE13// CHECK-PROTOTYPE-INSTANTIATE: define linkonce_odr{{.*}}_ZlsR11std_ostreamRK8StreamerI3FooE14 15struct std_ostream16{17 int dummy;18};19 20std_ostream cout;21 22template <typename STRUCT_TYPE>23struct Streamer;24 25typedef struct Foo {} Foo;26 27inline std_ostream& operator << (std_ostream&, const Streamer<Foo>&);28 29void test(const Streamer<Foo>& foo)30{31 cout << foo;32}33 34template <typename STRUCT_TYPE>35struct Streamer36{37 friend std_ostream& operator << (std_ostream& o, const Streamer& f) // expected-error{{redefinition of 'operator<<'}}38 {39 Streamer s(f);40 s(o);41 return o;42 }43 44 Streamer(const STRUCT_TYPE& s) : s(s) {}45 46 const STRUCT_TYPE& s;47 void operator () (std_ostream&) const;48};49 50#ifdef PROTOTYPE51std_ostream& operator << (std_ostream&, const Streamer<Foo>&);52#endif53 54#ifdef INSTANTIATE55template struct Streamer<Foo>;56#endif57 58#ifdef REDEFINE59std_ostream& operator << (std_ostream& o, const Streamer<Foo>&) // expected-note{{is here}}60{61 return o;62}63#endif64 65#ifndef INSTANTIATE66template <>67void Streamer<Foo>::operator () (std_ostream& o) const // expected-note{{requested here}}68{69}70#endif71 72int main(void)73{74 Foo foo;75 test(foo);76}77 78