This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/59186] New: decltype(this) treated specially in trailing-return-specifier
- From: "potswa at mac dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 19 Nov 2013 06:21:53 +0000
- Subject: [Bug c++/59186] New: decltype(this) treated specially in trailing-return-specifier
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59186
Bug ID: 59186
Summary: decltype(this) treated specially in
trailing-return-specifier
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: potswa at mac dot com
In the following TU, GCC 4.9 accepts the "error" line and rejects the "Same as
previous" line.
The "this" keyword is well-defined inside the body of a nonstatic member
function, not in a trailing-return-type.
The program illustrates that decltype(this) has one well-defined meaning in a
member declaration of a local class inside a nonstatic member function, but
another meaning when the same function is written with a trailing-return-type.
struct s {
auto f() -> decltype(this) { return this; } // error: this inaccessible
void g() {
struct t {
decltype(this) g() { return static_cast<s*>(nullptr); } // OK
auto h() -> decltype(this) { return static_cast<s*>(nullptr); } // Same as
previous.
};
}
};