diff options
Diffstat (limited to 'test/Modules/cxx-templates.cpp')
-rw-r--r-- | test/Modules/cxx-templates.cpp | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/test/Modules/cxx-templates.cpp b/test/Modules/cxx-templates.cpp index 65f41f677be5..cbe9f3508951 100644 --- a/test/Modules/cxx-templates.cpp +++ b/test/Modules/cxx-templates.cpp @@ -1,7 +1,8 @@ // RUN: rm -rf %t -// 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 -// 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 -// RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11 +// RUN: not %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups | FileCheck %s --check-prefix=CHECK-GLOBAL +// RUN: not %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -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 +// RUN: not %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump | FileCheck %s --check-prefix=CHECK-DUMP +// RUN: %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11 @import cxx_templates_a; @import cxx_templates_b; @@ -28,8 +29,8 @@ void g() { N::f<double>(1.0); N::f<int>(); N::f(); // expected-error {{no matching function}} - // expected-note@Inputs/cxx-templates-b.h:6 {{couldn't infer template argument}} - // expected-note@Inputs/cxx-templates-b.h:7 {{requires single argument 't'}} + // expected-note@Inputs/cxx-templates-a.h:6 {{couldn't infer template argument}} + // expected-note@Inputs/cxx-templates-a.h:7 {{requires 1 argument}} template_param_kinds_1<0>(); // ok, from cxx-templates-a.h template_param_kinds_1<int>(); // ok, from cxx-templates-b.h @@ -70,8 +71,15 @@ void g() { // Trigger the instantiation of a template in 'a' that uses a type defined in // 'b_impl'. That type is not visible here, nor in 'a'. This fails; there is // no reason why DefinedInBImpl should be visible here. + // + // We turn off error recovery for modules in this test (so we don't get an + // implicit import of cxx_templates_b_impl), and that results in us producing + // a big spew of errors here. + // // expected-error@Inputs/cxx-templates-a.h:19 {{definition of 'DefinedInBImpl' must be imported}} - // expected-note@Inputs/cxx-templates-b-impl.h:1 {{definition is here}} + // expected-note@Inputs/cxx-templates-b-impl.h:1 +{{definition is here}} + // expected-error@Inputs/cxx-templates-a.h:19 +{{}} + // expected-error@Inputs/cxx-templates-a.h:20 +{{}} PerformDelayedLookup(defined_in_b_impl); // expected-note {{in instantiation of}} merge_templates_a = merge_templates_b; // ok, same type @@ -88,8 +96,23 @@ void g() { static_assert(enum_c_from_a == enum_c_from_b, ""); CommonTemplate<int> cti; CommonTemplate<int>::E eee = CommonTemplate<int>::c; + + TemplateInstantiationVisibility<char[1]> tiv1; + TemplateInstantiationVisibility<char[2]> tiv2; + TemplateInstantiationVisibility<char[3]> tiv3; // expected-error {{must be imported from module 'cxx_templates_b_impl'}} + // expected-note@cxx-templates-b-impl.h:10 {{previous definition is here}} + TemplateInstantiationVisibility<char[4]> tiv4; + + int &p = WithPartialSpecializationUse().f(); + int &q = WithExplicitSpecializationUse().inner_template<int>(); } +static_assert(Outer<int>::Inner<int>::f() == 1, ""); +static_assert(Outer<int>::Inner<int>::g() == 2, ""); + +static_assert(MergeTemplateDefinitions<int>::f() == 1, ""); +static_assert(MergeTemplateDefinitions<int>::g() == 2, ""); + RedeclaredAsFriend<int> raf1; RedeclareTemplateAsFriend<double> rtaf; RedeclaredAsFriend<double> raf2; @@ -116,6 +139,15 @@ void testImplicitSpecialMembers(SomeTemplate<char[1]> &a, c = d; } +bool testFriendInClassTemplate(Std::WithFriend<int> wfi) { + return wfi != wfi; +} + +namespace Std { + void g(); // expected-error {{functions that differ only in their return type cannot be overloaded}} + // expected-note@cxx-templates-common.h:21 {{previous}} +} + // CHECK-GLOBAL: DeclarationName 'f' // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f' // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f' @@ -123,3 +155,13 @@ void testImplicitSpecialMembers(SomeTemplate<char[1]> &a, // CHECK-NAMESPACE-N: DeclarationName 'f' // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f' // CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f' + +// CHECK-DUMP: ClassTemplateDecl {{.*}} <{{.*[/\\]}}cxx-templates-common.h:1:1, {{.*}}> col:{{.*}} in cxx_templates_common SomeTemplate +// CHECK-DUMP: ClassTemplateSpecializationDecl {{.*}} prev [[CHAR2:[^ ]*]] {{.*}} SomeTemplate +// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]' +// CHECK-DUMP: ClassTemplateSpecializationDecl [[CHAR2]] {{.*}} SomeTemplate definition +// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]' +// CHECK-DUMP: ClassTemplateSpecializationDecl {{.*}} prev [[CHAR1:[^ ]*]] {{.*}} SomeTemplate +// CHECK-DUMP-NEXT: TemplateArgument type 'char [1]' +// CHECK-DUMP: ClassTemplateSpecializationDecl [[CHAR1]] {{.*}} SomeTemplate definition +// CHECK-DUMP-NEXT: TemplateArgument type 'char [1]' |