brintos

brintos / llvm-project-archived public Read only

0
0
Text · 13.5 KiB · f587af4 Raw
269 lines · cpp
1// RUN: rm -rf %t2// RUN: not %clang_cc1 -x objective-c++ -fmodules -fimplicit-module-maps -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++14 -ast-dump-lookups 2>/dev/null | FileCheck %s --check-prefix=CHECK-GLOBAL3// RUN: not %clang_cc1 -x objective-c++ -fmodules -fimplicit-module-maps -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++14 -ast-dump-lookups -ast-dump-filter N 2>/dev/null | FileCheck %s --check-prefix=CHECK-NAMESPACE-N4// RUN: not %clang_cc1 -x objective-c++ -fmodules -fimplicit-module-maps -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++14 -ast-dump -ast-dump-filter SomeTemplate 2>/dev/null | FileCheck %s --check-prefix=CHECK-DUMP5// RUN: %clang_cc1 -x objective-c++ -fmodules -fimplicit-module-maps -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++146// RUN: %clang_cc1 -x objective-c++ -fmodules -fimplicit-module-maps -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++14 -DEARLY_IMPORT7 8#ifdef EARLY_IMPORT9#include "cxx-templates-textual.h"10#endif11 12@import cxx_templates_a;13@import cxx_templates_b;14@import cxx_templates_c;15@import cxx_templates_d;16@import cxx_templates_common;17 18template<typename, char> struct Tmpl_T_C {};19template<typename, int, int> struct Tmpl_T_I_I {};20 21template<typename A, typename B, A> struct Tmpl_T_T_A {};22template<typename A, typename B, B> struct Tmpl_T_T_B {};23 24template<int> struct UseInt {};25 26void g() {27  f(0);28  f<double>(1.0);29  f<int>();30  f(); // expected-error {{no matching function}}31  // expected-note@Inputs/cxx-templates-a.h:3 {{couldn't infer template argument}}32  // expected-note@Inputs/cxx-templates-a.h:4 {{requires 1 argument}}33 34  N::f(0);35  N::f<double>(1.0);36  N::f<int>();37  N::f(); // expected-error {{no matching function}}38  // expected-note@Inputs/cxx-templates-b.h:6 {{couldn't infer template argument}}39  // expected-note@Inputs/cxx-templates-b.h:7 {{requires single argument}}40 41  template_param_kinds_1<0>(); // ok, from cxx-templates-a.h42  template_param_kinds_1<int>(); // ok, from cxx-templates-b.h43 44  template_param_kinds_2<Tmpl_T_C>(); // expected-error {{no matching function for call}}45  // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}}46  // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}}47 48  template_param_kinds_2<Tmpl_T_I_I>(); // expected-error {{ambiguous}}49  // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}}50  // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}}51 52  template_param_kinds_3<Tmpl_T_T_A>();53  template_param_kinds_3<Tmpl_T_T_B>();54 55  // Trigger the instantiation of a template in 'a' that uses a type defined in56  // 'common'. That type is not visible here.57  PerformDelayedLookup(defined_in_common);58 59  // Likewise, but via a default argument.60  PerformDelayedLookupInDefaultArgument(defined_in_common);61 62  // Trigger the instantiation of a template in 'b' that uses a type defined in63  // '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 in67  // 'b_impl', via a template defined in 'b'. Since the type is visible from68  // 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 in72  // 'b_impl'. That type is not visible here, nor in 'a'. This fails; there is73  // no reason why DefinedInBImpl should be visible here.74  //75  // We turn off error recovery for modules in this test (so we don't get an76  // implicit import of cxx_templates_b_impl), and that results in us producing77  // a big spew of errors here.78  //79  // expected-error@Inputs/cxx-templates-a.h:19 {{definition of 'DefinedInBImpl' must be imported}}80  // expected-note@Inputs/cxx-templates-b-impl.h:1 +{{definition here is not reachable}}81  // expected-error@Inputs/cxx-templates-a.h:19 +{{}}82  // expected-error@Inputs/cxx-templates-a.h:20 +{{}}83  PerformDelayedLookup(defined_in_b_impl); // expected-note {{in instantiation of}}84 85  merge_templates_a = merge_templates_b; // ok, same type86 87  using T = decltype(enum_a_from_a);88  using T = decltype(enum_b_from_b);89  T e = true ? enum_a_from_a : enum_b_from_b;90 91  UseRedeclaredEnum<int>(UseInt<1>());92  // FIXME: Reintroduce this once we merge function template specializations.93  //static_assert(UseRedeclaredEnumA == UseRedeclaredEnumB, "");94  //static_assert(UseRedeclaredEnumA == UseRedeclaredEnum<int>, "");95  //static_assert(UseRedeclaredEnumB == UseRedeclaredEnum<int>, "");96  static_assert(enum_c_from_a == enum_c_from_b, "");97  CommonTemplate<int> cti;98  CommonTemplate<int>::E eee = CommonTemplate<int>::c;99 100  TemplateInstantiationVisibility<char[1]> tiv1;101  TemplateInstantiationVisibility<char[2]> tiv2;102  TemplateInstantiationVisibility<char[3]> tiv3; // expected-error 5{{must be imported from module 'cxx_templates_b_impl'}}103  // expected-note@cxx-templates-b-impl.h:10 3{{explicit specialization declared here is not reachable}}104  // expected-note@cxx-templates-b-impl.h:10 2{{definition here is not reachable}}105  TemplateInstantiationVisibility<char[4]> tiv4;106 107  int &p = WithPartialSpecializationUse().f();108  int &q = WithExplicitSpecializationUse().inner_template<int>();109  int *r = PartiallyInstantiatePartialSpec<int*>::bar();110 111  (void)&WithImplicitSpecialMembers<int>::n;112 113  MergeClassTemplateSpecializations_string s;114 115  extern TestInjectedClassName::A *use_a;116  extern TestInjectedClassName::C *use_c;117  TestInjectedClassName::UseD();118}119 120static_assert(Outer<int>::Inner<int>::f() == 1, "");121static_assert(Outer<int>::Inner<int>::g() == 2, "");122 123static_assert(MergeTemplateDefinitions<int>::f() == 1, "");124static_assert(MergeTemplateDefinitions<int>::g() == 2, "");125 126RedeclaredAsFriend<int> raf1;127RedeclareTemplateAsFriend<double> rtaf;128RedeclaredAsFriend<double> raf2;129 130MergeSpecializations<int*>::partially_specialized_in_a spec_in_a_1;131MergeSpecializations<int&>::partially_specialized_in_b spec_in_b_1;132MergeSpecializations<int[]>::partially_specialized_in_c spec_in_c_1;133MergeSpecializations<char>::explicitly_specialized_in_a spec_in_a_2;134MergeSpecializations<double>::explicitly_specialized_in_b spec_in_b_2;135MergeSpecializations<bool>::explicitly_specialized_in_c spec_in_c_2;136 137MergeAnonUnionMember<> maum_main;138typedef DontWalkPreviousDeclAfterMerging<int> dwpdam_typedef_2;139dwpdam_typedef::type dwpdam_typedef_use;140DontWalkPreviousDeclAfterMerging<int>::Inner::type dwpdam;141 142using AliasTemplateMergingTest = WithAliasTemplate<int>::X<char>;143 144int AnonymousDeclsMergingTest(WithAnonymousDecls<int> WAD, WithAnonymousDecls<char> WADC) {145  return InstantiateWithAnonymousDeclsA(WAD) +146         InstantiateWithAnonymousDeclsB(WAD) +147         InstantiateWithAnonymousDeclsB2(WADC) +148         InstantiateWithAnonymousDeclsD(WADC);149}150 151@import cxx_templates_common;152 153typedef SomeTemplate<int*> SomeTemplateIntPtr;154typedef SomeTemplate<int&> SomeTemplateIntRef;155SomeTemplate<char*> some_template_char_ptr;156SomeTemplate<char&> some_template_char_ref;157 158void testImplicitSpecialMembers(SomeTemplate<char[1]> &a,159                                const SomeTemplate<char[1]> &b,160                                SomeTemplate<char[2]> &c,161                                const SomeTemplate<char[2]> &d) {162  a = b;163  c = d;164}165 166bool testFriendInClassTemplate(Std::WithFriend<int> wfi) {167  return wfi != wfi;168}169 170namespace hidden_specializations {171  // expected-note@cxx-templates-unimported.h:* 1+{{here}}172  void test() {173    // For functions, uses that would trigger instantiations of definitions are174    // not allowed.175    fn<void>(); // ok176    fn<char>(); // ok177    fn<int>(); // expected-error 1+{{explicit specialization of 'fn<int>' must be imported}}178    cls<void>::nested_fn(); // expected-error 1+{{explicit specialization of 'nested_fn' must be imported}}179    cls<void>::nested_fn_t<int>(); // expected-error 1+{{explicit specialization of 'nested_fn_t' must be imported}}180    cls<void>::nested_fn_t<char>(); // expected-error 1+{{explicit specialization of 'nested_fn_t' must be imported}}181 182    // For classes, uses that would trigger instantiations of definitions are183    // not allowed.184    cls<void> *k0; // ok185    cls<char> *k1; // ok186    cls<int> *k2; // ok187    cls<int*> *k3; // ok188    cls<void>::nested_cls *nk1; // ok189    cls<void>::nested_cls_t<int> *nk2; // ok190    cls<void>::nested_cls_t<char> *nk3; // ok191    cls<int> uk1; // expected-error 1+{{explicit specialization of 'cls<int>' must be imported}} expected-error 1+{{definition of}}192    cls<int*> uk3; // expected-error 1+{{partial specialization of 'cls<T *>' must be imported}} expected-error 1+{{definition of}}193    cls<char*> uk4; // expected-error 1+{{partial specialization of 'cls<T *>' must be imported}} expected-error 1+{{definition of}}194    cls<void>::nested_cls unk1; // expected-error 1+{{explicit specialization of 'nested_cls' must be imported}} expected-error 1+{{definition of}}195    cls<void>::nested_cls_t<int> unk2; // expected-error 1+{{explicit specialization of 'nested_cls_t' must be imported}} expected-error 1+{{definition of}}196    // expected-error@cxx-templates-unimported.h:29 {{explicit specialization of 'nested_cls_t' must be imported}}197    // expected-note@-2 {{in evaluation of exception specification}}198    cls<void>::nested_cls_t<char> unk3; // expected-error 1+{{explicit specialization of 'nested_cls_t' must be imported}}199 200    // For enums, uses that would trigger instantiations of definitions are not201    // allowed.202    cls<void>::nested_enum e; // ok203    (void)cls<void>::nested_enum::e; // expected-error 1+{{definition of 'nested_enum' must be imported}} expected-error 1+{{declaration of 'e'}}204 205    // For variable template specializations, no uses are allowed because206    // specializations can change the type.207    (void)sizeof(var<void>); // ok208    (void)sizeof(var<char>); // ok209    (void)sizeof(var<int>); // expected-error 1+{{explicit specialization of 'var<int>' must be imported}}210    (void)sizeof(var<int*>); // expected-error 1+{{partial specialization of 'var<T *>' must be imported}}211    (void)sizeof(var<char*>); // expected-error 1+{{partial specialization of 'var<T *>' must be imported}}212    (void)sizeof(cls<void>::nested_var); // ok213    (void)cls<void>::nested_var; // expected-error 1+{{explicit specialization of 'nested_var' must be imported}}214    (void)sizeof(cls<void>::nested_var_t<int>); // expected-error 1+{{explicit specialization of 'nested_var_t' must be imported}}215    (void)sizeof(cls<void>::nested_var_t<char>); // expected-error 1+{{explicit specialization of 'nested_var_t' must be imported}}216  }217 218  void cls<int>::nested_fn() {} // expected-error 1+{{explicit specialization of 'cls<int>' must be imported}} expected-error 1+{{definition of}}219  struct cls<int>::nested_cls {}; // expected-error 1+{{explicit specialization of 'cls<int>' must be imported}} expected-error 1+{{definition of}}220  int cls<int>::nested_var; // expected-error 1+{{explicit specialization of 'cls<int>' must be imported}} expected-error 1+{{definition of}}221  enum cls<int>::nested_enum : int {}; // expected-error 1+{{explicit specialization of 'cls<int>' must be imported}} expected-error 1+{{definition of}}222 223  template<typename T> void cls<T*>::nested_fn() {} // expected-error 1+{{partial specialization of 'cls<T *>' must be imported}}224  template<typename T> struct cls<T*>::nested_cls {}; // expected-error 1+{{partial specialization of 'cls<T *>' must be imported}}225  template<typename T> int cls<T*>::nested_var; // expected-error 1+{{partial specialization of 'cls<T *>' must be imported}}226  template<typename T> enum cls<T*>::nested_enum : int {}; // expected-error 1+{{partial specialization of 'cls<T *>' must be imported}}227}228 229namespace Std {230  void g(); // expected-error {{functions that differ only in their return type cannot be overloaded}}231  // expected-note@cxx-templates-common.h:21 {{previous}}232}233 234// CHECK-GLOBAL:      DeclarationName 'f'235// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'236// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'237// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'238// CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f'239 240// CHECK-NAMESPACE-N:      DeclarationName 'f'241// CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'242// CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'243// CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'244// CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f'245 246// CHECK-DUMP:      ClassTemplateDecl {{.*}} <{{.*[/\\]}}cxx-templates-common.h:1:1, {{.*}}>  col:{{.*}} in cxx_templates_common SomeTemplate247// CHECK-DUMP:        ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate248// CHECK-DUMP-NEXT:     TemplateArgument type 'char[{{1|2}}]'249// CHECK-DUMP:        ClassTemplateSpecializationDecl {{.*}} SomeTemplate definition250// CHECK-DUMP-NEXT:     DefinitionData251// CHECK-DUMP-NEXT:       DefaultConstructor252// CHECK-DUMP-NEXT:       CopyConstructor253// CHECK-DUMP-NEXT:       MoveConstructor254// CHECK-DUMP-NEXT:       CopyAssignment255// CHECK-DUMP-NEXT:       MoveAssignment256// CHECK-DUMP-NEXT:       Destructor257// CHECK-DUMP-NEXT:     TemplateArgument type 'char[{{1|2}}]'258// CHECK-DUMP:        ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate259// CHECK-DUMP-NEXT:     TemplateArgument type 'char[{{1|2}}]'260// CHECK-DUMP:        ClassTemplateSpecializationDecl {{.*}} SomeTemplate definition261// CHECK-DUMP-NEXT:     DefinitionData262// CHECK-DUMP-NEXT:       DefaultConstructor263// CHECK-DUMP-NEXT:       CopyConstructor264// CHECK-DUMP-NEXT:       MoveConstructor265// CHECK-DUMP-NEXT:       CopyAssignment266// CHECK-DUMP-NEXT:       MoveAssignment267// CHECK-DUMP-NEXT:       Destructor268// CHECK-DUMP-NEXT:     TemplateArgument type 'char[{{1|2}}]'269