xref: /minix3/external/bsd/llvm/dist/clang/test/Modules/Inputs/cxx-templates-b.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc @import cxx_templates_common;
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc template<typename T> T f();
f(T t)4f4a2713aSLionel Sambuc template<typename T> T f(T t) { return t; }
5f4a2713aSLionel Sambuc namespace N {
6f4a2713aSLionel Sambuc   template<typename T> T f();
f(T t)7f4a2713aSLionel Sambuc   template<typename T> T f(T t) { return t; }
8f4a2713aSLionel Sambuc }
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc template<typename> int template_param_kinds_1();
11f4a2713aSLionel Sambuc template<template<typename, int, int...> class> int template_param_kinds_2();
12f4a2713aSLionel Sambuc template<template<typename T, typename U, U> 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&> SomeTemplateIntRef;
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc extern DefinedInCommon &defined_in_common;
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc template<int> struct MergeTemplates;
21f4a2713aSLionel Sambuc MergeTemplates<0> *merge_templates_b;
22f4a2713aSLionel Sambuc 
23*0a6a1f1dSLionel Sambuc template<typename T> template<typename U>
24*0a6a1f1dSLionel Sambuc constexpr int Outer<T>::Inner<U>::g() { return 2; }
25*0a6a1f1dSLionel Sambuc static_assert(Outer<int>::Inner<int>::g() == 2, "");
26*0a6a1f1dSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc namespace TestInjectedClassName {
28*0a6a1f1dSLionel Sambuc   template<typename T> struct X { X(); };
29*0a6a1f1dSLionel Sambuc   typedef X<char[2]> B;
30*0a6a1f1dSLionel Sambuc }
31*0a6a1f1dSLionel Sambuc 
32f4a2713aSLionel Sambuc @import cxx_templates_b_impl;
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc template<typename T, typename> struct Identity { typedef T type; };
35f4a2713aSLionel Sambuc template<typename T> void UseDefinedInBImpl() {
36f4a2713aSLionel Sambuc   typename Identity<DefinedInBImpl, T>::type dependent;
37f4a2713aSLionel Sambuc   FoundByADL(dependent);
38f4a2713aSLionel Sambuc   typename Identity<DefinedInBImpl, T>::type::Inner inner;
39f4a2713aSLionel Sambuc   dependent.f();
40f4a2713aSLionel Sambuc }
41f4a2713aSLionel Sambuc 
42f4a2713aSLionel Sambuc extern DefinedInBImpl &defined_in_b_impl;
43f4a2713aSLionel Sambuc 
44f4a2713aSLionel Sambuc template<typename T>
45f4a2713aSLionel Sambuc struct RedeclareTemplateAsFriend {
46f4a2713aSLionel Sambuc   template<typename U>
47f4a2713aSLionel Sambuc   friend struct RedeclaredAsFriend;
48f4a2713aSLionel Sambuc };
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc void use_some_template_b() {
51f4a2713aSLionel Sambuc   SomeTemplate<char[1]> a;
52f4a2713aSLionel Sambuc   SomeTemplate<char[2]> b, c;
53f4a2713aSLionel Sambuc   b = c;
54*0a6a1f1dSLionel Sambuc 
55*0a6a1f1dSLionel Sambuc   WithImplicitSpecialMembers<int> wism1, wism2(wism1);
56f4a2713aSLionel Sambuc }
57f4a2713aSLionel Sambuc 
58f4a2713aSLionel Sambuc auto enum_b_from_b = CommonTemplate<int>::b;
59f4a2713aSLionel Sambuc const auto enum_c_from_b = CommonTemplate<int>::c;
60f4a2713aSLionel Sambuc 
61f4a2713aSLionel Sambuc template<int> struct UseInt;
62f4a2713aSLionel Sambuc template<typename T> void UseRedeclaredEnum(UseInt<T() + CommonTemplate<char>::a>);
63f4a2713aSLionel Sambuc constexpr void (*UseRedeclaredEnumB)(UseInt<1>) = UseRedeclaredEnum<int>;
64f4a2713aSLionel Sambuc 
65*0a6a1f1dSLionel Sambuc typedef WithPartialSpecialization<void(int)>::type WithPartialSpecializationInstantiate3;
66*0a6a1f1dSLionel Sambuc 
67f4a2713aSLionel Sambuc template<typename> struct MergeSpecializations;
68f4a2713aSLionel Sambuc template<typename T> struct MergeSpecializations<T&> {
69f4a2713aSLionel Sambuc   typedef int partially_specialized_in_b;
70f4a2713aSLionel Sambuc };
71f4a2713aSLionel Sambuc template<> struct MergeSpecializations<double> {
72f4a2713aSLionel Sambuc   typedef int explicitly_specialized_in_b;
73f4a2713aSLionel Sambuc };
74f4a2713aSLionel Sambuc 
75*0a6a1f1dSLionel Sambuc template<typename U> using AliasTemplate = U;
76*0a6a1f1dSLionel Sambuc 
77*0a6a1f1dSLionel Sambuc void InstantiateWithAliasTemplate(WithAliasTemplate<int>::X<char>);
78*0a6a1f1dSLionel Sambuc inline int InstantiateWithAnonymousDeclsB(WithAnonymousDecls<int> x) {
79*0a6a1f1dSLionel Sambuc   return (x.k ? x.a : x.b) + (x.k ? x.s.c : x.s.d) + x.e;
80*0a6a1f1dSLionel Sambuc }
81*0a6a1f1dSLionel Sambuc inline int InstantiateWithAnonymousDeclsB2(WithAnonymousDecls<char> x) {
82*0a6a1f1dSLionel Sambuc   return (x.k ? x.a : x.b) + (x.k ? x.s.c : x.s.d) + x.e;
83*0a6a1f1dSLionel Sambuc }
84*0a6a1f1dSLionel Sambuc 
85f4a2713aSLionel Sambuc @import cxx_templates_a;
86f4a2713aSLionel Sambuc template<typename T> void UseDefinedInBImplIndirectly(T &v) {
87f4a2713aSLionel Sambuc   PerformDelayedLookup(v);
88f4a2713aSLionel Sambuc }
89f4a2713aSLionel Sambuc 
90f4a2713aSLionel Sambuc void TriggerInstantiation() {
91f4a2713aSLionel Sambuc   UseDefinedInBImpl<void>();
92*0a6a1f1dSLionel Sambuc   Std::f<int>();
93*0a6a1f1dSLionel Sambuc   PartiallyInstantiatePartialSpec<int*>::foo();
94*0a6a1f1dSLionel Sambuc   WithPartialSpecialization<void(int)>::type x;
95f4a2713aSLionel Sambuc }
96