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. }; } };