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(); |
| 4 | template<typename T> T f(T t) { return t; } |
| 5 | namespace N { |
| 6 | template<typename T> T f(); |
| 7 | template<typename T> T f(T t) { return t; } |
| 8 | } |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 9 | |
| 10 | template<typename> int template_param_kinds_1(); |
| 11 | template<template<typename, int, int...> class> int template_param_kinds_2(); |
| 12 | template<template<typename T, typename U, U> 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&> SomeTemplateIntRef; |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 17 | |
| 18 | extern DefinedInCommon &defined_in_common; |
| 19 | |
Richard Smith | d46d6de | 2013-10-13 23:50:45 +0000 | [diff] [blame] | 20 | template<int> struct MergeTemplates; |
| 21 | MergeTemplates<0> *merge_templates_b; |
| 22 | |
Richard Smith | dc5523d | 2014-07-11 00:20:06 +0000 | [diff] [blame^] | 23 | template<typename T> template<typename U> |
| 24 | constexpr int Outer<T>::Inner<U>::g() { return 2; } |
| 25 | static_assert(Outer<int>::Inner<int>::g() == 2, ""); |
| 26 | |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 27 | @import cxx_templates_b_impl; |
| 28 | |
| 29 | template<typename T, typename> struct Identity { typedef T type; }; |
| 30 | template<typename T> void UseDefinedInBImpl() { |
| 31 | typename Identity<DefinedInBImpl, T>::type dependent; |
| 32 | FoundByADL(dependent); |
| 33 | typename Identity<DefinedInBImpl, T>::type::Inner inner; |
| 34 | dependent.f(); |
| 35 | } |
| 36 | |
| 37 | extern DefinedInBImpl &defined_in_b_impl; |
| 38 | |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 39 | template<typename T> |
| 40 | struct RedeclareTemplateAsFriend { |
| 41 | template<typename U> |
| 42 | friend struct RedeclaredAsFriend; |
| 43 | }; |
| 44 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 45 | void use_some_template_b() { |
| 46 | SomeTemplate<char[1]> a; |
| 47 | SomeTemplate<char[2]> b, c; |
| 48 | b = c; |
| 49 | } |
| 50 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 51 | auto enum_b_from_b = CommonTemplate<int>::b; |
| 52 | const auto enum_c_from_b = CommonTemplate<int>::c; |
| 53 | |
| 54 | template<int> struct UseInt; |
| 55 | template<typename T> void UseRedeclaredEnum(UseInt<T() + CommonTemplate<char>::a>); |
| 56 | constexpr void (*UseRedeclaredEnumB)(UseInt<1>) = UseRedeclaredEnum<int>; |
| 57 | |
Richard Smith | 0c1065f | 2013-10-15 23:19:58 +0000 | [diff] [blame] | 58 | template<typename> struct MergeSpecializations; |
| 59 | template<typename T> struct MergeSpecializations<T&> { |
| 60 | typedef int partially_specialized_in_b; |
| 61 | }; |
| 62 | template<> struct MergeSpecializations<double> { |
| 63 | typedef int explicitly_specialized_in_b; |
| 64 | }; |
| 65 | |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 66 | @import cxx_templates_a; |
| 67 | template<typename T> void UseDefinedInBImplIndirectly(T &v) { |
| 68 | PerformDelayedLookup(v); |
| 69 | } |
| 70 | |
| 71 | void TriggerInstantiation() { |
| 72 | UseDefinedInBImpl<void>(); |
Richard Smith | 561e0dc | 2014-03-23 19:45:26 +0000 | [diff] [blame] | 73 | Std::f<int>(); |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 74 | } |