public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/37831] New: -Wshadow warns about variable names that aren't equal @ 2008-10-15 1:38 bangerth at dealii dot org 2008-10-15 1:39 ` [Bug c++/37831] " bangerth at dealii dot org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: bangerth at dealii dot org @ 2008-10-15 1:38 UTC (permalink / raw) To: gcc-bugs -Wshadow is silly about this piece of code: --------------------------------- class Foo { int bar_; public: void bar(int bar) { bar_ = bar; } }; --------------------------------- This is a fairly common style. Note that local and member variable have names that differ by the underscore. Yet: g/x> c++ -Wshadow -c x.cc x.cc: In member function 'void Foo::bar(int)': x.cc:5: warning: declaration of 'bar' shadows a member of 'this' I think that's being overly pedantic. W. -- Summary: -Wshadow warns about variable names that aren't equal Product: gcc Version: 4.2.1 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bangerth at dealii dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37831 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/37831] -Wshadow warns about variable names that aren't equal 2008-10-15 1:38 [Bug c++/37831] New: -Wshadow warns about variable names that aren't equal bangerth at dealii dot org @ 2008-10-15 1:39 ` bangerth at dealii dot org 2008-10-15 1:42 ` [Bug c++/37831] -Wshadow warns about variables inside classes member functions pinskia at gcc dot gnu dot org 2008-10-15 1:52 ` bangerth at dealii dot org 2 siblings, 0 replies; 4+ messages in thread From: bangerth at dealii dot org @ 2008-10-15 1:39 UTC (permalink / raw) To: gcc-bugs ------- Comment #1 from bangerth at dealii dot org 2008-10-15 01:38 ------- Note also that the documentation plainly states: @item -Wshadow @opindex Wshadow @opindex Wno-shadow Warn whenever a local variable shadows another local variable, parameter or global variable or whenever a built-in function is shadowed. The current behavior could therefore simply be classified as a bug. W. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37831 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/37831] -Wshadow warns about variables inside classes member functions 2008-10-15 1:38 [Bug c++/37831] New: -Wshadow warns about variable names that aren't equal bangerth at dealii dot org 2008-10-15 1:39 ` [Bug c++/37831] " bangerth at dealii dot org @ 2008-10-15 1:42 ` pinskia at gcc dot gnu dot org 2008-10-15 1:52 ` bangerth at dealii dot org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu dot org @ 2008-10-15 1:42 UTC (permalink / raw) To: gcc-bugs ------- Comment #2 from pinskia at gcc dot gnu dot org 2008-10-15 01:40 ------- bar the function shadows bar the variable. I think the warning is correct. The variable _bar is not being taken into account at all. -- pinskia at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|-Wshadow warns about |-Wshadow warns about |variable names that aren't |variables inside classes |equal |member functions http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37831 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/37831] -Wshadow warns about variables inside classes member functions 2008-10-15 1:38 [Bug c++/37831] New: -Wshadow warns about variable names that aren't equal bangerth at dealii dot org 2008-10-15 1:39 ` [Bug c++/37831] " bangerth at dealii dot org 2008-10-15 1:42 ` [Bug c++/37831] -Wshadow warns about variables inside classes member functions pinskia at gcc dot gnu dot org @ 2008-10-15 1:52 ` bangerth at dealii dot org 2 siblings, 0 replies; 4+ messages in thread From: bangerth at dealii dot org @ 2008-10-15 1:52 UTC (permalink / raw) To: gcc-bugs ------- Comment #3 from bangerth at dealii dot org 2008-10-15 01:51 ------- (In reply to comment #2) > bar the function shadows bar the variable. I think the warning is correct. > The variable _bar is not being taken into account at all. Ah, bummer, I didn't even look close enough to see that the function and its argument are named the same. Silly me, I just saw this piece of code another project was unhappy about and thought I should submit this as a bug. You're right, and I agree that the warning is valid. W. -- bangerth at dealii dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37831 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-10-15 1:52 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-10-15 1:38 [Bug c++/37831] New: -Wshadow warns about variable names that aren't equal bangerth at dealii dot org 2008-10-15 1:39 ` [Bug c++/37831] " bangerth at dealii dot org 2008-10-15 1:42 ` [Bug c++/37831] -Wshadow warns about variables inside classes member functions pinskia at gcc dot gnu dot org 2008-10-15 1:52 ` bangerth at dealii dot org
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).