diff --git a/clang/test/SemaObjCXX/arc-templates.mm b/clang/test/SemaObjCXX/arc-templates.mm index ebede6404f90..81425985e629 100644 --- a/clang/test/SemaObjCXX/arc-templates.mm +++ b/clang/test/SemaObjCXX/arc-templates.mm @@ -1,4 +1,7 @@ -// RUN: %clang_cc1 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -fblocks %s +// RUN: %clang_cc1 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -fblocks -std=c++11 %s + +#define CONSUMED __attribute__((ns_consumed)) +#define PRODUCED __attribute__((ns_returns_retained)) @interface A @end @@ -318,3 +321,124 @@ namespace rdar15713945 { double &dr = (f)(unsafe); } } + +namespace consumed { + void take_yes_no(void (&)(id CONSUMED, id)); // expected-note 2 {{candidate function not viable}} + void take_no_yes(void (&)(id, CONSUMED id)); // expected-note 2 {{candidate function not viable}} + void take_yes_yes(void (&)(CONSUMED id, CONSUMED id)); // expected-note 2 {{candidate function not viable}} + + template void consumes_first(id CONSUMED, As...); + void test1() { + take_yes_no(consumes_first); + take_no_yes(consumes_first); // expected-error {{no matching function}} + take_yes_yes(consumes_first); // expected-error {{no matching function}} + } + + template void consumes_rest(id, CONSUMED As...); + void test2() { + take_yes_no(consumes_rest); // expected-error {{no matching function}} + take_no_yes(consumes_rest); + take_yes_yes(consumes_rest); // expected-error {{no matching function}} + } + + template void consumes_two(CONSUMED T, CONSUMED U); + void test3() { + take_yes_no(consumes_two); // expected-error {{no matching function}} + take_no_yes(consumes_two); // expected-error {{no matching function}} + take_yes_yes(consumes_two); + } +} + +namespace consumed_nested { + void take_yes_no(void (&)(id CONSUMED, id)); // expected-note 4 {{candidate function not viable}} + void take_no_yes(void (&)(id, CONSUMED id)); // expected-note 4 {{candidate function not viable}} + void take_yes_yes(void (&)(CONSUMED id, CONSUMED id)); // expected-note 4 {{candidate function not viable}} + + template struct consumes_first { + template static void fn(id CONSUMED, As...); + }; + void test1() { + take_yes_no(consumes_first<1>::fn); + take_no_yes(consumes_first<2>::fn); // expected-error {{no matching function}} + take_yes_yes(consumes_first<3>::fn); // expected-error {{no matching function}} + take_yes_no(consumes_first<4>::fn); + take_no_yes(consumes_first<5>::fn); // expected-error {{no matching function}} + take_yes_yes(consumes_first<6>::fn); // expected-error {{no matching function}} + } + + template struct consumes_rest { + template static void fn(id, CONSUMED As...); + }; + void test2() { + take_yes_no(consumes_rest<1>::fn); // expected-error {{no matching function}} + take_no_yes(consumes_rest<2>::fn); + take_yes_yes(consumes_rest<3>::fn); // expected-error {{no matching function}} + take_yes_no(consumes_rest<4>::fn); // expected-error {{no matching function}} + take_no_yes(consumes_rest<5>::fn); + take_yes_yes(consumes_rest<6>::fn); // expected-error {{no matching function}} + } + + template struct consumes_two { + template static void fn(CONSUMED T, CONSUMED U); + }; + void test3() { + take_yes_no(consumes_two<1>::fn); // expected-error {{no matching function}} + take_no_yes(consumes_two<2>::fn); // expected-error {{no matching function}} + take_yes_yes(consumes_two<3>::fn); + take_yes_no(consumes_two<1>::fn); // expected-error {{no matching function}} + take_no_yes(consumes_two<2>::fn); // expected-error {{no matching function}} + take_yes_yes(consumes_two<3>::fn); + } +} + +namespace produced { + void take_yes(PRODUCED id (&)()); // expected-note 2 {{candidate function not viable}} + void take_no(id (&)()); // expected-note 2 {{candidate function not viable}} + + template T non_produces1(); + template T non_produces2(); + template T non_produces3(); + template T non_produces4(); + void test1() { + take_yes(non_produces1); // expected-error {{no matching function}} + take_yes(non_produces2); // expected-error {{no matching function}} + take_no(non_produces3); + take_no(non_produces4); + } + + template PRODUCED T produces1(); + template PRODUCED T produces2(); + template PRODUCED T produces3(); + template PRODUCED T produces4(); + void test2() { + take_yes(produces1); + take_yes(produces2); + take_no(produces3); // expected-error {{no matching function}} + take_no(produces4); // expected-error {{no matching function}} + } +} + +namespace produced_nested { + void take_yes(PRODUCED id (&)()); // expected-note 2 {{candidate function not viable}} + void take_no(id (&)()); // expected-note 2 {{candidate function not viable}} + + template struct non_produces { + template static T fn(); + }; + void test1() { + take_yes(non_produces<1>::fn); // expected-error {{no matching function}} + take_yes(non_produces<2>::fn); // expected-error {{no matching function}} + take_no(non_produces<3>::fn); + take_no(non_produces<4>::fn); + } + + template struct produces { + template static PRODUCED T fn(); + }; + void test2() { + take_yes(produces<1>::fn); + take_yes(produces<2>::fn); + take_no(produces<3>::fn); // expected-error {{no matching function}} + take_no(produces<4>::fn); // expected-error {{no matching function}} + } +}