[PATCH] D52400: Improve -Wshadow warnings with enumerators

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 16 04:53:08 PDT 2018


aaron.ballman added a comment.

In https://reviews.llvm.org/D52400#1266307, @sberg wrote:

> doesnt this make -Wshadow more aggressive for enumerators than for other entities?


It does, but whether that's an issue with the enumerator shadow diagnosing or with the other entities not diagnosing, I'm less clear. Consider this slight modification to your code:

  struct S1;
  struct S2;
  struct S3 {
    void S1();
    enum { S2 };
  
    void f(S2 s);
  };

On the one hand, the warning is telling you about a problem before you hit it. However, this code will err on the declaration of `S::f()` anyway because `S2` is not a type, so the warning doesn't get us all *that* much benefit.

Then again, this is a case where you don't get any error but you do get a silent behavioral ambiguity without the current enumerator shadow diagnostic:

  struct S1;
  struct S2;
  struct S3 {
    void S1();
    enum { S2 };
  
    void f(decltype(S2) s);
  };

So there are cases where this behavior can be somewhat useful.

> (ran into such a new -Wshadow while compiling LibreOffice)

Was it a frequent/annoying occurrence?


https://reviews.llvm.org/D52400





More information about the cfe-commits mailing list