]> granicus.if.org Git - clang/commitdiff
Test template instantiation of ns_consumed and ns_returns_retained.
authorJohn McCall <rjmccall@apple.com>
Tue, 1 Mar 2016 06:54:30 +0000 (06:54 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 1 Mar 2016 06:54:30 +0000 (06:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262311 91177308-0d34-0410-b5e6-96231b3b80d8

test/SemaObjCXX/arc-templates.mm

index ebede6404f9076947cb7099f06a549e716d9a821..81425985e62914cdfcf406c7a2c33e9d19a9f51a 100644 (file)
@@ -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 <class... As> void consumes_first(id CONSUMED, As...);
+  void test1() {
+    take_yes_no(consumes_first<id>);
+    take_no_yes(consumes_first<id>); // expected-error {{no matching function}}
+    take_yes_yes(consumes_first<id>); // expected-error {{no matching function}}
+  }
+
+  template <class... As> void consumes_rest(id, CONSUMED As...);
+  void test2() {
+    take_yes_no(consumes_rest<id>); // expected-error {{no matching function}}
+    take_no_yes(consumes_rest<id>);
+    take_yes_yes(consumes_rest<id>); // expected-error {{no matching function}}
+  }
+
+  template <class T, class U> 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 <unsigned N> struct consumes_first {
+    template <class... As> static void fn(id CONSUMED, As...);
+  };
+  void test1() {
+    take_yes_no(consumes_first<1>::fn<id>);
+    take_no_yes(consumes_first<2>::fn<id>); // expected-error {{no matching function}}
+    take_yes_yes(consumes_first<3>::fn<id>); // 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 <unsigned N> struct consumes_rest {
+    template <class... As> static void fn(id, CONSUMED As...);
+  };
+  void test2() {
+    take_yes_no(consumes_rest<1>::fn<id>); // expected-error {{no matching function}}
+    take_no_yes(consumes_rest<2>::fn<id>);
+    take_yes_yes(consumes_rest<3>::fn<id>); // expected-error {{no matching function}}
+    take_yes_no(consumes_rest<4>::fn<id>); // expected-error {{no matching function}}
+    take_no_yes(consumes_rest<5>::fn<id>);
+    take_yes_yes(consumes_rest<6>::fn<id>); // expected-error {{no matching function}}
+  }
+
+  template <unsigned N> struct consumes_two {
+    template <class T, class U> static void fn(CONSUMED T, CONSUMED U);
+  };
+  void test3() {
+    take_yes_no(consumes_two<1>::fn<id, id>); // expected-error {{no matching function}}
+    take_no_yes(consumes_two<2>::fn<id, id>); // expected-error {{no matching function}}
+    take_yes_yes(consumes_two<3>::fn<id, id>);
+    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 <class T> T non_produces1();
+  template <class T> T non_produces2();
+  template <class T> T non_produces3();
+  template <class T> T non_produces4();
+  void test1() {
+    take_yes(non_produces1<id>); // expected-error {{no matching function}}
+    take_yes(non_produces2); // expected-error {{no matching function}}
+    take_no(non_produces3<id>);
+    take_no(non_produces4);
+  }
+
+  template <class T> PRODUCED T produces1();
+  template <class T> PRODUCED T produces2();
+  template <class T> PRODUCED T produces3();
+  template <class T> PRODUCED T produces4();
+  void test2() {
+    take_yes(produces1<id>);
+    take_yes(produces2);
+    take_no(produces3<id>); // 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 <unsigned N> struct non_produces {
+    template <class T> static T fn();
+  };
+  void test1() {
+    take_yes(non_produces<1>::fn<id>); // expected-error {{no matching function}}
+    take_yes(non_produces<2>::fn); // expected-error {{no matching function}}
+    take_no(non_produces<3>::fn<id>);
+    take_no(non_produces<4>::fn);
+  }
+
+  template <unsigned N> struct produces {
+    template <class T> static PRODUCED T fn();
+  };
+  void test2() {
+    take_yes(produces<1>::fn<id>);
+    take_yes(produces<2>::fn);
+    take_no(produces<3>::fn<id>); // expected-error {{no matching function}}
+    take_no(produces<4>::fn); // expected-error {{no matching function}}
+  }
+}