[petsc-dev] Use -Wshadow on pipelines?

Jed Brown jed at jedbrown.org
Sun Aug 9 22:57:24 CDT 2020

After adding support for C99, I'm in favor of using for loop declarations

  for (PetscInt i=0; i<n; i++)

whenever possible.  However, I don't think it's worth refactoring existing code, especially if it isn't automated.  I can imagine some day clang-tidy might be capable of automating such a transformation across an entire project without breaking other PETSc conventions (especially with respect to CHKERRQ), at which point we could consider whether the modest clarity improvement is worth the code churn.

At most, I would enable (and fix) -Wshadow=compatible-local at this time.

Jacob Faibussowitsch <jacob.fai at gmail.com> writes:

> Hello All,
> I discovered a rather obscure set of compiler flags -Wshadow, -Wshadow=local, -Wshadow=compatible-local while trying to track down a bug which warn about local redefinition of a variable. Out of curiosity I also recompiled petsc with this flag and lo and behold the src is littered with shadowed variables. From what I can tell most are likely harmless — defining an iterator variable in the beginning of the function with all the rest of the variables, then redefining it later in some loop — but maybe we should consider adding this as a CI flag as it isn’t activated by -Wall.
> Best regards,
> Jacob Faibussowitsch
> (Jacob Fai - booss - oh - vitch)
> Cell: (312) 694-3391

More information about the petsc-dev mailing list