[PATCH] D18271: Avoid -Wshadow warnings about constructor parameters named after fields

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 14 17:20:42 PDT 2016


rsmith added inline comments.

================
Comment at: lib/Sema/SemaDecl.cpp:6417-6425
@@ +6416,11 @@
+    if (isa<CXXConstructorDecl>(NewDC) && isa<ParmVarDecl>(D)) {
+      if (Diags.isIgnored(diag::warn_ctor_parm_shadows_field, R.getNameLoc())) {
+        D = D->getCanonicalDecl();
+        ShadowingDecls.insert({D, FD});
+      } else {
+        Diag(R.getNameLoc(), diag::warn_ctor_parm_shadows_field)
+            << D << FD << FD->getParent();
+        Diag(FD->getLocation(), diag::note_previous_declaration);
+      }
+      return;
+    }
----------------
I would prefer for us to produce the -Wshadow "modifying shadowed" warning where it applies, even when -Wshadow-all is enabled. The usual model is to act as if -W* flags are just a filter over the diagnostic output, and this diverges from that.

Is the goal to ensure that -Wshadow-field-in-constructor diagnoses all constructor parameter / field shadowing, even if -Wshadow is not enabled?


http://reviews.llvm.org/D18271





More information about the cfe-commits mailing list