Created on 2014-01-13.00:00:00 last changed 27 months ago
[Accepted at the November, 2020 meeting as part of paper P1787R6 and moved to DR at the February, 2021 meeting.]
The description of the use of this found in _N4567_.5.1.1 [expr.prim.general] paragraphs 3 and 4 allow it to appear in the declaration of a non-static member function following the optional cv-qualifier-seq and in the brace-or-equal-initializer of a non-static data member; all other uses are prohibited. These restrictions appear to allow questionable uses of this in several contexts. For example:
template <typename T> struct Fish { static const bool value = true; }; struct Other { int p(); auto q() -> decltype(p()) *; }; class Outer { // The following declares a member function of class Other. // Is this interpreted as Other* or Outer*? friend auto Other::q() -> decltype(this->p()) *; int g(); int f() { extern void f(decltype(this->g()) *); struct Inner { // The following are all within the declaration of Outer::f(). // Is this Outer* or Inner*? static_assert(Fish<decltype(this->g())>::value, ""); enum { X = Fish<decltype(this->f())>::value }; struct Inner2 : Fish<decltype(this->g())> { }; friend void f(decltype(this->g()) *); friend auto Other::q() -> decltype(this->p()) *; }; return 0; } };
struct A { int f(); bool b = [] { struct Local { static_assert(sizeof this->f() == sizeof(int), ""); // A or Local? }; }; };
There is implementation divergence on the treatment of these examples.
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-08-19 07:54:33 | admin | set | status: drwp -> cd6 |
2021-02-24 00:00:00 | admin | set | status: accepted -> drwp |
2020-12-15 00:00:00 | admin | set | status: drafting -> accepted |
2014-01-13 00:00:00 | admin | create |