JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
An assignment operator (operator=) does not return a value equal to *this, and is used one or more times in the analyzed code.
| Class Name | Inappropriate Assignment Operator Return | ||||||
|---|---|---|---|---|---|---|---|
| Significance | style | ||||||
| Mnemonic | LANG.STRUCT.ASSIGNRET | ||||||
| Categories |
|
||||||
| Availability | Available for C++ only (not C). |
||||||
| Enabling | Checks for this warning class are
disabled by default. To enable them, add the following WARNING_FILTER
rule to the project configuration file.
WARNING_FILTER += allow class="Inappropriate Assignment Operator Return" |
class MyClass1 {
public:
MyClass1(int x) : m_x(x) {};
MyClass1 & operator=(MyClass1 & other) {
m_x = other.m_x;
return other; // 'Inappropriate Assignment Operator Return' warning issued here
}
private:
int m_x;
};
class MyClass2 {
public:
MyClass2(int x) : m_x(x) {};
void operator=(MyClass2 & other) { // 'Inappropriate Assignment Operator Return' warning issued here
m_x = other.m_x;
}
private:
int m_x;
};
class MyClass3 {
public:
MyClass3(int x) : m_x(x) {};
MyClass3 & operator=(MyClass3 & other) {
m_x = other.m_x;
return *this; // ok: returns *this
}
private:
int m_x;
};
// Use the assignment operators so that they are instantiated.
void test( MyClass1 & p1, MyClass2 & p2, MyClass3 & p3 )
{
MyClass1 v1(0);
MyClass2 v2(0);
MyClass3 v3(0);
v1 = p1;
v2 = p2;
v3 = p3;
}
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.