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 |
A copy constructor or copy assignment operator has a non-const parameter.
A warning of this class is issued for a constructor or overloaded assignment operator if all of the following are true.
Warnings of this class are not issued if the copy-constructed or copy-assigned object is of a std type. Types such as std::shared_ptr<> require a reference counter to be incremented each time a copy is made, so cannot be const parameters in these contexts.
| Class Name | Copy Operation Parameter Is Not const | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | style | ||||||||||||
| Mnemonic | LANG.FUNCS.COPINC | ||||||||||||
| 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="Copy Operation Parameter Is Not const" |
#include <utility>
#include <memory>
namespace lang_funcs_copinc_OK
{
struct S {
S();
S( const S & s ) {} // ok: const argument
S& operator=( const S & s ) { return *this; } // ok: const argument
S( S && s ) {} // ok: rvalue reference argument (move constructor)
int sf;
};
void test() {
S s;
S sc(s);
S sm = std::move(s);
sc = s;
std::shared_ptr<S> p = std::make_shared<S>(); // ok: copy-assigning to std::shared_ptr<>
std::shared_ptr<S> p2(p); // ok: copy-constructing std::shared_ptr<>
}
}
namespace lang_funcs_copinc_WARNINGS
{
struct S {
S();
S( S & s ) {} // 'Copy Operation Parameter Is Not const' warning issued here
S& operator=( S & s ) { return *this; } // 'Copy Operation Parameter Is Not const' warning issued here
int sf;
};
void test() {
S s;
S sc(s);
sc = s;
}
}
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.