What does it mean to “ODR-use” something?

It’s just an arbitrary definition, used by the standard to
specify when you must provide a definition for an entity (as
opposed to just a declaration). The standard doesn’t say just
“used”, because this can be interpreted diversely depending on
context. And some ODR-use doesn’t really correspond to what one
would normally associate with “use”; for example, a virtual
function is always ODR-used unless it is pure, even if it isn’t
actually called anywhere in the program.

The full definition is in §3.2, second paragraph, although this
contains references to other sections to complete the
definition.

With regards to templates, ODR-used is only part of question;
the other part is instantiation. In particular, §14.7 covers
when a template is instantiated. But the two are related: while
the text in §14.7.1 (implicit instantiation) is fairly long, the
basic principle is that a template will only be instantiated if
it is used, and in this context, used means ODR-used. Thus,
a member function of a class template will only be instantiated
if it is called, or if it is virtual and the class itself is
instantiated. The standard itself counts on this in many
places: the std::list<>::sort uses < on the individual
elements, but you can instantiate a list over an element type
which doesn’t support <, as long as you don’t call sort on
it.

Leave a Comment