Skip to content

Commit

Permalink
Use l-value reference specifier for assignment operators to prevent m…
Browse files Browse the repository at this point in the history
…isuse
  • Loading branch information
danmar committed Aug 6, 2024
1 parent b62cb22 commit f1c2344
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion cppcheckpremium-suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ premium-misra-cpp-2023-13.1.2
premium-misra-cpp-2023-13.3.1
premium-misra-cpp-2023-13.3.2
premium-misra-cpp-2023-13.3.3
premium-misra-cpp-2023-15.0.2
premium-misra-cpp-2023-15.1.2
premium-misra-cpp-2023-15.1.3
premium-misra-cpp-2023-18.1.1
Expand Down
2 changes: 1 addition & 1 deletion lib/importproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
ImportProject() = default;
virtual ~ImportProject() = default;
ImportProject(const ImportProject&) = default;
ImportProject& operator=(const ImportProject&) = default;
ImportProject& operator=(const ImportProject&) & = default;

void selectOneVsConfig(Platform::Type platform);
void selectVsConfigurations(Platform::Type platform, const std::vector<std::string> &configurations);
Expand Down
2 changes: 1 addition & 1 deletion lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Library::Library(const Library& other)
: mData(new LibraryData(*other.mData))
{}

Library& Library::operator=(const Library& other)
Library& Library::operator=(const Library& other) &
{
mData.reset(new LibraryData(*other.mData));
return *this;
Expand Down
2 changes: 1 addition & 1 deletion lib/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CPPCHECKLIB Library {
~Library();

Library(const Library& other);
Library& operator=(const Library& other);
Library& operator=(const Library& other) &;

enum class ErrorCode : std::uint8_t {
OK,
Expand Down
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,7 @@ Variable::~Variable()
delete mValueType;
}

Variable& Variable::operator=(const Variable &var)
Variable& Variable::operator=(const Variable &var) &
{
if (this == &var)
return *this;
Expand Down
2 changes: 1 addition & 1 deletion lib/symboldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class CPPCHECKLIB Variable {

~Variable();

Variable &operator=(const Variable &var);
Variable &operator=(const Variable &var) &;

/**
* Get name token.
Expand Down
2 changes: 1 addition & 1 deletion lib/valueptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CPPCHECKLIB ValuePtr {
swap(mClone, rhs.mClone);
}

ValuePtr<T>& operator=(ValuePtr rhs) {
ValuePtr<T>& operator=(ValuePtr rhs) & {
swap(rhs);
return *this;
}
Expand Down

0 comments on commit f1c2344

Please sign in to comment.