Rule A5-3-1 (required, implementation, non-automated)

Evaluation of the operand to the typeid operator shall not contain side effects.

Rationale

The operand of typeid operator is evaluated only if it is a function call which returns a reference to a polymorphic type. Providing side effects to typeid operator, which takes place only under special circumstances, makes the code more difficult to maintain.

Example

// $Id: A5-3-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <typeinfo>
bool SideEffects() noexcept
{
// Implementation
return true;
}
class A
{
public:
static A& F1() noexcept { return a; }
virtual ~A() {}

private:
static A a;
};
A A::a;
void F2() noexcept(false)
{
typeid(SideEffects()); // Non-compliant - sideEffects() function not called
typeid(A::F1()); // Non-compliant - A::f1() functions called to determine
// the polymorphic type
}

See also

HIC++ v4.0 [9]: 5.1.6 Do not code side effects into the right-hand operands of: &&, ||, sizeof, typeid or a function passed to condition_variable::wait.