Skip to content

Taking care of operation overloading functions#1108

Merged
danmar merged 1 commit intodanmar:masterfrom
Hinterwaeldlers:overloadOperator
Mar 12, 2018
Merged

Taking care of operation overloading functions#1108
danmar merged 1 commit intodanmar:masterfrom
Hinterwaeldlers:overloadOperator

Conversation

@Hinterwaeldlers
Copy link
Copy Markdown
Contributor

This is a reworked version of the original pull request: #958
Somehow I am not allowed, to reopen the original pull request.

Sorry for the huge delay, but was a bit out of time.

I hope that this time it fits to the needs

Comment thread lib/checkunusedfunctions.cpp Outdated
return true;
}

const std::vector<std::string> additionalOperators = {
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.

@Hinterwaeldlers
Copy link
Copy Markdown
Contributor Author

Thanks for pointing it out. I've corrected it and the check does now pasd

@amai2012 amai2012 requested a review from danmar March 9, 2018 11:20
Copy link
Copy Markdown
Owner

@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.

I would like some minor tweaks

return false;
}

const char firstOperatorChar = funcName[operatorPrefix.length()];
Copy link
Copy Markdown
Owner

@danmar danmar Mar 10, 2018

Choose a reason for hiding this comment

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

It seems to me there is access out of bounds if funcName is "operator".

Comment thread lib/checkunusedfunctions.cpp Outdated
<< "delete[]";
const std::string opName = funcName.substr(operatorPrefix.length());

for (std::vector<std::string>::const_iterator curOp = additionalOperators.begin(); curOp != additionalOperators.end(); ++curOp) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Using std::find(), you only need 1 line of code to return true if vector has item.

Comment thread lib/checkunusedfunctions.cpp Outdated
filename = func.filename;
unusedFunctionError(errorLogger, filename, func.lineNumber, it->first);
errors = true;
if (!isOperatorFunction(it->first)) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

does it work with an conditional continue here instead?

if (isOperatorFunction(it->first))
    continue;

I prefer early return/continue/etc.

Comment thread lib/checkunusedfunctions.cpp Outdated
if (calls.find(functionName) == calls.end()) {
const Location &loc = decl->second;
unusedFunctionError(errorLogger, loc.fileName, loc.lineNumber, functionName);
if (!isOperatorFunction(functionName)) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This code is so short, so no early continue is needed.. keep this code as it is.

@Hinterwaeldlers
Copy link
Copy Markdown
Contributor Author

Thanks for the comments, I've change the parts accordingly. Hope it fits now

@danmar danmar merged commit a9b1f4c into danmar:master Mar 12, 2018
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