This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Diagnose parameter names that shadow inherited field names
ClosedPublic

Authored by aaron.ballman on Sep 24 2018, 7:52 AM.

Details

Summary

This patch diagnoses parameter names that shadow the names of inherited fields under -Wshadow-field. It addresses PR34120. Note, unlike GCC, we take into account the accessibility of the field when deciding whether to warn or not.

Diff Detail

Event Timeline

aaron.ballman created this revision.Sep 24 2018, 7:52 AM

Thanks!

lib/Sema/SemaDecl.cpp
12380–12382

I think you could move it into the if() above?

aaron.ballman marked an inline comment as done.

Updated based on review feedback.

lib/Sema/SemaDecl.cpp
12380–12382

You are correct, I'll hoist it.

lebedev.ri accepted this revision.Sep 26 2018, 6:47 AM

This looks good to me, but you probably want to wait for someone else to review this, too.

This revision is now accepted and ready to land.Sep 26 2018, 6:47 AM

@rsmith -- any thoughts on this before I commit?

aaron.ballman closed this revision.Nov 2 2018, 2:07 PM

I've commit in r346041.

And now i'm having concerns.

struct Base {
    void* f;
};

struct Inherit : Base {
    static void func(void* f) { // <- does 'f' *actually* shadow the 'f' in the 'Base'? You can't access that non-static member variable from static function.
    }
};

And now i'm having concerns.

struct Base {
    void* f;
};

struct Inherit : Base {
    static void func(void* f) { // <- does 'f' *actually* shadow the 'f' in the 'Base'? You can't access that non-static member variable from static function.
    }
};

The diagnostic is correct here, IMO. Consider:

struct Base {
    int* f;
};

struct Inherit : Base {
    static void func(void* f) { 
        decltype(f) ptr = 0;
    }
};

If the parameter were originally named frobble (so there was no hiding), then the decltype(f) would have resulted in int *. When frobble gets refactored into f, the type of ptr changes to void *.

...

...

Ok, thank you for reassuring me that it is working as intended.