xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/metafun-apply.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc struct add_pointer {
4*f4a2713aSLionel Sambuc   template<typename T>
5*f4a2713aSLionel Sambuc   struct apply {
6*f4a2713aSLionel Sambuc     typedef T* type;
7*f4a2713aSLionel Sambuc   };
8*f4a2713aSLionel Sambuc };
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc struct add_reference {
11*f4a2713aSLionel Sambuc   template<typename T>
12*f4a2713aSLionel Sambuc   struct apply {
13*f4a2713aSLionel Sambuc     typedef T& type; // expected-error{{cannot form a reference to 'void'}}
14*f4a2713aSLionel Sambuc   };
15*f4a2713aSLionel Sambuc };
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc struct bogus {
18*f4a2713aSLionel Sambuc   struct apply {
19*f4a2713aSLionel Sambuc     typedef int type;
20*f4a2713aSLionel Sambuc   };
21*f4a2713aSLionel Sambuc };
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc template<typename MetaFun, typename T>
24*f4a2713aSLionel Sambuc struct apply1 {
25*f4a2713aSLionel Sambuc   typedef typename MetaFun::template apply<T>::type type; // expected-note{{in instantiation of template class 'add_reference::apply<void>' requested here}} \
26*f4a2713aSLionel Sambuc   // expected-error{{'apply' following the 'template' keyword does not refer to a template}}
27*f4a2713aSLionel Sambuc };
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc int i;
30*f4a2713aSLionel Sambuc apply1<add_pointer, int>::type ip = &i;
31*f4a2713aSLionel Sambuc apply1<add_reference, int>::type ir = i;
32*f4a2713aSLionel Sambuc apply1<add_reference, float>::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot bind to a value of unrelated type 'int'}}
33*f4a2713aSLionel Sambuc 
test()34*f4a2713aSLionel Sambuc void test() {
35*f4a2713aSLionel Sambuc   apply1<add_reference, void>::type t; // expected-note{{in instantiation of template class 'apply1<add_reference, void>' requested here}}
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc   apply1<bogus, int>::type t2; // expected-note{{in instantiation of template class 'apply1<bogus, int>' requested here}}
38*f4a2713aSLionel Sambuc }
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc 
41