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

Fix ref qualifiers for methods #6831

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cppcheckpremium-suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ premium-misra-cpp-2023-6.7.1
premium-misra-cpp-2023-6.8.3

# FIXME enforce proper ref qualifications
premium-misra-cpp-2023-6.8.4
# premium-misra-cpp-2023-6.8.4

# We intentionally use the standard integer types
premium-misra-cpp-2023-6.9.2
Expand Down
2 changes: 1 addition & 1 deletion lib/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct Analyzer {
return get(Match);
}

Action& operator|=(Action a) {
Action& operator|=(Action a) & {
set(a.mFlag);
return *this;
}
Expand Down
5 changes: 4 additions & 1 deletion lib/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ class CPPCHECKLIB Check {
virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const = 0;

/** class name, used to generate documentation */
const std::string& name() const {
const std::string& name() const & {
return mName;
}
std::string name() && {
return mName;
}

Expand Down
5 changes: 4 additions & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ class Variables {
void clear() {
mVarUsage.clear();
}
const std::map<nonneg int, VariableUsage> &varUsage() const {
const std::map<nonneg int, VariableUsage> &varUsage() const & {
return mVarUsage;
}
std::map<nonneg int, VariableUsage> varUsage() && {
return mVarUsage;
}
void addVar(const Variable *var, VariableType type, bool write_);
Expand Down
2 changes: 1 addition & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ void CppCheck::executeAddonsWholeProgram(const std::list<FileWithDetails> &files
}
}

Settings &CppCheck::settings()
Settings &CppCheck::settings() &
{
return mSettings;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
* @brief Get reference to current settings.
* @return a reference to current settings
*/
Settings &settings();
Settings &settings() &;

/**
* @brief Returns current version number as a string.
Expand Down
20 changes: 16 additions & 4 deletions lib/errorlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ class CPPCHECKLIB ErrorMessage {
int line; // negative value means "no line"
unsigned int column;

const std::string& getinfo() const {
const std::string& getinfo() const & {
return mInfo;
}
std::string getinfo() && {
return mInfo;
}

Expand Down Expand Up @@ -181,18 +184,27 @@ class CPPCHECKLIB ErrorMessage {
void setmsg(const std::string &msg);

/** Short message (single line short message) */
const std::string &shortMessage() const {
const std::string &shortMessage() const & {
return mShortMessage;
}
std::string shortMessage() && {
return mShortMessage;
}

/** Verbose message (may be the same as the short message) */
// cppcheck-suppress unusedFunction - used by GUI only
const std::string &verboseMessage() const {
const std::string &verboseMessage() const & {
return mVerboseMessage;
}
std::string verboseMessage() && {
return mVerboseMessage;
}

/** Symbol names */
const std::string &symbolNames() const {
const std::string &symbolNames() const & {
return mSymbolNames;
}
std::string symbolNames() && {
return mSymbolNames;
}

Expand Down
26 changes: 22 additions & 4 deletions lib/filesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ class FileWithDetails
throw std::runtime_error("empty path specified");
}

const std::string& path() const
const std::string& path() const &
{
return mPath;
}
std::string path() &&
{
return mPath;
}

const std::string& spath() const
const std::string& spath() const &
{
return mPathSimplified;
}
std::string spath() &&
{
return mPathSimplified;
}
Expand All @@ -77,12 +85,22 @@ struct CPPCHECKLIB FileSettings {

std::string cfg;
FileWithDetails file;
const std::string& filename() const
const std::string& filename() const &
{
// cppcheck-suppress returnTempReference
return file.path();
}
std::string filename() &&
{
return file.path();
}
// cppcheck-suppress unusedFunction
const std::string& sfilename() const
const std::string& sfilename() const &
{
// cppcheck-suppress returnTempReference
return file.spath();
}
std::string sfilename() &&
{
return file.spath();
}
Expand Down
10 changes: 8 additions & 2 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,16 @@ struct Library::LibraryData
void addBlock(const char* blockName) {
mBlocks.insert(blockName);
}
const std::string& start() const {
const std::string& start() const & {
return mStart;
}
const std::string& end() const {
std::string start() && {
return mStart;
}
const std::string& end() const & {
return mEnd;
}
std::string end() && {
return mEnd;
}
int offset() const {
Expand Down
3 changes: 2 additions & 1 deletion lib/programmemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ struct ExprIdToken {
return !(lhs < rhs);
}

const Token& operator*() const NOEXCEPT {
const Token& operator*() const& NOEXCEPT {
return *tok;
}
Token operator*() && NOEXCEPT;

const Token* operator->() const NOEXCEPT {
return tok;
Expand Down
5 changes: 0 additions & 5 deletions lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,6 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedGlobalSuppr
return result;
}

const std::list<SuppressionList::Suppression> &SuppressionList::getSuppressions() const
{
return mSuppressions;
}

void SuppressionList::markUnmatchedInlineSuppressionsAsChecked(const Tokenizer &tokenizer) {
int currLineNr = -1;
int currFileIdx = -1;
Expand Down
12 changes: 10 additions & 2 deletions lib/suppressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class CPPCHECKLIB SuppressionList {
std::size_t hash;
std::string errorId;
void setFileName(std::string s);
const std::string &getFileName() const {
const std::string &getFileName() const & {
return mFileName;
}
std::string getFileName() && {
return mFileName;
}
int lineNumber;
Expand Down Expand Up @@ -241,7 +244,12 @@ class CPPCHECKLIB SuppressionList {
* @brief Returns list of all suppressions.
* @return list of suppressions
*/
const std::list<Suppression> &getSuppressions() const;
const std::list<Suppression> &getSuppressions() const & {
return mSuppressions;
}
std::list<Suppression> getSuppressions() && {
return mSuppressions;
}

/**
* @brief Marks Inline Suppressions as checked if source line is in the token stream
Expand Down
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6220,7 +6220,7 @@ Type* Scope::findType(const std::string& name)

//---------------------------------------------------------------------------

Scope *Scope::findInNestedListRecursive(const std::string & name)
Scope *Scope::findInNestedListRecursive(const std::string & name) &
{
auto it = std::find_if(nestedList.cbegin(), nestedList.cend(), [&](const Scope* s) {
return s->className == name;
Expand Down
12 changes: 9 additions & 3 deletions lib/symboldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,10 @@ class CPPCHECKLIB Variable {
* Get array dimensions.
* @return array dimensions vector
*/
const std::vector<Dimension> &dimensions() const {
const std::vector<Dimension> &dimensions() const & {
return mDimensions;
}
std::vector<Dimension> dimensions() && {
return mDimensions;
}

Expand Down Expand Up @@ -1146,7 +1149,7 @@ class CPPCHECKLIB Scope {
* @brief find if name is in nested list
* @param name name of nested scope
*/
Scope *findInNestedListRecursive(const std::string & name);
Scope *findInNestedListRecursive(const std::string & name) &;

void addVariable(const Token *token_, const Token *start_,
const Token *end_, AccessControl access_, const Type *type_,
Expand Down Expand Up @@ -1373,7 +1376,10 @@ class CPPCHECKLIB SymbolDatabase {
return mVariableList.at(varId);
}

const std::vector<const Variable *> & variableList() const {
const std::vector<const Variable *> & variableList() const & {
return mVariableList;
}
std::vector<const Variable *> variableList() && {
return mVariableList;
}

Expand Down
20 changes: 16 additions & 4 deletions lib/templatesimplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class CPPCHECKLIB TemplateSimplifier {
public:
explicit TemplateSimplifier(Tokenizer &tokenizer);

const std::string& dump() const {
const std::string& dump() const & {
return mDump;
}
std::string dump() && {
return mDump;
}

Expand Down Expand Up @@ -169,13 +172,22 @@ class CPPCHECKLIB TemplateSimplifier {
void token(Token * token) {
mToken = token;
}
const std::string & scope() const {
const std::string & scope() const & {
return mScope;
}
std::string scope() && {
return mScope;
}
const std::string & name() const {
const std::string & name() const & {
return mName;
}
const std::string & fullName() const {
std::string name() && {
return mName;
}
const std::string & fullName() const & {
return mFullName;
}
std::string fullName() && {
return mFullName;
}
const Token * nameToken() const {
Expand Down
5 changes: 4 additions & 1 deletion lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ class CPPCHECKLIB Token {
*/
void concatStr(std::string const& b);

const std::string &str() const {
const std::string &str() const & {
return mStr;
}
std::string str() && {
return mStr;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2534,7 +2534,7 @@ namespace {
return false;
}

ScopeInfo3 * findScope(const ScopeInfo3 * scope) {
ScopeInfo3 * findScope(const ScopeInfo3 * scope) & {
if (scope->bodyStart == bodyStart)
return this;
for (auto & child : children) {
Expand Down Expand Up @@ -4178,7 +4178,7 @@ namespace {
const std::unordered_map<std::string, nonneg int>& map(bool global) const {
return global ? mVariableId_global : mVariableId;
}
nonneg int& getVarId() {
nonneg int& getVarId() & {
return mVarId;
}
};
Expand Down
5 changes: 4 additions & 1 deletion lib/tokenlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ class CPPCHECKLIB TokenList {
* The first filename is the filename for the sourcefile
* @return vector with filenames
*/
const std::vector<std::string>& getFiles() const {
const std::vector<std::string>& getFiles() const & {
return mFiles;
}
std::vector<std::string> getFiles() && {
return mFiles;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tokenrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TokenRangeBase {
T* mt;
TokenIterator() : mt(nullptr) {}
explicit TokenIterator(T* t) : mt(t) {}
TokenIterator& operator++() {
TokenIterator& operator++() & {
mt = mt->next();
return *this;
}
Expand Down
17 changes: 13 additions & 4 deletions lib/vf_analyzers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
return &mIt->second;
}

Iterator &operator++() {
Iterator &operator++() & {
// cppcheck-suppress postfixOperator - forward iterator needs to perform post-increment
mIt++;
return *this;
Expand Down Expand Up @@ -926,7 +926,10 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
}
}

virtual const std::unordered_map<nonneg int, const Variable*>& getVars() const {
virtual const std::unordered_map<nonneg int, const Variable*>& getVars() const & {
return vars;
}
virtual std::unordered_map<nonneg int, const Variable*> getVars() && {
return vars;
}

Expand Down Expand Up @@ -1073,11 +1076,17 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer {

SingleValueFlowAnalyzer(ValueFlow::Value v, const Settings& s) : ValueFlowAnalyzer(s), value(std::move(v)) {}

const std::unordered_map<nonneg int, const Variable*>& getVars() const {
const std::unordered_map<nonneg int, const Variable*>& getVars() const & {
return varids;
}
std::unordered_map<nonneg int, const Variable*> getVars() && {
return varids;
}

const std::unordered_map<nonneg int, const Variable*>& getAliasedVars() const {
const std::unordered_map<nonneg int, const Variable*>& getAliasedVars() const & {
return aliases;
}
std::unordered_map<nonneg int, const Variable*> getAliasedVars() && {
return aliases;
}

Expand Down
Loading