Example for Rule 12–1–1

Moderators: david ward, misra cpp

Post Reply
pkruk
Posts: 20
Joined: Fri Jul 27, 2007 3:25 pm

Example for Rule 12–1–1

Post by pkruk » Wed Dec 24, 2008 11:34 am

Hello,

I'm not sure if the example for this rule is correct in one case. Simplified code:

Code: Select all

class B2
{
public:
virtual ~B2 ( );
B2 ( )
{
typeid ( B2 ); // Non-compliant
}
};
Why is this typeid non compliant? It does not use object’s dynamic type so it should not be a violation of the rule. This is similar to using typeid on e.g. not polymorphic type, which is allowed by the rule. ISO/IEC 14882:2003(E) standard:
5.2.8
3. When typeid is applied to an expression other than an lvalue of a polymorphic class type, the result
refers to a type_info object representing the static type of the expression. [...]
4. When typeid is applied to a type-id, the result refers to a type_info object representing the type of the
type-id. [...]

misra cpp
Posts: 151
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Example for Rule 12–1–1

Post by misra cpp » Tue Oct 11, 2016 11:04 am

The example is incorrect. It should be “typeid(*this)” and will be modified in a Technical Corrigendum
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.12 Special member functions (C++)”