https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77566
Bug ID: 77566 Summary: Warnings (-Wextra) disappear for a public reference to the this pointer Product: gcc Version: 6.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: michele.caini at gmail dot com Target Milestone: --- I'm referring to this question on SO: http://stackoverflow.com/questions/39449946/reference-to-the-this-pointer-gcc-vs-clang The following code compiles with warnings with -Wextra: struct A { private: A* const& this_ref{this}; }; int main() { A a{}; (void)a; } Relevant warning: /data/user/0/com.n0n3m4.droidc/files/temp.c: In constructor 'constexpr A::A()': /data/user/0/com.n0n3m4.droidc/files/temp.c:1:8: warning: a temporary bound to 'A::this_ref' only persists until the constructor exits [-Wextra] struct A { ^ The following code (public data member) has no warning instead: struct A { A* const& this_ref{this}; }; int main() { A a{}; (void)a; } I guess the same diagnostic issue should be detected for the second snippet.