Douglas Gregor | 65019ac | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fms-extensions -std=c++11 %s -verify |
Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 2 | |
| 3 | struct Nontemplate { |
| 4 | typedef int type; |
| 5 | }; |
| 6 | |
| 7 | template<typename T> |
| 8 | struct 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 | |
| 26 | X<int>::type i1; |
| 27 | X<int>::type2 i2; // expected-error{{no type named 'type2' in 'X<int>'}} |
| 28 | X<int>::type3 i3; |
| 29 | X<int>::type4 i4; // expected-error{{no type named 'type4' in 'X<int>'}} |
| 30 | |
| 31 | struct HasFoo { |
| 32 | void foo(); |
| 33 | }; |
| 34 | struct HasBar { |
| 35 | void bar(int); |
| 36 | void bar(float); |
| 37 | }; |
| 38 | |
| 39 | template<typename T> |
| 40 | void f(T t) { |
| 41 | __if_exists(T::foo) { |
| 42 | { } |
| 43 | t.foo(); |
| 44 | } |
| 45 | |
| 46 | __if_not_exists(T::bar) { |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 47 | int *i = t; // expected-error{{no viable conversion from 'HasFoo' to 'int *'}} |
Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 48 | { } |
| 49 | } |
Francois Pichet | 9d24a8b | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 50 | |
| 51 | int array2[] = {
|
| 52 | 0,
|
| 53 | __if_exists(T::bar) {2, }// expected-warning{{dependent __if_exists declarations are ignored}}
|
| 54 | 3
|
| 55 | };
|
Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 58 | template void f(HasFoo); // expected-note{{in instantiation of function template specialization 'f<HasFoo>' requested here}} |
Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 59 | template void f(HasBar); |
Douglas Gregor | 65019ac | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 60 | |
| 61 | template<typename T, typename ...Ts> |
| 62 | void g(T, Ts...) { |
| 63 | __if_exists(T::operator Ts) { // expected-error{{__if_exists name contains unexpanded parameter pack 'Ts'}} |
| 64 | } |
| 65 | |
| 66 | __if_not_exists(Ts::operator T) { // expected-error{{__if_not_exists name contains unexpanded parameter pack 'Ts'}} |
| 67 | } |
| 68 | } |