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