150
|
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -std=c++11 %s
|
|
2
|
|
3 // Make sure we handle contexts correctly with sizeof
|
|
4 template<typename T> void f(T n) {
|
|
5 int buffer[n];
|
|
6 [] { int x = sizeof(sizeof(buffer)); }();
|
|
7 }
|
|
8 int main() {
|
|
9 f<int>(1);
|
|
10 }
|
|
11
|
|
12 // Make sure we handle references to non-static data members in unevaluated
|
|
13 // contexts in class template methods correctly. Previously we assumed these
|
|
14 // would be valid MemberRefExprs, but they have no 'this' so we need to form a
|
|
15 // DeclRefExpr to the FieldDecl instead.
|
|
16 // PR26893
|
|
17 template <class T>
|
|
18 struct M {
|
|
19 M() {}; // expected-note {{in instantiation of default member initializer 'M<S>::m' requested here}}
|
|
20 int m = *T::x; // expected-error {{invalid use of non-static data member 'x'}}
|
|
21 void f() {
|
|
22 // These are valid.
|
|
23 static_assert(sizeof(T::x) == 8, "ptr");
|
|
24 static_assert(sizeof(*T::x) == 4, "int");
|
|
25 }
|
|
26 };
|
|
27 struct S { int *x; };
|
|
28 template struct M<S>; // expected-note {{in instantiation of member function 'M<S>::M' requested here}}
|
|
29
|
|
30 // Similar test case for PR26893.
|
|
31 template <typename T=void>
|
|
32 struct bar {
|
|
33 struct foo { int array[10]; };
|
|
34 int baz() { return sizeof(foo::array); }
|
|
35 };
|
|
36 template struct bar<>;
|