39 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -std=c++11 %s2 3// Make sure we handle contexts correctly with sizeof4template<typename T> void f(T n) { // expected-note {{declared here}}5 int buffer[n]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \6 expected-note {{function parameter 'n' with unknown value cannot be used in a constant expression}} \7 expected-note@#instantiate {{in instantiation of function template specialization 'f<int>' requested here}}8 [] { int x = sizeof(sizeof(buffer)); }();9}10int main() {11 f<int>(1); // #instantiate12}13 14// Make sure we handle references to non-static data members in unevaluated15// contexts in class template methods correctly. Previously we assumed these16// would be valid MemberRefExprs, but they have no 'this' so we need to form a17// DeclRefExpr to the FieldDecl instead.18// PR2689319template <class T>20struct M {21 M() {}; // expected-note {{in instantiation of default member initializer 'M<S>::m' requested here}}22 int m = *T::x; // expected-error {{invalid use of non-static data member 'x'}}23 void f() {24 // These are valid.25 static_assert(sizeof(T::x) == 8, "ptr");26 static_assert(sizeof(*T::x) == 4, "int");27 }28};29struct S { int *x; };30template struct M<S>; // expected-note {{in instantiation of member function 'M<S>::M' requested here}}31 32// Similar test case for PR26893.33template <typename T=void>34struct bar {35 struct foo { int array[10]; };36 int baz() { return sizeof(foo::array); }37};38template struct bar<>;39