blob: 660e70549e30f93c94ce4c5fc1056c6cf794185d [file] [log] [blame]
Reid Kleckner4776f2e2016-03-11 19:17:53 +00001// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -std=c++11 %s
Eli Friedmane4f22df2012-02-29 04:03:55 +00002
3// Make sure we handle contexts correctly with sizeof
4template<typename T> void f(T n) {
5 int buffer[n];
6 [] { int x = sizeof(sizeof(buffer)); }();
7}
8int main() {
9 f<int>(1);
10}
Reid Kleckner1af391df2016-03-11 18:59:12 +000011
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
17template <class T>
18struct 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};
27struct S { int *x; };
28template struct M<S>; // expected-note {{in instantiation of member function 'M<S>::M' requested here}}
29
30// Similar test case for PR26893.
31template <typename T=void>
32struct bar {
33 struct foo { int array[10]; };
34 int baz() { return sizeof(foo::array); }
35};
36template struct bar<>;