Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Rafael Espindola | 925213b | 2013-07-04 16:16:58 +0000 | [diff] [blame] | 2 | // RUN: not %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups | FileCheck %s --check-prefix=CHECK-GLOBAL |
| 3 | // RUN: not %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups -ast-dump-filter N | FileCheck %s --check-prefix=CHECK-NAMESPACE-N |
Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 4 | // RUN: not %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump | FileCheck %s --check-prefix=CHECK-DUMP |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 5 | // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11 |
| 6 | |
| 7 | @import cxx_templates_a; |
| 8 | @import cxx_templates_b; |
Richard Smith | 0c1065f | 2013-10-15 23:19:58 +0000 | [diff] [blame] | 9 | @import cxx_templates_c; |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 10 | @import cxx_templates_common; |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 11 | |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 12 | template<typename, char> struct Tmpl_T_C {}; |
| 13 | template<typename, int, int> struct Tmpl_T_I_I {}; |
| 14 | |
| 15 | template<typename A, typename B, A> struct Tmpl_T_T_A {}; |
| 16 | template<typename A, typename B, B> struct Tmpl_T_T_B {}; |
| 17 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 18 | template<int> struct UseInt {}; |
| 19 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 20 | void g() { |
| 21 | f(0); |
| 22 | f<double>(1.0); |
| 23 | f<int>(); |
| 24 | f(); // expected-error {{no matching function}} |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 25 | // expected-note@Inputs/cxx-templates-b.h:3 {{couldn't infer template argument}} |
| 26 | // expected-note@Inputs/cxx-templates-b.h:4 {{requires single argument}} |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 27 | |
| 28 | N::f(0); |
| 29 | N::f<double>(1.0); |
| 30 | N::f<int>(); |
| 31 | N::f(); // expected-error {{no matching function}} |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 32 | // expected-note@Inputs/cxx-templates-b.h:6 {{couldn't infer template argument}} |
| 33 | // expected-note@Inputs/cxx-templates-b.h:7 {{requires single argument 't'}} |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 34 | |
| 35 | template_param_kinds_1<0>(); // ok, from cxx-templates-a.h |
| 36 | template_param_kinds_1<int>(); // ok, from cxx-templates-b.h |
| 37 | |
| 38 | template_param_kinds_2<Tmpl_T_C>(); // expected-error {{no matching function}} |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 39 | // expected-note@Inputs/cxx-templates-a.h:11 {{invalid explicitly-specified argument}} |
| 40 | // expected-note@Inputs/cxx-templates-b.h:11 {{invalid explicitly-specified argument}} |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 41 | |
| 42 | template_param_kinds_2<Tmpl_T_I_I>(); // expected-error {{ambiguous}} |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 43 | // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}} |
| 44 | // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}} |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 45 | |
| 46 | // FIXME: This should be valid, but we incorrectly match the template template |
| 47 | // argument against both template template parameters. |
| 48 | template_param_kinds_3<Tmpl_T_T_A>(); // expected-error {{ambiguous}} |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 49 | // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}} |
| 50 | // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}} |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 51 | template_param_kinds_3<Tmpl_T_T_B>(); // expected-error {{ambiguous}} |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 52 | // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}} |
| 53 | // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}} |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 54 | |
| 55 | // Trigger the instantiation of a template in 'a' that uses a type defined in |
| 56 | // 'common'. That type is not visible here. |
| 57 | PerformDelayedLookup(defined_in_common); |
| 58 | |
Richard Smith | b71782b | 2013-08-01 04:12:04 +0000 | [diff] [blame] | 59 | // Likewise, but via a default argument. |
| 60 | PerformDelayedLookupInDefaultArgument(defined_in_common); |
| 61 | |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 62 | // Trigger the instantiation of a template in 'b' that uses a type defined in |
| 63 | // 'b_impl'. That type is not visible here. |
| 64 | UseDefinedInBImpl<int>(); |
| 65 | |
| 66 | // Trigger the instantiation of a template in 'a' that uses a type defined in |
| 67 | // 'b_impl', via a template defined in 'b'. Since the type is visible from |
| 68 | // within 'b', the instantiation succeeds. |
| 69 | UseDefinedInBImplIndirectly(defined_in_b_impl); |
| 70 | |
| 71 | // Trigger the instantiation of a template in 'a' that uses a type defined in |
| 72 | // 'b_impl'. That type is not visible here, nor in 'a'. This fails; there is |
| 73 | // no reason why DefinedInBImpl should be visible here. |
| 74 | // expected-error@Inputs/cxx-templates-a.h:19 {{definition of 'DefinedInBImpl' must be imported}} |
| 75 | // expected-note@Inputs/cxx-templates-b-impl.h:1 {{definition is here}} |
| 76 | PerformDelayedLookup(defined_in_b_impl); // expected-note {{in instantiation of}} |
Richard Smith | d46d6de | 2013-10-13 23:50:45 +0000 | [diff] [blame] | 77 | |
| 78 | merge_templates_a = merge_templates_b; // ok, same type |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 79 | |
| 80 | using T = decltype(enum_a_from_a); |
| 81 | using T = decltype(enum_b_from_b); |
| 82 | T e = true ? enum_a_from_a : enum_b_from_b; |
| 83 | |
| 84 | UseRedeclaredEnum<int>(UseInt<1>()); |
| 85 | // FIXME: Reintroduce this once we merge function template specializations. |
| 86 | //static_assert(UseRedeclaredEnumA == UseRedeclaredEnumB, ""); |
| 87 | //static_assert(UseRedeclaredEnumA == UseRedeclaredEnum<int>, ""); |
| 88 | //static_assert(UseRedeclaredEnumB == UseRedeclaredEnum<int>, ""); |
| 89 | static_assert(enum_c_from_a == enum_c_from_b, ""); |
| 90 | CommonTemplate<int> cti; |
| 91 | CommonTemplate<int>::E eee = CommonTemplate<int>::c; |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 94 | RedeclaredAsFriend<int> raf1; |
| 95 | RedeclareTemplateAsFriend<double> rtaf; |
| 96 | RedeclaredAsFriend<double> raf2; |
| 97 | |
Richard Smith | 0c1065f | 2013-10-15 23:19:58 +0000 | [diff] [blame] | 98 | MergeSpecializations<int*>::partially_specialized_in_a spec_in_a_1; |
| 99 | MergeSpecializations<int&>::partially_specialized_in_b spec_in_b_1; |
| 100 | MergeSpecializations<int[]>::partially_specialized_in_c spec_in_c_1; |
| 101 | MergeSpecializations<char>::explicitly_specialized_in_a spec_in_a_2; |
| 102 | MergeSpecializations<double>::explicitly_specialized_in_b spec_in_b_2; |
| 103 | MergeSpecializations<bool>::explicitly_specialized_in_c spec_in_c_2; |
| 104 | |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 105 | @import cxx_templates_common; |
| 106 | |
| 107 | typedef SomeTemplate<int*> SomeTemplateIntPtr; |
| 108 | typedef SomeTemplate<int&> SomeTemplateIntRef; |
| 109 | SomeTemplate<char*> some_template_char_ptr; |
| 110 | SomeTemplate<char&> some_template_char_ref; |
| 111 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 112 | void testImplicitSpecialMembers(SomeTemplate<char[1]> &a, |
| 113 | const SomeTemplate<char[1]> &b, |
| 114 | SomeTemplate<char[2]> &c, |
| 115 | const SomeTemplate<char[2]> &d) { |
| 116 | a = b; |
| 117 | c = d; |
| 118 | } |
| 119 | |
Richard Smith | c264d35 | 2014-03-23 02:30:01 +0000 | [diff] [blame] | 120 | bool testFriendInClassTemplate(Std::WithFriend<int> wfi) { |
| 121 | return wfi != wfi; |
| 122 | } |
| 123 | |
Richard Smith | 561e0dc | 2014-03-23 19:45:26 +0000 | [diff] [blame] | 124 | namespace Std { |
| 125 | void g(); // expected-error {{functions that differ only in their return type cannot be overloaded}} |
| 126 | // expected-note@cxx-templates-common.h:21 {{previous}} |
| 127 | } |
| 128 | |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 129 | // FIXME: We should only have two entries for each of these names (one for each |
| 130 | // function template), but we don't attempt to deduplicate lookup results from |
| 131 | // sibling modules yet. |
| 132 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 133 | // CHECK-GLOBAL: DeclarationName 'f' |
| 134 | // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f' |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 135 | // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f' |
| 136 | // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f' |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 137 | // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f' |
| 138 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 139 | // CHECK-NAMESPACE-N: DeclarationName 'f' |
| 140 | // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f' |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 141 | // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f' |
| 142 | // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f' |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 143 | // CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f' |
Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 144 | |
David Blaikie | 5ee3d00 | 2014-04-02 05:48:29 +0000 | [diff] [blame^] | 145 | // CHECK-DUMP: ClassTemplateDecl {{.*}} <{{.*[/\\]}}cxx-templates-common.h:1:1, {{.*}}> col:{{.*}} in cxx_templates_common SomeTemplate |
Richard Smith | cbdf733 | 2014-03-18 02:07:28 +0000 | [diff] [blame] | 146 | // CHECK-DUMP: ClassTemplateSpecializationDecl {{.*}} prev [[CHAR2:[^ ]*]] {{.*}} SomeTemplate |
| 147 | // CHECK-DUMP-NEXT: TemplateArgument type 'char [2]' |
| 148 | // CHECK-DUMP: ClassTemplateSpecializationDecl [[CHAR2]] {{.*}} SomeTemplate definition |
| 149 | // CHECK-DUMP-NEXT: TemplateArgument type 'char [2]' |
| 150 | // CHECK-DUMP: ClassTemplateSpecializationDecl {{.*}} prev [[CHAR1:[^ ]*]] {{.*}} SomeTemplate |
| 151 | // CHECK-DUMP-NEXT: TemplateArgument type 'char [1]' |
| 152 | // CHECK-DUMP: ClassTemplateSpecializationDecl [[CHAR1]] {{.*}} SomeTemplate definition |
| 153 | // CHECK-DUMP-NEXT: TemplateArgument type 'char [1]' |