| 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) { // 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 |
} |
| 10 |
int main() { |
| 11 |
f<int>(1); // #instantiate |
| 12 |
} |
| 13 |
|
| 14 |
// Make sure we handle references to non-static data members in unevaluated |
| 15 |
// contexts in class template methods correctly. Previously we assumed these |
| 16 |
// would be valid MemberRefExprs, but they have no 'this' so we need to form a |
| 17 |
// DeclRefExpr to the FieldDecl instead. |
| 18 |
// PR26893 |
| 19 |
template <class T> |
| 20 |
struct 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 |
}; |
| 29 |
struct S { int *x; }; |
| 30 |
template struct M<S>; // expected-note {{in instantiation of member function 'M<S>::M' requested here}} |
| 31 |
|
| 32 |
// Similar test case for PR26893. |
| 33 |
template <typename T=void> |
| 34 |
struct bar { |
| 35 |
struct foo { int array[10]; }; |
| 36 |
int baz() { return sizeof(foo::array); } |
| 37 |
}; |
| 38 |
template struct bar<>; |