MISRA C++:2023 Rule 6.0.1
Description
Rule Definition
Block scope declarations shall not be visually ambiguous.
Rationale
If you declare a function at block scope, it is often not clear if the statement is a function declaration or an object declaration with a call to the constructor. For instance, these declarations are ambiguous:
ResourceType aResource();
It is not immediately clear if
aResource
is a function returning a variable of typeResourceType
or an object of typeResourceType
.TimeKeeper aTimeKeeper(Timer());
It is not immediately clear if
aTimeKeeper
is an object constructed with an unnamed object of typeTimer
or a function with an unnamed function pointer type as parameter. The function pointer refers to a function with no argument and return typeTimer
.
This rule does not check for ambiguous declarations in the global scope.
Polyspace Implementation
The rule checker flags ambiguous function declarations that can be mistaken for an object declaration.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Basic Concepts |
Category: Required |
Version History
Introduced in R2024b