blob: 4340910d1e2a40d1a2b22d1b5ff99cd0fa75fb9b [file] [log] [blame]
Richard Smith5de91b52013-06-25 01:25:15 +00001@import cxx_templates_common;
2
Richard Smith8f8f05c2013-06-24 04:45:28 +00003template<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}
Richard Smithbf78e642013-06-24 22:51:00 +00009
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();
Richard Smith5de91b52013-06-25 01:25:15 +000013
14template<typename T> struct SomeTemplate<T*>;
15template<typename T> struct SomeTemplate<T*> {};
16typedef SomeTemplate<int*> SomeTemplateIntPtr;
Richard Smith0e5d7b82013-07-25 23:08:39 +000017
18template<typename T> void PerformDelayedLookup(T &t) {
19 t.f();
20 typename T::Inner inner;
21 FoundByADL(t);
22}
Richard Smithb71782b2013-08-01 04:12:04 +000023
24template<typename T> void PerformDelayedLookupInDefaultArgument(T &t, int a = (FoundByADL(T()), 0)) {}
Richard Smith7ecc31b2013-08-02 01:09:12 +000025
26template<typename T> struct RedeclaredAsFriend {};
Richard Smithd55889a2013-09-09 16:55:27 +000027
28void use_some_template_a() {
29 SomeTemplate<char[2]> a;
30 SomeTemplate<char[1]> b, c;
31 b = c;
Richard Smith8c913ec2014-08-14 02:21:01 +000032
33 (void)&WithImplicitSpecialMembers<int>::n;
Richard Smithd55889a2013-09-09 16:55:27 +000034}
Richard Smithd46d6de2013-10-13 23:50:45 +000035
36template<int> struct MergeTemplates;
37MergeTemplates<0> *merge_templates_a;
Richard Smith01a73372013-10-15 22:02:41 +000038
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>;
Richard Smith0c1065f2013-10-15 23:19:58 +000045
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};
Richard Smithc264d352014-03-23 02:30:01 +000053
54void InstantiateWithFriend(Std::WithFriend<int> wfi) {}
Richard Smithdf352052014-05-22 20:59:29 +000055
56template<typename T> struct WithPartialSpecialization<T*> {
57 typedef int type;
58 T &f() { static T t; return t; }
59};
60typedef WithPartialSpecializationUse::type WithPartialSpecializationInstantiate;
Richard Smith72544f82014-08-14 03:30:27 +000061typedef WithPartialSpecialization<void(int)>::type WithPartialSpecializationInstantiate2;
Richard Smith871cd4c2014-05-23 21:00:28 +000062
63template<> struct WithExplicitSpecialization<int> {
64 int n;
65 template<typename T> T &inner_template() {
66 return n;
67 }
68};
Richard Smithdc5523d2014-07-11 00:20:06 +000069
70template<typename T> template<typename U>
71constexpr int Outer<T>::Inner<U>::f() { return 1; }
72static_assert(Outer<int>::Inner<int>::f() == 1, "");
Richard Smith547864d2014-07-11 18:22:58 +000073
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; }
Richard Smithf59b7352014-07-28 21:16:37 +000079
80template<typename T> using AliasTemplate = T;
Richard Smith049fcd82014-07-29 00:58:01 +000081
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;
Richard Smith43ccec8e2014-08-26 03:52:16 +000088
89void InstantiateWithAliasTemplate(WithAliasTemplate<int>::X<char>);
Richard Smith01bdb7a2014-08-28 05:44:07 +000090inline 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);
Richard Smith337f7c92014-10-10 22:37:41 +000092
93
94template<typename T1 = int>
95struct MergeAnonUnionMember {
96 MergeAnonUnionMember() { (void)values.t1; }
97 union { int t1; } values;
98};
99inline MergeAnonUnionMember<> maum_a() { return {}; }
Richard Smith41c79d92014-10-11 00:37:16 +0000100
101template<typename T> struct DontWalkPreviousDeclAfterMerging { struct Inner { typedef T type; }; };
Richard Smith6377f8f2014-10-21 21:15:18 +0000102
103namespace TestInjectedClassName {
104 template<typename T> struct X { X(); };
105 typedef X<char[1]> A;
106}