CQM-GeneralParameter¶
Parameters of a function shall not get casted to a more specific type
Required inputs: IR
Any parameter of a routine that gets casted to a more specific type is a violation. Routines declared in a superclass are not considered.
Motivation
A general data type is specified as the type for a routine parameter. Within the routine, however, a more specific data type of the parameter is assumed. Via a typecast, the type of the parameter is converted into this data type and used. The specification of the general data type therefore suggests to a client a generality that does not exist at all and thus cannot be used by the client as expected. This is particularly dangerous because type errors, which can occur when using the assumed generality, only occur at runtime.
This rule is based on the CQM Quality Indicator: allgemeine Parameter (p. 167-170).
Reference
Simon, Frank/ Seng, Olaf/ Mohaupt, Thomas (2006): Code-Quality-Management: Technische Qualität industrieller Softwaresysteme transparent und vergleichbar gemacht, 1st ed., Heidelberg, Germany: dpunkt.verlag GmbH.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
parameter_cast |
This parameter gets casted to a more specific type. |
None |
False |
Options¶
This rule shares the following common options: 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
cast_types¶
cast_types
Set with the cast types, which if used constitute a violation.Type: set[CastOptions]
Default:
{'Const_Cast', 'Dynamic_Cast', 'Reinterpret_Cast', 'Static_Cast'}
Option Types¶
These types are used by options listed above:
CastOptions¶
An enumeration.C_Cast
Function_Notation_Cast
Braced_Notation_Cast
Reinterpret_Cast
Static_Cast
Const_Cast
Dynamic_Cast
Managed_Safe_Cast