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