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 |
The definition of a constructor for class or struct C has all of the following properties.
A constructor with these properties is a copy constructor for C.
| Class Name | Implicit Constructor Shadowing | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Significance | style | |||||||||
| Mnemonic | LANG.FUNCS.ICS | |||||||||
| Categories |
|
|||||||||
| Availability | Available for C++ only (not C). |
|||||||||
| Enabling | Checks for this warning class are disabled by default,
and require the unnormalized
C ASTs for the project. To enable them, add the following
WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes WARNING_FILTER += allow class="Implicit Constructor Shadowing" |
struct NoImpl {
// This is a defining declaration for the copy constructor,
// so there is no implicitly defined copy constructor.
NoImpl(const NoImpl& x, int i=0){} // 'Implicit Constructor Shadowing' warning issued here
};
struct ImplShadowed {
// There IS an implicitly defined copy constructor for this class,
// because this declaration does not indicate the defaulted parameter.
ImplShadowed(const ImplShadowed& x, int i);
};
// Definition matches signature of copy constructor, even though declaration doesn't.
// (parse error)
ImplShadowed::ImplShadowed(const ImplShadowed& x, int i=0){} // 'Implicit Constructor Shadowing' warning issued here
struct ImplOk {
// There IS an implicitly defined copy constructor for this class,
// but it is not shadowed by the definition of this constructor.
ImplOk(const ImplOk& x, int i); // Ok: no user confusion or parse issues.
};
// Constructor definition does not have type signature matching that of the copy constructor.
ImplOk::ImplOk(const ImplOk& x, int i){}
void my_init(NoImpl x, ImplShadowed y, ImplOk z){
// Calls the explicitly declared/defined copy constructor.
// This may not be what a human reader expects.
auto ni_copy = NoImpl(x);
// We guard this statement with "#ifdef __CODESONAR__ ... #endif" so that it is
// preprocessed out by the native compiler (so the example can be compiled)
// but still observed by the CodeSonar analysis.
#ifdef __CODESONAR__
// Resolution conflict: matches both implicitly defined copy constructor and explicit definition.
// (parse error)
auto ishadow_copy = ImplShadowed(y);
#endif
// Calls the implicitly declared/defined copy constructor.
auto iok_copy = ImplOk(z);
}
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.