[llvm-bugs] [Bug 31222] Produce warning when a derived class shadows a field of the base class with `-Wshadow`

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Sep 23 09:33:24 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=31222

Aaron Ballman <aaron at aaronballman.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #1 from Aaron Ballman <aaron at aaronballman.com> ---
Clang currently supports -Wshadow-field to catch exactly this situation. It's
not enabled by -Wshadow because this diagnostic has a fair number of "false"
positives that users aren't always interested in dealing with. Consider this
case:

struct S {
  int x, y;
};

struct D : S {
  int z;

  int f() {
    return z;
  }
};

Everything is great -- there's no shadowing. Sometime later, a developer goes
and changes the definition of S to:

struct S {
  int x, y, z;
};

This creates a shadow within D, but it didn't actually break anything either.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180923/ec043c80/attachment.html>


More information about the llvm-bugs mailing list