blob: 8ac4e2418cfbd302ca0d9899daba8adf05612036 [file] [log] [blame]
Douglas Gregor65019ac2011-10-25 03:44:56 +00001// RUN: %clang_cc1 -fms-extensions -std=c++11 %s -verify
Douglas Gregor3896fc52011-10-24 22:31:10 +00002
3struct Nontemplate {
4 typedef int type;
5};
6
7template<typename T>
8struct X {
9 __if_exists(Nontemplate::type) {
10 typedef Nontemplate::type type;
11 }
12
13 __if_exists(Nontemplate::value) {
14 typedef Nontemplate::value type2;
15 }
16
17 __if_not_exists(Nontemplate::value) {
18 typedef int type3;
19 }
20
21 __if_exists(T::X) { // expected-warning{{dependent __if_exists declarations are ignored}}
22 typedef T::X type4;
23 }
24};
25
26X<int>::type i1;
27X<int>::type2 i2; // expected-error{{no type named 'type2' in 'X<int>'}}
28X<int>::type3 i3;
29X<int>::type4 i4; // expected-error{{no type named 'type4' in 'X<int>'}}
30
31struct HasFoo {
32 void foo();
33};
34struct HasBar {
35 void bar(int);
36 void bar(float);
37};
38
39template<typename T>
40void f(T t) {
41 __if_exists(T::foo) {
42 { }
43 t.foo();
44 }
45
46 __if_not_exists(T::bar) {
Douglas Gregorba0513d2011-10-25 01:33:02 +000047 int *i = t; // expected-error{{no viable conversion from 'HasFoo' to 'int *'}}
Douglas Gregor3896fc52011-10-24 22:31:10 +000048 { }
49 }
50}
51
Douglas Gregorba0513d2011-10-25 01:33:02 +000052template void f(HasFoo); // expected-note{{in instantiation of function template specialization 'f<HasFoo>' requested here}}
Douglas Gregor3896fc52011-10-24 22:31:10 +000053template void f(HasBar);
Douglas Gregor65019ac2011-10-25 03:44:56 +000054
55template<typename T, typename ...Ts>
56void g(T, Ts...) {
57 __if_exists(T::operator Ts) { // expected-error{{__if_exists name contains unexpanded parameter pack 'Ts'}}
58 }
59
60 __if_not_exists(Ts::operator T) { // expected-error{{__if_not_exists name contains unexpanded parameter pack 'Ts'}}
61 }
62}