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++/57709] New: -Wshadow is too strict / has false positives


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57709

            Bug ID: 57709
           Summary: -Wshadow is too strict / has false positives
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jan.kratochvil at redhat dot com
            Target: x86_64-unknown-linux-gnu

class C {
  int both_var;
  void var_and_method() {}
  void m() { int both_var, var_and_method; }
};

FAIL: gcc (GCC) 4.8.2 20130625 (prerelease)
FAIL: gcc (GCC) 4.9.0 20130625 (experimental)
g++ -c -o shadow.o shadow.C -Wshadow -Wno-unused
shadow.C:4:18: warning: declaration of âboth_varâ shadows a member of 'this'
[-Wshadow]
shadow.C:4:28: warning: declaration of âvar_and_methodâ shadows a member of
'this' [-Wshadow]

clang-3.3-0.4.rc2.fc18.x86_64
clang -c -o shadow.o shadow.C -Wshadow -Wno-unused
shadow.C:4:18: warning: declaration shadows a field of 'C' [-Wshadow]
  void m() { int both_var, var_and_method; }
                 ^
shadow.C:2:7: note: previous declaration is here
  int both_var;
      ^
1 warning generated.

------------------------------------------------------------------------------

clang does no warn on "var_and_method" as variable vs. method are safe, if one
tries to use them inappropriately one gets an error.

It is difficult to enable -Wshadow for existing project as it has many needless
warnings, with clang it is easier and still safe.

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