Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 1 | @import cxx_templates_common; |
| 2 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 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 | } |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 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(); |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 13 | |
| 14 | template<typename T> struct SomeTemplate<T*>; |
| 15 | template<typename T> struct SomeTemplate<T*> {}; |
| 16 | typedef SomeTemplate<int*> SomeTemplateIntPtr; |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 17 | |
| 18 | template<typename T> void PerformDelayedLookup(T &t) { |
| 19 | t.f(); |
| 20 | typename T::Inner inner; |
| 21 | FoundByADL(t); |
| 22 | } |
Richard Smith | b71782b | 2013-08-01 04:12:04 +0000 | [diff] [blame] | 23 | |
| 24 | template<typename T> void PerformDelayedLookupInDefaultArgument(T &t, int a = (FoundByADL(T()), 0)) {} |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 25 | |
| 26 | template<typename T> struct RedeclaredAsFriend {}; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 27 | |
| 28 | void use_some_template_a() { |
| 29 | SomeTemplate<char[2]> a; |
| 30 | SomeTemplate<char[1]> b, c; |
| 31 | b = c; |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 32 | |
| 33 | (void)&WithImplicitSpecialMembers<int>::n; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 34 | } |
Richard Smith | d46d6de | 2013-10-13 23:50:45 +0000 | [diff] [blame] | 35 | |
| 36 | template<int> struct MergeTemplates; |
| 37 | MergeTemplates<0> *merge_templates_a; |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 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>; |
Richard Smith | 0c1065f | 2013-10-15 23:19:58 +0000 | [diff] [blame] | 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 | }; |
Richard Smith | c264d35 | 2014-03-23 02:30:01 +0000 | [diff] [blame] | 53 | |
| 54 | void InstantiateWithFriend(Std::WithFriend<int> wfi) {} |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 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; |
Richard Smith | 72544f8 | 2014-08-14 03:30:27 +0000 | [diff] [blame] | 61 | typedef WithPartialSpecialization<void(int)>::type WithPartialSpecializationInstantiate2; |
Richard Smith | 871cd4c | 2014-05-23 21:00:28 +0000 | [diff] [blame] | 62 | |
| 63 | template<> struct WithExplicitSpecialization<int> { |
| 64 | int n; |
| 65 | template<typename T> T &inner_template() { |
| 66 | return n; |
| 67 | } |
| 68 | }; |
Richard Smith | dc5523d | 2014-07-11 00:20:06 +0000 | [diff] [blame] | 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, ""); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 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; } |
Richard Smith | f59b735 | 2014-07-28 21:16:37 +0000 | [diff] [blame] | 79 | |
| 80 | template<typename T> using AliasTemplate = T; |
Richard Smith | 049fcd8 | 2014-07-29 00:58:01 +0000 | [diff] [blame] | 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; |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 88 | |
| 89 | void InstantiateWithAliasTemplate(WithAliasTemplate<int>::X<char>); |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 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); |
Richard Smith | 337f7c9 | 2014-10-10 22:37:41 +0000 | [diff] [blame] | 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 {}; } |
Richard Smith | 41c79d9 | 2014-10-11 00:37:16 +0000 | [diff] [blame] | 100 | |
| 101 | template<typename T> struct DontWalkPreviousDeclAfterMerging { struct Inner { typedef T type; }; }; |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 102 | |
| 103 | namespace TestInjectedClassName { |
| 104 | template<typename T> struct X { X(); }; |
| 105 | typedef X<char[1]> A; |
| 106 | } |