Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang tidy fixes step 1 #32

Merged
merged 15 commits into from
Jan 22, 2023

Conversation

jtxa
Copy link
Contributor

@jtxa jtxa commented Jan 13, 2023

Here are some fixes based on clang-tidy warnings. Mostly auto-fixes, please see commit messages for details.

About half of the messages as discussed in #26 are fixed now:

bugprone-macro-parentheses
modernize-deprecated-headers
modernize-make-shared
modernize-raw-string-literal
modernize-redundant-void-arg
modernize-return-braced-init-list
modernize-use-auto
modernize-use-bool-literals
modernize-use-emplace
readability-container-size-empty
readability-delete-null-pointer
readability-duplicate-include
readability-isolate-declaration
readability-make-member-function-const
readability-non-const-parameter
readability-qualified-auto
readability-redundant-access-specifiers
readability-static-accessed-through-instance
readability-uppercase-literal-suffix

Additionally small manual fixes for:

bugprone-suspicious-string-compare
readability-const-return-type

Further changes were needed to get the CI running OK again.
There were some updates to MegaLinter.

ATM the ubuntu mirror from MS Azure seems to be not reachable for the GitHub runner. So the tests on Linux may fail. Perhaps a temporary problem, I'll try to run them again later. If necessary I'll add an extra commit, that changes the mirror used.

@sierrafoxtrot sierrafoxtrot self-assigned this Jan 15, 2023
This warning occurs:

~~~
  test $? -eq 0 || no_result
       ^-- SC2320 (warning): This $? refers to echo/printf, not a previous command. Assign to variable to avoid it being overwritten.
~~~

See https://www.shellcheck.net/wiki/SC2320 for details.

But in this case the return code of echo is really checked:
to make sure that the file redirection worked.

To avoid the, otherwise useful, ShellCheck warning,
simply pipe through `cat` for these cases.
MegaLinter v6.14.0 does also check file name spelling.
@jtxa
Copy link
Contributor Author

jtxa commented Jan 15, 2023

Created a new PR #33 for the CI fixes. That one should be merged first.
Afterwards I'll rebase this PR and remove those commits from here.

@jtxa
Copy link
Contributor Author

jtxa commented Jan 15, 2023

On MacOS these changes causes errors and warnings like:

error: no member named 'emplace_back' in 'std::list<std::string>'; did you mean '__emplace_back'?
warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

I need to take a look how this has to be solved.

Command:

~~~sh
run-clang-tidy-14 -header-filter='.*' -checks='-*,modernize-deprecated-headers,readability-duplicate-include' -fix
~~~
Command:

~~~sh
run-clang-tidy-14 -header-filter='.*' -checks='-*,modernize-use-auto,readability-qualified-auto' -fix
~~~

Afterwards remove obsolete newlines manually.
Command:

~~~sh
run-clang-tidy-14 -header-filter='.*' -checks='-*,readability-non-const-parameter,readability-make-member-function-const' -fix
~~~
Command:

~~~sh
run-clang-tidy-14 -header-filter='.*' -checks='-*,modernize-make-shared,modernize-use-emplace,modernize-return-braced-init-list,modernize-use-bool-literals,modernize-raw-string-literal' -fix
~~~
Command:

~~~sh
run-clang-tidy-14 -header-filter='.*' -checks='-*,modernize-redundant-void-arg' -fix
~~~
Command:

~~~sh
run-clang-tidy-14 -header-filter='.*' -checks='-*,readability-uppercase-literal-suffix' -fix
~~~
Command:

~~~sh
run-clang-tidy-14 -header-filter='.*' -checks='-*,readability-redundant-access-specifiers,readability-container-size-empty,readability-static-accessed-through-instance,readability-delete-null-pointer,readability-isolate-declaration' -fix
~~~

Afterwards fix white spaces (newline, indentation).
Command:

~~~sh
run-clang-tidy-14 -header-filter='.*' -checks='-*,bugprone-macro-parentheses' -fix
~~~

Manually replace duplicate macros by include.
Fix the following warning:

~~~
return type 'const std::string' (aka 'const basic_string<char>') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type,-warnings-as-errors]
~~~
Fix the following warnings:

~~~
function 'memcmp' is called without explicitly comparing result [bugprone-suspicious-string-compare,-warnings-as-errors]

function 'strcmp' is called without explicitly comparing result [bugprone-suspicious-string-compare,-warnings-as-errors]
~~~
Add more checks and disable those not fixed yet.
@sierrafoxtrot
Copy link
Owner

This is huge (but sensational Josef!). It's going to take a while to go through. Nights are mostly available, otherwise, I'll definitely be able to pour through on the upcoming weekend.

@jtxa
Copy link
Contributor Author

jtxa commented Jan 17, 2023

I rebased it on top of #33 first (no code changes), and added the fix for MacOS:
In CMake no C++11 was required until now, and on MacOS it seems the default was somewhere between C++98 and C++11.
(The first 3 commit are included in #33, I hope they vanish here if you merge the other PR first. Or you merge this alone and cancel the other one, I don't know how GH works in this case.)

The review needs to be done per commit, that should be easier.
I did compile each commit separately and compared the executable if they are binary identical to its predecessor.
Hope this helps that you don't feel the need to review every single line of the mass auto-fixes in detail.

Commit Binaries
C++: Modernize and de-duplicate includes identical
C++: Use auto keyword identical
C++: Improve const usage differs
C++: Apply misc C++11 modernizations differs
C++: Remove void arguments for consistency identical
C++: Use uppercase literal suffix identical
C++: Apply misc readability fixes differs
C++: Fix macro parantheses identical
C++: Remove useless const identical
C++: Fix strcmp/memcmp identical

Copy link
Owner

@sierrafoxtrot sierrafoxtrot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Curious (but not concerned) to know why we are dropping abseil (the checks look handy). Guessing we violate something it checks?

@sierrafoxtrot sierrafoxtrot merged commit 66914e1 into sierrafoxtrot:master Jan 22, 2023
@jtxa jtxa deleted the clang-tidy-fixes-step1 branch January 22, 2023 10:10
@jtxa
Copy link
Contributor Author

jtxa commented Jan 24, 2023

Curious (but not concerned) to know why we are dropping abseil (the checks look handy). Guessing we violate something it checks?

Should have explained the current state of the rules. Today I use the default + those rules we currently check. Perhaps it's better to enable all, and then disable those we really don't want.

The initial .clang-tidy file just enabled those, that were running without problems. It was minimal to get the CI running.
But because the analyzing time increased dramatically now, I have gone through all groups, and though about their usefulness. There are common rules, rules by companies or groups, rules for specific libraries.

This is what I guessed:

Enabled:

  • bugprone: some warnings remained
  • cert: some warnings remained
  • clang-analyzer: some warnings remained; OSX warnings irrelevant
  • concurrency: maybe irrelevant (it's just 2 checks, but 1 is failing)
  • misc: some warnings remained
  • modernize: some warnings remained, 3 warnings disabled on purpose as discussed
  • performance: some warnings remained
  • portability: Yeah, no warnings!
  • readability: some warnings remained

Currently not enabled:

  • cppcoreguidelines: many warnings, wanted to take a closer look, after the normal ones from above are more or less fixed
  • fuchsia: coding guidelines for a special OS, maybe needs to be reviewed and considered
  • google: coding guidelines by google, maybe needs to be reviewed and considered (e.g. c-style-cast)
  • hicpp: High Integrity C++ Coding Standard, maybe needs to be reviewed and considered
  • llvm: coding guidelines by LLVM, maybe needs to be reviewed and considered

Irrelevant:

  • abseil: because we do not use abseil. It's a library like boost, the warnings tell you when it's better to use the abseil API.
  • altera: no altera code used
  • android: no android target
  • boost: boost not used anymore
  • darwin: no darwin specific code
  • linuxkernel: no kernel dev
  • llvmlibc: not using this lib
  • mpi: no MPI lib used
  • objc: no ObjC used, only C++
  • openmp: OpenMP not used
  • zircon: for Zircon kernel devs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants