Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaTemplate / instantiate-sizeof.cpp
blob0931ef2335c4b58aa33d9ca0265828ad7e1fc1a2
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -std=c++11 %s
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)); }();
10 int main() {
11 f<int>(1); // #instantiate
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");
29 struct S { int *x; };
30 template struct M<S>; // expected-note {{in instantiation of member function 'M<S>::M' requested here}}
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); }
38 template struct bar<>;