[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / restrict-this.cpp
blobe78c8e0d56e2f877b2f41da32141cf5c7be478e3
1 // RUN: %clang_cc1 -verify -fsyntax-only %s
2 // expected-no-diagnostics
4 struct C {
5 void f() __restrict {
6 static_assert(__is_same(decltype(this), C *__restrict));
7 (void) [this]() {
8 static_assert(__is_same(decltype(this), C *__restrict));
9 (void) [this]() { static_assert(__is_same(decltype(this), C *__restrict)); };
11 // By-value capture means 'this' is now a different object; do not
12 // make it __restrict.
13 (void) [*this]() { static_assert(__is_same(decltype(this), const C *)); };
14 (void) [*this]() mutable { static_assert(__is_same(decltype(this), C *)); };
19 template <typename T> struct TC {
20 void f() __restrict {
21 static_assert(__is_same(decltype(this), TC<int> *__restrict));
22 (void) [this]() {
23 static_assert(__is_same(decltype(this), TC<int> *__restrict));
24 (void) [this]() { static_assert(__is_same(decltype(this), TC<int> *__restrict)); };
26 // By-value capture means 'this' is now a different object; do not
27 // make it __restrict.
28 (void) [*this]() { static_assert(__is_same(decltype(this), const TC<int> *)); };
29 (void) [*this]() mutable { static_assert(__is_same(decltype(this), TC<int> *)); };
34 void f() {
35 TC<int>{}.f();
38 namespace gh18121 {
39 struct Foo {
40 void member() __restrict {
41 Foo *__restrict This = this;
46 namespace gh42411 {
47 struct foo {
48 int v;
49 void f() const __restrict {
50 static_assert(__is_same(decltype((v)), const int&));
51 (void) [this]() { static_assert(__is_same(decltype((v)), const int&)); };
56 namespace gh82941 {
57 void f(int& x) {
58 (void)x;
61 class C {
62 int x;
63 void g() __restrict;
66 void C::g() __restrict {
67 f(this->x);