1 @import cxx_templates_common; 2 3 template<typename T> T f() { return T(); } 4 template<typename T> T f(T); 5 namespace N { 6 template<typename T> T f() { return T(); } 7 template<typename T> T f(T); 8 } 9 10 template<int N> int template_param_kinds_1(); 11 template<template<typename T, int, int> class> int template_param_kinds_2(); 12 template<template<typename T, typename U, T> class> int template_param_kinds_3(); 13 14 template<typename T> struct SomeTemplate<T*>; 15 template<typename T> struct SomeTemplate<T*> {}; 16 typedef SomeTemplate<int*> SomeTemplateIntPtr; 17 18 template<typename T> void PerformDelayedLookup(T &t) { 19 t.f(); 20 typename T::Inner inner; 21 FoundByADL(t); 22 } 23 24 template<typename T> void PerformDelayedLookupInDefaultArgument(T &t, int a = (FoundByADL(T()), 0)) {} 25 26 template<typename T> struct RedeclaredAsFriend {}; 27 28 void use_some_template_a() { 29 SomeTemplate<char[2]> a; 30 SomeTemplate<char[1]> b, c; 31 b = c; 32 33 (void)&WithImplicitSpecialMembers<int>::n; 34 } 35 36 template<int> struct MergeTemplates; 37 MergeTemplates<0> *merge_templates_a; 38 39 auto enum_a_from_a = CommonTemplate<int>::a; 40 const auto enum_c_from_a = CommonTemplate<int>::c; 41 42 template<int> struct UseInt; 43 template<typename T> void UseRedeclaredEnum(UseInt<T() + CommonTemplate<char>::a>); 44 constexpr void (*UseRedeclaredEnumA)(UseInt<1>) = UseRedeclaredEnum<int>; 45 46 template<typename> struct MergeSpecializations; 47 template<typename T> struct MergeSpecializations<T*> { 48 typedef int partially_specialized_in_a; 49 }; 50 template<> struct MergeSpecializations<char> { 51 typedef int explicitly_specialized_in_a; 52 }; 53 54 void InstantiateWithFriend(Std::WithFriend<int> wfi) {} 55 56 template<typename T> struct WithPartialSpecialization<T*> { 57 typedef int type; 58 T &f() { static T t; return t; } 59 }; 60 typedef WithPartialSpecializationUse::type WithPartialSpecializationInstantiate; 61 typedef WithPartialSpecialization<void(int)>::type WithPartialSpecializationInstantiate2; 62 63 template<> struct WithExplicitSpecialization<int> { 64 int n; 65 template<typename T> T &inner_template() { 66 return n; 67 } 68 }; 69 70 template<typename T> template<typename U> 71 constexpr int Outer<T>::Inner<U>::f() { return 1; } 72 static_assert(Outer<int>::Inner<int>::f() == 1, ""); 73 74 template<typename T> struct MergeTemplateDefinitions { 75 static constexpr int f(); 76 static constexpr int g(); 77 }; 78 template<typename T> constexpr int MergeTemplateDefinitions<T>::f() { return 1; } 79 80 template<typename T> using AliasTemplate = T; 81 82 template<typename T> struct PartiallyInstantiatePartialSpec {}; 83 template<typename T> struct PartiallyInstantiatePartialSpec<T*> { 84 static T *foo() { return reinterpret_cast<T*>(0); } 85 static T *bar() { return reinterpret_cast<T*>(0); } 86 }; 87 typedef PartiallyInstantiatePartialSpec<int*> PartiallyInstantiatePartialSpecHelper; 88 89 void InstantiateWithAliasTemplate(WithAliasTemplate<int>::X<char>); 90 inline int InstantiateWithAnonymousDeclsA(WithAnonymousDecls<int> x) { return (x.k ? x.a : x.b) + (x.k ? x.s.c : x.s.d) + x.e; } 91 inline int InstantiateWithAnonymousDeclsB2(WithAnonymousDecls<char> x); 92 93 94 template<typename T1 = int> 95 struct MergeAnonUnionMember { 96 MergeAnonUnionMember() { (void)values.t1; } 97 union { int t1; } values; 98 }; 99 inline MergeAnonUnionMember<> maum_a() { return {}; } 100 101 template<typename T> struct DontWalkPreviousDeclAfterMerging { struct Inner { typedef T type; }; }; 102 103 namespace TestInjectedClassName { 104 template<typename T> struct X { X(); }; 105 typedef X<char[1]> A; 106 } 107