MISRAC++2023-8.2.9 (C++ only)
In this section:
Synopsis
(Required) The operand to typeid shall not be an expression of polymorphic class type
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
It is undefined whether such an expression is evaluated in runtime or not.
Coding standards
This check does not correspond to any coding standard rules.
Code examples
The following code example fails the check and will give a warning:
#include <typeinfo>
struct P { virtual void foo() {} }; // Polymorphic
void example( P * p ) {
auto& t = typeid( *p ); // Non-compliant
}
The following code example passes the check and will not give a warning about this issue:
#include <typeinfo>
struct S { }; // Non-polymorphic
void example( S* s ) {
auto& t = typeid( *s ); // Compliant
}