Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics5.C

raw
1 // P0847R7
2 // { dg-do compile { target c++23 } }
3
4 // rejection and diagnosis of invalid uses of 'this' in body of xobj member functions
5
6 // { dg-message "In explicit object member function" "" { target *-*-* } 0 }
7
8 struct S0 {
9 int _n;
10 void f(this S0& s) { // { dg-note {use explicit object parameter 's' instead} }
11 this->_n = 10; // { dg-error "'this' is unavailable for explicit object member functions" }
12 // suppress unused variable warning
13 static_cast<void>(s);
14 }
15 };
16
17 struct S1 {
18 int _n;
19 void f(this S1&) { // { dg-note "name the explicit object parameter" }
20 this->_n = 10; // { dg-error "'this' is unavailable for explicit object member functions" }
21 }
22 };
23