[PATCH] D31235: Enhance -Wshadow to warn when shadowing typedefs or type aliases

Ahmed Asadi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 22 14:22:35 PDT 2017


ahmedasadi added inline comments.


================
Comment at: lib/Sema/SemaDecl.cpp:6753
     // the constructor initializes the field with the parameter.
-    if (isa<CXXConstructorDecl>(NewDC) && isa<ParmVarDecl>(D)) {
-      // Remember that this was shadowed so we can either warn about its
-      // modification or its existence depending on warning settings.
-      D = D->getCanonicalDecl();
-      ShadowingDecls.insert({D, FD});
-      return;
-    }
+    if (isa<CXXConstructorDecl>(NewDC))
+      if (ParmVarDecl* PVD = dyn_cast<ParmVarDecl>(D)) {
----------------
arphaman wrote:
> Why is the change to this `if` necessary? It doesn't seem that related to the main change.
VarDecl overrides getCanonicalDecl() to return a VarDecl*. As the type of D was changed from VarDecl* to NamedDecl*,  getCanonicalDecl() now returns a NamedDecl*. 

I created a new ParmVarDecl variable so getCanonicalDecl() returns a VarDecl* which can be inserted into ShadowingDecls.

Perhaps it might be better to just cast D->getCanonicalDecl() to a VarDecl when inserting it into ShadowingDecls?


https://reviews.llvm.org/D31235





More information about the cfe-commits mailing list