Skip to content

Commit

Permalink
return by value for temporary objects
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Aug 13, 2024
1 parent a8c2c5d commit 375d380
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CPPCHECKLIB Check {
const std::string& name() const & {
return mName;
}
const std::string& name() && {
std::string name() && {
return mName;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Variables {
const std::map<nonneg int, VariableUsage> &varUsage() const & {
return mVarUsage;
}
const std::map<nonneg int, VariableUsage> &varUsage() && {
std::map<nonneg int, VariableUsage> varUsage() && {
return mVarUsage;
}
void addVar(const Variable *var, VariableType type, bool write_);
Expand Down
8 changes: 4 additions & 4 deletions lib/errorlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CPPCHECKLIB ErrorMessage {
return mInfo;
}

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

Expand Down Expand Up @@ -189,7 +189,7 @@ class CPPCHECKLIB ErrorMessage {
return mShortMessage;
}

const std::string &shortMessage() && {
std::string shortMessage() && {
return mShortMessage;
}

Expand All @@ -199,7 +199,7 @@ class CPPCHECKLIB ErrorMessage {
return mVerboseMessage;
}

const std::string &verboseMessage() && {
std::string verboseMessage() && {
return mVerboseMessage;
}

Expand All @@ -208,7 +208,7 @@ class CPPCHECKLIB ErrorMessage {
return mSymbolNames;
}

const std::string &symbolNames() && {
std::string symbolNames() && {
return mSymbolNames;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/filesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FileWithDetails
return mPath;
}

const std::string& path() &&
std::string path() &&
{
return mPath;
}
Expand All @@ -59,7 +59,7 @@ class FileWithDetails
{
return mPathSimplified;
}
const std::string& spath() &&
std::string spath() &&
{
return mPathSimplified;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ struct Library::LibraryData
const std::string& start() const & {
return mStart;
}
const std::string& start() && {
std::string start() && {
return mStart;
}
const std::string& end() const & {
return mEnd;
}
const std::string& end() && {
std::string end() && {
return mEnd;
}
int offset() const {
Expand Down
2 changes: 1 addition & 1 deletion lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ const std::list<SuppressionList::Suppression> &SuppressionList::getSuppressions(
return mSuppressions;
}

const std::list<SuppressionList::Suppression> &SuppressionList::getSuppressions() &&
std::list<SuppressionList::Suppression> SuppressionList::getSuppressions() &&
{
return mSuppressions;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/suppressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CPPCHECKLIB SuppressionList {
const std::string &getFileName() const& {
return mFileName;
}
const std::string &getFileName() && {
std::string getFileName() && {
return mFileName;
}
int lineNumber;
Expand Down Expand Up @@ -245,7 +245,7 @@ class CPPCHECKLIB SuppressionList {
* @return list of suppressions
*/
const std::list<Suppression> &getSuppressions() const&;
const std::list<Suppression> &getSuppressions() &&;
std::list<Suppression> getSuppressions() &&;

/**
* @brief Marks Inline Suppressions as checked if source line is in the token stream
Expand Down
6 changes: 2 additions & 4 deletions lib/symboldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ class CPPCHECKLIB Variable {
const std::vector<Dimension> &dimensions() const& {
return mDimensions;
}
const std::vector<Dimension> &dimensions() && {
std::vector<Dimension> dimensions() && {
return mDimensions;
}

Expand Down Expand Up @@ -1379,9 +1379,7 @@ class CPPCHECKLIB SymbolDatabase {
const std::vector<const Variable *> & variableList() const& {
return mVariableList;
}
const std::vector<const Variable *> & variableList() && {
return mVariableList;
}
std::vector<const Variable *> variableList() &&; // Unimplemented by intention; Not safe to use this on temporary object

/**
* @brief output a debug message
Expand Down
8 changes: 4 additions & 4 deletions lib/templatesimplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CPPCHECKLIB TemplateSimplifier {
const std::string& dump() const & {
return mDump;
}
const std::string& dump() && {
std::string dump() && {
return mDump;
}

Expand Down Expand Up @@ -175,19 +175,19 @@ class CPPCHECKLIB TemplateSimplifier {
const std::string & scope() const & {
return mScope;
}
const std::string & scope() && {
std::string scope() && {
return mScope;
}
const std::string & name() const & {
return mName;
}
const std::string & name() && {
std::string name() && {
return mName;
}
const std::string & fullName() const & {
return mFullName;
}
const std::string & fullName() && {
std::string fullName() && {
return mFullName;
}
const Token * nameToken() const {
Expand Down
2 changes: 1 addition & 1 deletion lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class CPPCHECKLIB Token {
const std::string &str() const & {
return mStr;
}
const std::string &str() && {
std::string str() && {
return mStr;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tokenlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class CPPCHECKLIB TokenList {
const std::vector<std::string>& getFiles() const & {
return mFiles;
}
const std::vector<std::string>& getFiles() && {
std::vector<std::string> getFiles() && {
return mFiles;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,14 +1532,14 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer {
const std::unordered_map<nonneg int, const Variable*>& getVars() const & {
return varids;
}
const std::unordered_map<nonneg int, const Variable*>& getVars() && {
std::unordered_map<nonneg int, const Variable*> getVars() && {
return varids;
}

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

Expand Down

0 comments on commit 375d380

Please sign in to comment.