annotate clang/test/SemaTemplate/instantiate-sizeof.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -std=c++11 %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 // Make sure we handle contexts correctly with sizeof
anatofuz
parents:
diff changeset
4 template<typename T> void f(T n) {
anatofuz
parents:
diff changeset
5 int buffer[n];
anatofuz
parents:
diff changeset
6 [] { int x = sizeof(sizeof(buffer)); }();
anatofuz
parents:
diff changeset
7 }
anatofuz
parents:
diff changeset
8 int main() {
anatofuz
parents:
diff changeset
9 f<int>(1);
anatofuz
parents:
diff changeset
10 }
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 // Make sure we handle references to non-static data members in unevaluated
anatofuz
parents:
diff changeset
13 // contexts in class template methods correctly. Previously we assumed these
anatofuz
parents:
diff changeset
14 // would be valid MemberRefExprs, but they have no 'this' so we need to form a
anatofuz
parents:
diff changeset
15 // DeclRefExpr to the FieldDecl instead.
anatofuz
parents:
diff changeset
16 // PR26893
anatofuz
parents:
diff changeset
17 template <class T>
anatofuz
parents:
diff changeset
18 struct M {
anatofuz
parents:
diff changeset
19 M() {}; // expected-note {{in instantiation of default member initializer 'M<S>::m' requested here}}
anatofuz
parents:
diff changeset
20 int m = *T::x; // expected-error {{invalid use of non-static data member 'x'}}
anatofuz
parents:
diff changeset
21 void f() {
anatofuz
parents:
diff changeset
22 // These are valid.
anatofuz
parents:
diff changeset
23 static_assert(sizeof(T::x) == 8, "ptr");
anatofuz
parents:
diff changeset
24 static_assert(sizeof(*T::x) == 4, "int");
anatofuz
parents:
diff changeset
25 }
anatofuz
parents:
diff changeset
26 };
anatofuz
parents:
diff changeset
27 struct S { int *x; };
anatofuz
parents:
diff changeset
28 template struct M<S>; // expected-note {{in instantiation of member function 'M<S>::M' requested here}}
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 // Similar test case for PR26893.
anatofuz
parents:
diff changeset
31 template <typename T=void>
anatofuz
parents:
diff changeset
32 struct bar {
anatofuz
parents:
diff changeset
33 struct foo { int array[10]; };
anatofuz
parents:
diff changeset
34 int baz() { return sizeof(foo::array); }
anatofuz
parents:
diff changeset
35 };
anatofuz
parents:
diff changeset
36 template struct bar<>;