https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104379

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #2)
> I suppose the same issue might happen with templates where we'd warn
> once per instantiation?

Yes indeed. Once for the primary template, and then again for each
specialization generated from it:


template<typename T>
struct S
{
  int i;
  int f(int i) { return i; }
};

int i = S<int>().f(1);
int j = S<long>().f(1);



shad2.C: In member function ‘int S<T>::f(int)’:
shad2.C:5:13: warning: declaration of ‘i’ shadows a member of ‘S<T>’ [-Wshadow]
    5 |   int f(int i) { return i; }
      |         ~~~~^
shad2.C:4:7: note: shadowed declaration is here
    4 |   int i;
      |       ^
shad2.C: In instantiation of ‘int S<T>::f(int) [with T = int]’:
shad2.C:8:19:   required from here
shad2.C:5:13: warning: declaration of ‘i’ shadows a member of ‘S<int>’
[-Wshadow]
    5 |   int f(int i) { return i; }
      |         ~~~~^
shad2.C:4:7: note: shadowed declaration is here
    4 |   int i;
      |       ^
shad2.C: In instantiation of ‘int S<T>::f(int) [with T = long int]’:
shad2.C:9:20:   required from here
shad2.C:5:13: warning: declaration of ‘i’ shadows a member of ‘S<long int>’
[-Wshadow]
    5 |   int f(int i) { return i; }
      |         ~~~~^
shad2.C:4:7: note: shadowed declaration is here
    4 |   int i;
      |       ^

Reply via email to