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 | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 4 | // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11 |
| 5 | |
| 6 | @import cxx_templates_a; |
| 7 | @import cxx_templates_b; |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame^] | 8 | @import cxx_templates_common; |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 9 | |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 10 | template<typename, char> struct Tmpl_T_C {}; |
| 11 | template<typename, int, int> struct Tmpl_T_I_I {}; |
| 12 | |
| 13 | template<typename A, typename B, A> struct Tmpl_T_T_A {}; |
| 14 | template<typename A, typename B, B> struct Tmpl_T_T_B {}; |
| 15 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame^] | 16 | template<int> struct UseInt {}; |
| 17 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 18 | void g() { |
| 19 | f(0); |
| 20 | f<double>(1.0); |
| 21 | f<int>(); |
| 22 | f(); // expected-error {{no matching function}} |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 23 | // expected-note@Inputs/cxx-templates-b.h:3 {{couldn't infer template argument}} |
| 24 | // expected-note@Inputs/cxx-templates-b.h:4 {{requires single argument}} |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 25 | |
| 26 | N::f(0); |
| 27 | N::f<double>(1.0); |
| 28 | N::f<int>(); |
| 29 | N::f(); // expected-error {{no matching function}} |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 30 | // expected-note@Inputs/cxx-templates-b.h:6 {{couldn't infer template argument}} |
| 31 | // expected-note@Inputs/cxx-templates-b.h:7 {{requires single argument 't'}} |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 32 | |
| 33 | template_param_kinds_1<0>(); // ok, from cxx-templates-a.h |
| 34 | template_param_kinds_1<int>(); // ok, from cxx-templates-b.h |
| 35 | |
| 36 | template_param_kinds_2<Tmpl_T_C>(); // expected-error {{no matching function}} |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 37 | // expected-note@Inputs/cxx-templates-a.h:11 {{invalid explicitly-specified argument}} |
| 38 | // expected-note@Inputs/cxx-templates-b.h:11 {{invalid explicitly-specified argument}} |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 39 | |
| 40 | template_param_kinds_2<Tmpl_T_I_I>(); // expected-error {{ambiguous}} |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 41 | // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}} |
| 42 | // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}} |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 43 | |
| 44 | // FIXME: This should be valid, but we incorrectly match the template template |
| 45 | // argument against both template template parameters. |
| 46 | template_param_kinds_3<Tmpl_T_T_A>(); // expected-error {{ambiguous}} |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 47 | // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}} |
| 48 | // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}} |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 49 | template_param_kinds_3<Tmpl_T_T_B>(); // expected-error {{ambiguous}} |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 50 | // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}} |
| 51 | // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}} |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 52 | |
| 53 | // Trigger the instantiation of a template in 'a' that uses a type defined in |
| 54 | // 'common'. That type is not visible here. |
| 55 | PerformDelayedLookup(defined_in_common); |
| 56 | |
Richard Smith | b71782b | 2013-08-01 04:12:04 +0000 | [diff] [blame] | 57 | // Likewise, but via a default argument. |
| 58 | PerformDelayedLookupInDefaultArgument(defined_in_common); |
| 59 | |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 60 | // Trigger the instantiation of a template in 'b' that uses a type defined in |
| 61 | // 'b_impl'. That type is not visible here. |
| 62 | UseDefinedInBImpl<int>(); |
| 63 | |
| 64 | // Trigger the instantiation of a template in 'a' that uses a type defined in |
| 65 | // 'b_impl', via a template defined in 'b'. Since the type is visible from |
| 66 | // within 'b', the instantiation succeeds. |
| 67 | UseDefinedInBImplIndirectly(defined_in_b_impl); |
| 68 | |
| 69 | // Trigger the instantiation of a template in 'a' that uses a type defined in |
| 70 | // 'b_impl'. That type is not visible here, nor in 'a'. This fails; there is |
| 71 | // no reason why DefinedInBImpl should be visible here. |
| 72 | // expected-error@Inputs/cxx-templates-a.h:19 {{definition of 'DefinedInBImpl' must be imported}} |
| 73 | // expected-note@Inputs/cxx-templates-b-impl.h:1 {{definition is here}} |
| 74 | PerformDelayedLookup(defined_in_b_impl); // expected-note {{in instantiation of}} |
Richard Smith | d46d6de | 2013-10-13 23:50:45 +0000 | [diff] [blame] | 75 | |
| 76 | merge_templates_a = merge_templates_b; // ok, same type |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame^] | 77 | |
| 78 | using T = decltype(enum_a_from_a); |
| 79 | using T = decltype(enum_b_from_b); |
| 80 | T e = true ? enum_a_from_a : enum_b_from_b; |
| 81 | |
| 82 | UseRedeclaredEnum<int>(UseInt<1>()); |
| 83 | // FIXME: Reintroduce this once we merge function template specializations. |
| 84 | //static_assert(UseRedeclaredEnumA == UseRedeclaredEnumB, ""); |
| 85 | //static_assert(UseRedeclaredEnumA == UseRedeclaredEnum<int>, ""); |
| 86 | //static_assert(UseRedeclaredEnumB == UseRedeclaredEnum<int>, ""); |
| 87 | static_assert(enum_c_from_a == enum_c_from_b, ""); |
| 88 | CommonTemplate<int> cti; |
| 89 | CommonTemplate<int>::E eee = CommonTemplate<int>::c; |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 92 | RedeclaredAsFriend<int> raf1; |
| 93 | RedeclareTemplateAsFriend<double> rtaf; |
| 94 | RedeclaredAsFriend<double> raf2; |
| 95 | |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 96 | @import cxx_templates_common; |
| 97 | |
| 98 | typedef SomeTemplate<int*> SomeTemplateIntPtr; |
| 99 | typedef SomeTemplate<int&> SomeTemplateIntRef; |
| 100 | SomeTemplate<char*> some_template_char_ptr; |
| 101 | SomeTemplate<char&> some_template_char_ref; |
| 102 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 103 | void testImplicitSpecialMembers(SomeTemplate<char[1]> &a, |
| 104 | const SomeTemplate<char[1]> &b, |
| 105 | SomeTemplate<char[2]> &c, |
| 106 | const SomeTemplate<char[2]> &d) { |
| 107 | a = b; |
| 108 | c = d; |
| 109 | } |
| 110 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 111 | // CHECK-GLOBAL: DeclarationName 'f' |
| 112 | // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f' |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 113 | // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f' |
| 114 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 115 | // CHECK-NAMESPACE-N: DeclarationName 'f' |
| 116 | // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f' |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 117 | // CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f' |