public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56556] New: Wshadow warns for private members in base classes
@ 2013-03-07 0:44 david at doublewise dot net
2013-03-07 0:46 ` [Bug c++/56556] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: david at doublewise dot net @ 2013-03-07 0:44 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56556
Bug #: 56556
Summary: Wshadow warns for private members in base classes
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: david@doublewise.net
The following code warns due to -Wshadow:
class Base {
private:
int x;
};
class Derived : public Base {
Derived(int x) {}
};
Perhaps we should consider not having this warn? In my particular case, I have
a Base class with a private member variable, a class Derived that derives from
Base, and a class EvenMoreDerived that derives from Derived. In a member
function of EvenMoreDerived, I am trying to use a variable with the same name
as the private member variable of Base.
The only situation I can think of where this could theoretically be useful is
if there is some kind of overload resolution issue, but due to derived classes
hiding member functions of base classes I don't imagine that would be an issue.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/56556] Wshadow warns for private members in base classes
2013-03-07 0:44 [Bug c++/56556] New: Wshadow warns for private members in base classes david at doublewise dot net
@ 2013-03-07 0:46 ` pinskia at gcc dot gnu.org
2022-02-04 11:08 ` redi at gcc dot gnu.org
2024-05-11 14:34 ` trash.paradise at protonmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-03-07 0:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56556
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-03-07 00:46:12 UTC ---
The main reason for the warning here is namelookup happens before access
control happens. So even if change the name of x usage in Derived, you will
start to get weird error messages.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/56556] Wshadow warns for private members in base classes
2013-03-07 0:44 [Bug c++/56556] New: Wshadow warns for private members in base classes david at doublewise dot net
2013-03-07 0:46 ` [Bug c++/56556] " pinskia at gcc dot gnu.org
@ 2022-02-04 11:08 ` redi at gcc dot gnu.org
2024-05-11 14:34 ` trash.paradise at protonmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-04 11:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56556
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|RESOLVED |NEW
Resolution|INVALID |---
Last reconfirmed| |2022-02-04
Severity|normal |enhancement
Keywords| |diagnostic
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The problem with -Wshadow=local is that it doesn't warn about this either:
class Derived {
int x;
Derived(int x) {}
};
And you might want a warning there, just not for the case where 'x' is a
private member in some base.
I think I agree with David that this shouldn't warn in the first place, you
shouldn't need to work around it.
I understand Andrew's explanation, but that's the reason GCC behaves like this
today, not a reason it *should* behave like this.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/56556] Wshadow warns for private members in base classes
2013-03-07 0:44 [Bug c++/56556] New: Wshadow warns for private members in base classes david at doublewise dot net
2013-03-07 0:46 ` [Bug c++/56556] " pinskia at gcc dot gnu.org
2022-02-04 11:08 ` redi at gcc dot gnu.org
@ 2024-05-11 14:34 ` trash.paradise at protonmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: trash.paradise at protonmail dot com @ 2024-05-11 14:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56556
--- Comment #4 from Gaël Bonithon <trash.paradise at protonmail dot com> ---
It would be nice if this could be fixed. I'm currently experimenting with
porting a GTK text editor to Qt6, and it seems that because of this, I can't
name a local variable 'data' in a method of a QWidget derived class without
causing a warning:
mousepad-window.cpp:3740:12: warning: declaration of 'data' shadows a member of
'MousepadWindow' [-Wshadow]
3740 | gpointer data = GINT_TO_POINTER (gtk_text_buffer_get_modified
(active->buffer));
| ^~~~
In file included from /usr/include/qt6/QtWidgets/qmainwindow.h:8,
from /usr/include/qt6/QtWidgets/QMainWindow:1,
from ../mousepad/mousepad-window.hpp:27:
/usr/include/qt6/QtWidgets/qwidget.h:780:18: note: shadowed declaration is here
780 | QWidgetData *data;
Sorry, but this seems really silly. Clang doesn't warn in this case.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-11 14:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-07 0:44 [Bug c++/56556] New: Wshadow warns for private members in base classes david at doublewise dot net
2013-03-07 0:46 ` [Bug c++/56556] " pinskia at gcc dot gnu.org
2022-02-04 11:08 ` redi at gcc dot gnu.org
2024-05-11 14:34 ` trash.paradise at protonmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).