| 1 |
// P0847R7 |
| 2 |
// { dg-do compile { target c++23 } } |
| 3 |
|
| 4 |
// rejection and diagnosis of incorrect uses of 'this' in declarations and definitions |
| 5 |
|
| 6 |
using func_type = void(this int); // { dg-line func_type_line } |
| 7 |
// { dg-error "a function type cannot have an explicit object parameter" "" { target *-*-* } func_type_line } |
| 8 |
// { dg-note "the type of an explicit object member function is a regular function type" "" { target *-*-* } func_type_line } |
| 9 |
|
| 10 |
using func_ptr_type = void(*)(this int); // { dg-line func_ptr_type_line } |
| 11 |
// { dg-error "a pointer to function type cannot have an explicit object parameter" "" { target *-*-* } func_ptr_type_line } |
| 12 |
// { dg-note "the type of a pointer to explicit object member function is a regular pointer to function type" "" { target *-*-* } func_ptr_type_line } |
| 13 |
|
| 14 |
struct S { |
| 15 |
static void f(this S) {} // { dg-line static_member_func_line } |
| 16 |
}; |
| 17 |
// { dg-error "an explicit object member function cannot be 'static'" "" { target *-*-* } static_member_func_line } |
| 18 |
// { dg-note "explicit object parameter declared here" "" { target *-*-* } static_member_func_line } |
| 19 |
|
| 20 |
using mem_func_type = void (S::*)(this S&); // { dg-line mem_func_type_line } |
| 21 |
// { dg-error "a pointer to member function type cannot have an explicit object parameter" "" { target *-*-* } mem_func_type_line } |
| 22 |
// { dg-note "the type of a pointer to explicit object member function is a regular pointer to function type" "" { target *-*-* } mem_func_type_line } |
| 23 |
|
| 24 |
void f(this int); // { dg-error "a non-member function cannot have an explicit object parameter" } |
| 25 |
void f(this int) {} // { dg-error "a non-member function cannot have an explicit object parameter" } |
| 26 |
|