diff --git a/lib/analyzer.h b/lib/analyzer.h index 76824cc80d7..b33dbc276ba 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 d7290dc2578..64d05f33a5e 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 4c3bcb7d0b6..1659790be02 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1511,7 +1511,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 6483f80680f..88bc6f020d8 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 3af84f07751..cc8120729bb 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -92,7 +92,11 @@ 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 +185,30 @@ 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..22046416878 100644 --- a/lib/filesettings.h +++ b/lib/filesettings.h @@ -45,12 +45,21 @@ class FileWithDetails throw std::runtime_error("empty path specified"); } - const std::string& path() const + const std::string& path() const & { return mPath; } - const std::string& spath() const + std::string path() && + { + return mPath; + } + + const std::string& spath() const & + { + return mPathSimplified; + } + std::string spath() && { return mPathSimplified; } diff --git a/lib/library.cpp b/lib/library.cpp index 17ca05ee6cf..8cc0562d84a 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/suppressions.cpp b/lib/suppressions.cpp index 71481f324a5..a5509001931 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -517,7 +517,12 @@ std::list SuppressionList::getUnmatchedGlobalSuppr return result; } -const std::list &SuppressionList::getSuppressions() const +const std::list &SuppressionList::getSuppressions() const & +{ + return mSuppressions; +} + +std::list SuppressionList::getSuppressions() && { return mSuppressions; } diff --git a/lib/suppressions.h b/lib/suppressions.h index b6b8c815117..2e8288226a6 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,8 @@ class CPPCHECKLIB SuppressionList { * @brief Returns list of all suppressions. * @return list of suppressions */ - const std::list &getSuppressions() const; + const std::list &getSuppressions() const&; + std::list getSuppressions() &&; /** * @brief Marks Inline Suppressions as checked if source line is in the token stream diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index f481034c609..d4f9ae5109f 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -534,7 +534,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; } @@ -1373,9 +1376,10 @@ class CPPCHECKLIB SymbolDatabase { return mVariableList.at(varId); } - const std::vector & variableList() const { + const std::vector & variableList() const& { return mVariableList; } + std::vector variableList() &&; // Unimplemented by intention; Not safe to use this on temporary object /** * @brief output a debug message diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index db7d6967e9c..ede9e8a6813 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 829cba6fe70..ba1b100cb8c 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/tokenlist.h b/lib/tokenlist.h index 1bf852d3734..bfba0f5cd8b 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 762a4dbc57b..71d2ea5f403 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/valueflow.cpp b/lib/valueflow.cpp index 72da844aa87..26af0c5055b 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -759,7 +759,7 @@ class SelectValueFromVarIdMapRange { return &mIt->second; } - Iterator &operator++() { + Iterator &operator++() & { // cppcheck-suppress postfixOperator - forward iterator needs to perform post-increment mIt++; return *this; @@ -1529,11 +1529,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; }