19-12-2017, 07:13 AM
Dear MISRA team,
i was wondering why is this rule advisory, when basically the same undefined behaviour applies as referenced in rule 5-2-2 (ISO 5.2.9(8))?
The result of is undefined if does not point to a B.
Granted, most compiler vendors tend to return a null pointer but it is by no means defined in the standard.
Very important: if the intention of MISRA was to prevent the usage of static_cast and allow only dynamic_cast, the rule text does not mention that at all. My suspicion rose when i studied the given example code: it shows only dynamic_cast.
BTW: am i right that rule 5-2-2 is only for old, non-ISO-compliant compilers? An attempt to use static_cast with a virtual base does not compile on any i have seen.
Thanks.
i was wondering why is this rule advisory, when basically the same undefined behaviour applies as referenced in rule 5-2-2 (ISO 5.2.9(8))?
The result of
Code:
static_cast(&a)
Code:
(&a)
Granted, most compiler vendors tend to return a null pointer but it is by no means defined in the standard.
Very important: if the intention of MISRA was to prevent the usage of static_cast and allow only dynamic_cast, the rule text does not mention that at all. My suspicion rose when i studied the given example code: it shows only dynamic_cast.
BTW: am i right that rule 5-2-2 is only for old, non-ISO-compliant compilers? An attempt to use static_cast with a virtual base does not compile on any i have seen.
Thanks.
<t></t>