This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


1174. When is a pure virtual function “used?”

Section: 6.3  [basic.def.odr]     Status: C++11     Submitter: Daniel Krügler     Date: 2010-08-07

[Voted into the WP at the March, 2011 meeting as part of paper N3262.]

According to 6.3 [basic.def.odr] paragraph 2,

A variable or non-overloaded function whose name appears as a potentially-evaluated expression is used... A virtual member function is used if it is not pure.

However, that does not adequately address when a pure virtual function is used or not used. For example,

    struct S {
      virtual void pure1() = 0;
      virtual void pure2() = 0;
    };
    void f(S* p) {
      p->pure1();
      p->S::pure2();
    };

Both pure1 and pure2 satisfy the criterion that their name appears in a potentially-evaluated expression, but pure1 should not be considered “used” (which would require that it be defined); pure2 is “used” and must be defined.

Proposed resolution (November, 2010) [SUPERSEDED]:

Change 6.3 [basic.def.odr] paragraph 2 as follows:

...A variable or non-overloaded function whose name appears as a potentially-evaluated expression is odr-used unless it is an object that satisfies the requirements for appearing in a constant expression (7.7 [expr.const]) and the lvalue-to-rvalue conversion (7.3.2 [conv.lval]) is immediately applied... A virtual member function is odr-used if it is not pure. A non-overloaded function whose name appears as a potentially-evaluated expression or a member of a set of candidate functions is odr-used if it is selected by overload resolution when referred to from a potentially-evaluated expression, are odr-used, unless the function is pure and its name is not explicitly qualified. [Note:...