diff --git a/cppcheckpremium-suppressions b/cppcheckpremium-suppressions index 07fce749a80..da438d3892b 100644 --- a/cppcheckpremium-suppressions +++ b/cppcheckpremium-suppressions @@ -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 diff --git a/lib/analyzer.h b/lib/analyzer.h index a02e6b11d63..3e4a95aeeef 100644 --- a/lib/analyzer.h +++ b/lib/analyzer.h @@ -110,7 +110,7 @@ struct Analyzer { return get(Match); } - Action& operator|=(Action a) { + Action& operator|=(Action a) & { set(a.mFlag); return *this; } diff --git a/lib/check.h b/lib/check.h index ce128ee7d25..a8fcd62f28f 100644 --- a/lib/check.h +++ b/lib/check.h @@ -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; } diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 755b77517c7..7742163c642 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -147,7 +147,10 @@ class Variables { void clear() { mVarUsage.clear(); } - const std::map &varUsage() const { + const std::map &varUsage() const & { + return mVarUsage; + } + std::map varUsage() && { return mVarUsage; } void addVar(const Variable *var, VariableType type, bool write_); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 0cdcc8f15cb..4dba4602c9d 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1513,7 +1513,7 @@ void CppCheck::executeAddonsWholeProgram(const std::list &files } } -Settings &CppCheck::settings() +Settings &CppCheck::settings() & { return mSettings; } diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 9143760dcff..5d594eb7b0f 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -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. diff --git a/lib/errorlogger.h b/lib/errorlogger.h index c39d242f683..abe1ba65544 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -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; } @@ -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; } diff --git a/lib/filesettings.h b/lib/filesettings.h index 75bf8faaa50..72dd77421a0 100644 --- a/lib/filesettings.h +++ b/lib/filesettings.h @@ -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; } @@ -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(); } diff --git a/lib/library.cpp b/lib/library.cpp index 5570f04c0c4..d10080b524f 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -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 { diff --git a/lib/programmemory.h b/lib/programmemory.h index 5d8b2632908..78ffadca352 100644 --- a/lib/programmemory.h +++ b/lib/programmemory.h @@ -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; diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 37dd297fa97..765f1fbc9f7 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -524,11 +524,6 @@ std::list SuppressionList::getUnmatchedGlobalSuppr return result; } -const std::list &SuppressionList::getSuppressions() const -{ - return mSuppressions; -} - void SuppressionList::markUnmatchedInlineSuppressionsAsChecked(const Tokenizer &tokenizer) { int currLineNr = -1; int currFileIdx = -1; diff --git a/lib/suppressions.h b/lib/suppressions.h index 8f7337d7c60..5413e809eb3 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -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; @@ -241,7 +244,12 @@ class CPPCHECKLIB SuppressionList { * @brief Returns list of all suppressions. * @return list of suppressions */ - const std::list &getSuppressions() const; + const std::list &getSuppressions() const & { + return mSuppressions; + } + std::list getSuppressions() && { + return mSuppressions; + } /** * @brief Marks Inline Suppressions as checked if source line is in the token stream diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 18d10578ea1..66b423189a3 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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; diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index a594c84b2ac..b7637d2820b 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -540,7 +540,10 @@ class CPPCHECKLIB Variable { * Get array dimensions. * @return array dimensions vector */ - const std::vector &dimensions() const { + const std::vector &dimensions() const & { + return mDimensions; + } + std::vector dimensions() && { return mDimensions; } @@ -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_, @@ -1373,7 +1376,10 @@ class CPPCHECKLIB SymbolDatabase { return mVariableList.at(varId); } - const std::vector & variableList() const { + const std::vector & variableList() const & { + return mVariableList; + } + std::vector variableList() && { return mVariableList; } diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 6cbfd40a8ea..2f5cb75cfee 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -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; } @@ -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 { diff --git a/lib/token.h b/lib/token.h index 38481ed6a99..23308c03771 100644 --- a/lib/token.h +++ b/lib/token.h @@ -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; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 00e48ab0c9c..109e2657463 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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) { @@ -4178,7 +4178,7 @@ namespace { const std::unordered_map& map(bool global) const { return global ? mVariableId_global : mVariableId; } - nonneg int& getVarId() { + nonneg int& getVarId() & { return mVarId; } }; diff --git a/lib/tokenlist.h b/lib/tokenlist.h index 09a74c4ca16..a1b2257b36e 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -139,7 +139,10 @@ class CPPCHECKLIB TokenList { * The first filename is the filename for the sourcefile * @return vector with filenames */ - const std::vector& getFiles() const { + const std::vector& getFiles() const & { + return mFiles; + } + std::vector getFiles() && { return mFiles; } diff --git a/lib/tokenrange.h b/lib/tokenrange.h index f4b462534f9..597c73b0965 100644 --- a/lib/tokenrange.h +++ b/lib/tokenrange.h @@ -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; } diff --git a/lib/vf_analyzers.cpp b/lib/vf_analyzers.cpp index 5dddda0039a..f5a3fd7c28c 100644 --- a/lib/vf_analyzers.cpp +++ b/lib/vf_analyzers.cpp @@ -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; @@ -926,7 +926,10 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer { } } - virtual const std::unordered_map& getVars() const { + virtual const std::unordered_map& getVars() const & { + return vars; + } + virtual std::unordered_map getVars() && { return vars; } @@ -1073,11 +1076,17 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer { SingleValueFlowAnalyzer(ValueFlow::Value v, const Settings& s) : ValueFlowAnalyzer(s), value(std::move(v)) {} - const std::unordered_map& getVars() const { + const std::unordered_map& getVars() const & { + return varids; + } + std::unordered_map getVars() && { return varids; } - const std::unordered_map& getAliasedVars() const { + const std::unordered_map& getAliasedVars() const & { + return aliases; + } + std::unordered_map getAliasedVars() && { return aliases; }