This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/59186] New: decltype(this) treated specially in trailing-return-specifier


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]