[PATCH] D52421: [Sema] Diagnose parameter names that shadow inherited field names

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 6 09:43:59 PST 2018


aaron.ballman added a comment.

In https://reviews.llvm.org/D52421#1288910, @lebedev.ri wrote:

> 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 *`.


https://reviews.llvm.org/D52421





More information about the cfe-commits mailing list