xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/ms-if-exists.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fms-extensions -std=c++11 %s -verify
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc struct Nontemplate {
4*f4a2713aSLionel Sambuc   typedef int type;
5*f4a2713aSLionel Sambuc };
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc template<typename T>
8*f4a2713aSLionel Sambuc struct X {
__if_existsX9*f4a2713aSLionel Sambuc   __if_exists(Nontemplate::type) {
10*f4a2713aSLionel Sambuc     typedef Nontemplate::type type;
11*f4a2713aSLionel Sambuc   }
12*f4a2713aSLionel Sambuc 
__if_existsX13*f4a2713aSLionel Sambuc   __if_exists(Nontemplate::value) {
14*f4a2713aSLionel Sambuc     typedef Nontemplate::value type2;
15*f4a2713aSLionel Sambuc   }
16*f4a2713aSLionel Sambuc 
__if_not_existsX17*f4a2713aSLionel Sambuc   __if_not_exists(Nontemplate::value) {
18*f4a2713aSLionel Sambuc     typedef int type3;
19*f4a2713aSLionel Sambuc   }
20*f4a2713aSLionel Sambuc 
__if_existsX21*f4a2713aSLionel Sambuc   __if_exists(T::X) { // expected-warning{{dependent __if_exists declarations are ignored}}
22*f4a2713aSLionel Sambuc     typedef T::X type4;
23*f4a2713aSLionel Sambuc   }
24*f4a2713aSLionel Sambuc };
25*f4a2713aSLionel Sambuc 
26*f4a2713aSLionel Sambuc X<int>::type i1;
27*f4a2713aSLionel Sambuc X<int>::type2 i2; // expected-error{{no type named 'type2' in 'X<int>'}}
28*f4a2713aSLionel Sambuc X<int>::type3 i3;
29*f4a2713aSLionel Sambuc X<int>::type4 i4; // expected-error{{no type named 'type4' in 'X<int>'}}
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc struct HasFoo {
32*f4a2713aSLionel Sambuc   void foo();
33*f4a2713aSLionel Sambuc };
34*f4a2713aSLionel Sambuc struct HasBar {
35*f4a2713aSLionel Sambuc   void bar(int);
36*f4a2713aSLionel Sambuc   void bar(float);
37*f4a2713aSLionel Sambuc };
38*f4a2713aSLionel Sambuc 
39*f4a2713aSLionel Sambuc template<typename T>
f(T t)40*f4a2713aSLionel Sambuc void f(T t) {
41*f4a2713aSLionel Sambuc   __if_exists(T::foo) {
42*f4a2713aSLionel Sambuc     { }
43*f4a2713aSLionel Sambuc     t.foo();
44*f4a2713aSLionel Sambuc   }
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc   __if_not_exists(T::bar) {
47*f4a2713aSLionel Sambuc     int *i = t; // expected-error{{no viable conversion from 'HasFoo' to 'int *'}}
48*f4a2713aSLionel Sambuc     { }
49*f4a2713aSLionel Sambuc   }
50*f4a2713aSLionel Sambuc 
51*f4a2713aSLionel Sambuc   int array2[] = {
52*f4a2713aSLionel Sambuc     0,
53*f4a2713aSLionel Sambuc     __if_exists(T::bar) {2, }// expected-warning{{dependent __if_exists declarations are ignored}}
54*f4a2713aSLionel Sambuc     3
55*f4a2713aSLionel Sambuc   };
56*f4a2713aSLionel Sambuc }
57*f4a2713aSLionel Sambuc 
58*f4a2713aSLionel Sambuc template void f(HasFoo); // expected-note{{in instantiation of function template specialization 'f<HasFoo>' requested here}}
59*f4a2713aSLionel Sambuc template void f(HasBar);
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc template<typename T, typename ...Ts>
g(T,Ts...)62*f4a2713aSLionel Sambuc void g(T, Ts...) {
63*f4a2713aSLionel Sambuc   __if_exists(T::operator Ts) { // expected-error{{__if_exists name contains unexpanded parameter pack 'Ts'}}
64*f4a2713aSLionel Sambuc   }
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc   __if_not_exists(Ts::operator T) { // expected-error{{__if_not_exists name contains unexpanded parameter pack 'Ts'}}
67*f4a2713aSLionel Sambuc   }
68*f4a2713aSLionel Sambuc }
69