avoid more cases of returning non-const pointers from `const` objects (#4821)

This commit is contained in:
Oliver Stöneberg 2023-02-24 21:22:08 +01:00 committed by GitHub
parent d65cc696b0
commit 8583fcf96e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 15 deletions

View File

@ -335,13 +335,13 @@ void MainWindow::loadSettings()
mSettings->value(SETTINGS_WINDOW_HEIGHT, 600).toInt());
}
ShowTypes *types = mUI->mResults->getShowTypes();
mUI->mActionShowStyle->setChecked(types->isShown(ShowTypes::ShowStyle));
mUI->mActionShowErrors->setChecked(types->isShown(ShowTypes::ShowErrors));
mUI->mActionShowWarnings->setChecked(types->isShown(ShowTypes::ShowWarnings));
mUI->mActionShowPortability->setChecked(types->isShown(ShowTypes::ShowPortability));
mUI->mActionShowPerformance->setChecked(types->isShown(ShowTypes::ShowPerformance));
mUI->mActionShowInformation->setChecked(types->isShown(ShowTypes::ShowInformation));
const ShowTypes &types = mUI->mResults->getShowTypes();
mUI->mActionShowStyle->setChecked(types.isShown(ShowTypes::ShowStyle));
mUI->mActionShowErrors->setChecked(types.isShown(ShowTypes::ShowErrors));
mUI->mActionShowWarnings->setChecked(types.isShown(ShowTypes::ShowWarnings));
mUI->mActionShowPortability->setChecked(types.isShown(ShowTypes::ShowPortability));
mUI->mActionShowPerformance->setChecked(types.isShown(ShowTypes::ShowPerformance));
mUI->mActionShowInformation->setChecked(types.isShown(ShowTypes::ShowInformation));
mUI->mActionShowCppcheck->setChecked(true);
mUI->mActionShowClang->setChecked(true);

View File

@ -113,9 +113,9 @@ void ResultsView::clearRecheckFile(const QString &filename)
mUI->mTree->clearRecheckFile(filename);
}
ShowTypes * ResultsView::getShowTypes() const
const ShowTypes & ResultsView::getShowTypes() const
{
return &mUI->mTree->mShowSeverities;
return mUI->mTree->mShowSeverities;
}
void ResultsView::progress(int value, const QString& description)

View File

@ -189,7 +189,7 @@ public:
* @brief Return checking statistics.
* @return Pointer to checking statistics.
*/
CheckStatistics *getStatistics() const {
const CheckStatistics *getStatistics() const {
return mStatistics;
}
@ -197,7 +197,7 @@ public:
* @brief Return Showtypes.
* @return Pointer to Showtypes.
*/
ShowTypes * getShowTypes() const;
const ShowTypes & getShowTypes() const;
signals:

View File

@ -1399,12 +1399,12 @@ public:
const Scope *findScopeByName(const std::string& name) const;
const Type* findType(const Token *startTok, const Scope *startScope, bool lookOutside = false) const;
Type* findType(const Token *startTok, Scope *startScope, bool lookOutside = false) const {
Type* findType(const Token *startTok, Scope *startScope, bool lookOutside = false) {
return const_cast<Type*>(this->findType(startTok, const_cast<const Scope *>(startScope), lookOutside));
}
const Scope *findScope(const Token *tok, const Scope *startScope) const;
Scope *findScope(const Token *tok, Scope *startScope) const {
Scope *findScope(const Token *tok, Scope *startScope) {
return const_cast<Scope *>(this->findScope(tok, const_cast<const Scope *>(startScope)));
}

View File

@ -156,6 +156,7 @@ public:
mNameToken == rhs.mNameToken && mParamEnd == rhs.mParamEnd && mFlags == rhs.mFlags;
}
// TODO: do not return non-const pointer from const object
Token * token() const {
return mToken;
}

View File

@ -510,7 +510,7 @@ static Token *splitDefinitionFromTypedef(Token *tok, nonneg int *unnamedCount)
* code that generated it deals in some way with functions, then this
* function will probably need to be extended to handle a new function
* related pattern */
Token *Tokenizer::processFunc(Token *tok2, bool inOperator) const
const Token *Tokenizer::processFunc(const Token *tok2, bool inOperator) const
{
if (tok2->next() && tok2->next()->str() != ")" &&
tok2->next()->str() != ",") {
@ -570,6 +570,11 @@ Token *Tokenizer::processFunc(Token *tok2, bool inOperator) const
return tok2;
}
Token *Tokenizer::processFunc(Token *tok2, bool inOperator)
{
return const_cast<Token*>(processFunc(const_cast<const Token*>(tok2), inOperator));
}
void Tokenizer::simplifyUsingToTypedef()
{
if (!isCPP() || mSettings->standards.cpp < Standards::CPP11)

View File

@ -693,7 +693,8 @@ public:
Tokenizer &operator=(const Tokenizer &) = delete;
private:
Token *processFunc(Token *tok2, bool inOperator) const;
const Token *processFunc(const Token *tok2, bool inOperator) const;
Token *processFunc(Token *tok2, bool inOperator);
/**
* Get new variable id.