AutosarC++18_10-A2.10.6¶
A class or enumeration name shall not be hidden by a variable, function or enumerator declaration in the same scope
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
C++ Language Standard [3] defines that a class or enumeration name can be hidden by an explicit declaration (of the same name) of a variable, data member, function, or enumerator in the same scope, regardless of the declaration order. Such declarations can be misleading for a developer and can lead to compilation errors.
Example
//% $Id: A2-10-6.cpp 313821 2018-03-27 11:16:14Z michal.szczepankiewicz $
#include <cstdint>
namespace NS1 {
class G {};
void G() {} //non-compliant, hides class G
}
namespace NS2 {
enum class H { VALUE=0, };
std::uint8_t H = 17; //non-compliant, hides
//scoped enum H
}
namespace NS3 {
class J {};
enum H //does not hide NS2::H, but non-compliant to A7-2-3
{
J=0, //non-compliant, hides class J
};
}
int main(void)
{
NS1::G();
//NS1::G a; //compilation error, NS1::G is a function
//after a name lookup procedure
class NS1::G a{}; //accessing hidden class type name
enum NS2::H b ; //accessing scoped enum NS2::H
NS2::H = 7;
class NS3::J c{}; //accessing hidden class type name
std::uint8_t z = NS3::J;
}
See Also
- ISO/IEC 14882:2014 [3]: 3.3.10.2: [basic.scope.hiding]
- MISRA C++ 2008 [7]: 2-10-6: If an identifier refers to a type, it shall not also refer to an object or a function in the same scope.
- HIC++ v4.0 [9]: 3.1.1: Do not hide declarations.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
reused_type |
Type should not be hidden by a name in the same scope. |
None |
False |
Options¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
invert_findings¶
invert_findings : bool = True