This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/77566] New: Warnings (-Wextra) disappear for a public reference to the this pointer
- From: "michele.caini at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 12 Sep 2016 12:40:27 +0000
- Subject: [Bug c++/77566] New: Warnings (-Wextra) disappear for a public reference to the this pointer
- Auto-submitted: auto-generated
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.