| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
| 2 |
struct Y { |
| 3 |
int x; |
| 4 |
}; |
| 5 |
|
| 6 |
template<typename T> |
| 7 |
struct X1 { |
| 8 |
int f(T* ptr, int T::*pm) { |
| 9 |
// expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}} |
| 10 |
return ptr->*pm; |
| 11 |
} |
| 12 |
}; |
| 13 |
|
| 14 |
template struct X1<Y>; |
| 15 |
template struct X1<int>; // expected-note{{instantiation}} |
| 16 |
|
| 17 |
template<typename T, typename Class> |
| 18 |
struct X2 { |
| 19 |
T f(Class &obj, T Class::*pm) { // expected-error{{to a reference}} \ |
| 20 |
// expected-error{{member pointer to void}} |
| 21 |
return obj.*pm; |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
template struct X2<int, Y>; |
| 26 |
template struct X2<int&, Y>; // expected-note{{instantiation}} |
| 27 |
template struct X2<const void, Y>; // expected-note{{instantiation}} |
| 28 |
|
| 29 |
template<typename T, typename Class, T Class::*Ptr> |
| 30 |
struct X3 { |
| 31 |
X3<T, Class, Ptr> &operator=(const T& value) { |
| 32 |
return *this; |
| 33 |
} |
| 34 |
}; |
| 35 |
|
| 36 |
X3<int, Y, &Y::x> x3; |
| 37 |
|
| 38 |
typedef int Y::*IntMember; |
| 39 |
|
| 40 |
template<IntMember Member> |
| 41 |
struct X4 { |
| 42 |
X3<int, Y, Member> member; |
| 43 |
|
| 44 |
int &getMember(Y& y) { return y.*Member; } |
| 45 |
}; |
| 46 |
|
| 47 |
int &get_X4(X4<&Y::x> x4, Y& y) { |
| 48 |
return x4.getMember(y); |
| 49 |
} |
| 50 |
|
| 51 |
template<IntMember Member> |
| 52 |
void accept_X4(X4<Member>); |
| 53 |
|
| 54 |
void test_accept_X4(X4<&Y::x> x4) { |
| 55 |
accept_X4(x4); |
| 56 |
} |
| 57 |
|
| 58 |
namespace ValueDepMemberPointer { |
| 59 |
template <void (*)()> struct instantiate_function {}; |
| 60 |
template <typename T> struct S { |
| 61 |
static void instantiate(); |
| 62 |
typedef instantiate_function<&S::instantiate> x; // expected-note{{instantiation}} |
| 63 |
}; |
| 64 |
template <typename T> void S<T>::instantiate() { |
| 65 |
int a[(int)sizeof(T)-42]; // expected-error{{array with a negative size}} |
| 66 |
} |
| 67 |
S<int> s; |
| 68 |
} |
| 69 |
|
| 70 |
namespace PR18192 { |
| 71 |
struct A { struct { int n; }; }; |
| 72 |
template<int A::*> struct X {}; |
| 73 |
constexpr int A::*p = &A::n; |
| 74 |
X<p> x; // expected-error{{not a pointer to member constant}} |
| 75 |
} |