Skip to content

fixed some clang-tidy warnings#3080

Merged
danmar merged 4 commits intocppcheck-opensource:mainfrom
firewave:tidy-22
May 8, 2022
Merged

fixed some clang-tidy warnings#3080
danmar merged 4 commits intocppcheck-opensource:mainfrom
firewave:tidy-22

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread cli/cppcheckexecutor.h Outdated
Comment thread gui/checkthread.cpp Outdated
#include "common.h"

static bool executeCommand(std::string exe, std::vector<std::string> args, std::string redirect, std::string *output)
static bool executeCommand(const std::string& exe, const std::vector<std::string> &args, const std::string& redirect, std::string *output)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hmm.. shouldn't this use the exact same parameters as executeCommand in cppcheckexecutor.h?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean? the signature also already was different.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a callback used by CppCheck. The CppCheck constructor is:

CppCheck(ErrorLogger &errorLogger,
         bool useGlobalSuppressions,
         std::function<bool(std::string,std::vector<std::string>,std::string,std::string*)> executeCommand);

I believe executeCommand should match that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the signature also already was different.

then that should be fixed imho.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can update the callback signature if you want.

Comment thread gui/cppchecklibrarydata.cpp
Comment thread lib/symboldatabase.cpp Outdated
Token* start = const_cast<Token*>(it->bodyStart);
Token* end = const_cast<Token*>(it->bodyEnd);
if (it->type == Scope::eGlobal) {
for (Scope &it : scopeList) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would prefer the name scope. I guess you wanted to limit the change somewhat.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Will adjust.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment thread lib/valueflow.cpp Outdated
const Settings* settings)
{
std::list<ValueFlow::Value> values = {val};
std::list<ValueFlow::Value> values = {std::move(val)};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we move the value it will always copy because its a const ref.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The parameter is not a const ref - it's passed byvalue.

Clang or clang-tidy (can't remember) will also warn about such cases where a std::move() doesn't do anything.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see its val2 thats passed by const ref.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

But this is using val.

if (idxValues.empty() ||
std::any_of(idxValues.begin(), idxValues.end(), [&](const ValueFlow::Value& vidx) {
if (vidx.isImpossible())
if (vidx.isImpossible())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

won't this be changed back by astyle? did you try that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No longer an issue with uncrustify.

Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

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

hm.. a split up PR would have been easier to review .. 99% of this is ok and could have been merged.

@firewave firewave marked this pull request as draft September 4, 2021 11:13
@firewave firewave force-pushed the tidy-22 branch 2 times, most recently from 5da0c84 to a3796b5 Compare October 10, 2021 21:49
@firewave
Copy link
Copy Markdown
Collaborator Author

Note about the unfixed modernize-loop-convert warnings - these are cases where const_iterator is used. Unfortunately the for range loop is not using that but the regular iterator, so modernizing this actually changes the behavior. I think this can be worked around by wrapping the variable in question with std::as_const() but that is a C++17 feature. I want to file a ticket about that with clang-tidy at some point after I researched this a bit more - so probably never ... :/

@firewave firewave marked this pull request as ready for review October 13, 2021 11:58
@firewave
Copy link
Copy Markdown
Collaborator Author

@danmar This is ready for another review.

Comment thread cli/cppcheckexecutor.h
/**
* Execute a shell command and read the output from it. Returns true if command terminated successfully.
*/
static bool executeCommand(std::string exe, std::vector<std::string> args, const std::string &redirect, std::string *output_);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this should have the same signature as the executeCommand in gui/checkThread. It's used for the same callback. It's called from lib/cppcheck.cpp

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have no adjusted this yet.

Comment thread lib/tokenize.cpp Outdated
if (isC())
return;

const Token * templateToken = nullptr;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No warning from Cppcheck about this variable? Do you know if there is a ticket?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

when I look in the source code I do not see this? A rebase is needed?
https://github.com/danmar/cppcheck/blob/main/lib/tokenize.cpp#L4498

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I didn't rebase this yet. Just commented on an open conversation.

I think this might not have been detected by cppcheck and requires a ticket. I think somebody else removed it.

@firewave firewave marked this pull request as draft February 13, 2022 16:32
@firewave
Copy link
Copy Markdown
Collaborator Author

firewave commented May 2, 2022

I finally addressed all remarks. So this can be reviewed again. Sorry it took so long.

@firewave firewave marked this pull request as ready for review May 2, 2022 06:28
@firewave firewave changed the title fixed some clang-tidy and compiler warnings fixed some clang-tidy warnings May 3, 2022
@danmar danmar merged commit c710335 into cppcheck-opensource:main May 8, 2022
@firewave firewave deleted the tidy-22 branch May 8, 2022 18:57
firewave added a commit to firewave/cppcheck that referenced this pull request Sep 22, 2022
firewave added a commit to firewave/cppcheck that referenced this pull request Oct 8, 2022
firewave added a commit to firewave/cppcheck that referenced this pull request Oct 8, 2022
firewave added a commit to firewave/cppcheck that referenced this pull request Dec 19, 2022
firewave added a commit to firewave/cppcheck that referenced this pull request Dec 19, 2022
firewave added a commit to firewave/cppcheck that referenced this pull request Mar 2, 2023
firewave added a commit to firewave/cppcheck that referenced this pull request Sep 1, 2023
firewave added a commit to firewave/cppcheck that referenced this pull request Feb 5, 2024
firewave added a commit to firewave/cppcheck that referenced this pull request Feb 5, 2024
firewave added a commit to firewave/cppcheck that referenced this pull request Feb 5, 2024
firewave added a commit to firewave/cppcheck that referenced this pull request Feb 5, 2024
firewave added a commit to firewave/cppcheck that referenced this pull request Feb 5, 2024
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.

3 participants