Is there a conflict between [temp.spec]/5 and [basic.odr] w.r.t. the odr-rule for explicit specializations?

Viewed 50

Background

There are several Q&As that cover the fact that an explicit specialization of, say, a function template, is not a function template but a function, and thus falls under [basic.def.odr]/13.3

There can be more than one definition of a [...] inline function or variable

such that the following example is (frequently) shown as well-formed:

// foo.h
// -----
template<typename T>
void foo(T) {}

// explicit specialization
template<>
inline void foo<int>(int) { int a; (void)a; }
// ^^^ note: inline

// bar.cpp
----------
#include "foo.h"

void bar() { foo<int>(42); }

// baz.cpp
----------
#include "foo.h"

void baz() { foo<int>(42); }

specifically, as per [basic.def.odr]/13.3, there is no odr-violation even if foo<int>(int) is defined in both translation units (the TUs relating to bar.cpp and baz.cpp), as the explicit specialization/the function is inline.

However, according to [temp.spec]/5.2 [emphasis mine]:

For a given template and a given set of template-arguments, [...] an explicit specialization shall be defined at most once in a program (according to [basic.def.odr]),

an explicit specialization shall be defined at most once in a program (albeit with a reference to [basic.def.odr]; no particular section).

Question

  • Is there a conflict between [temp.spec]/5 and [basic.odr] w.r.t. the odr-rule for explicit specializations? Or should the rule of the former simply be read as "except for where [basic.def.odr]/13.3 applies"?
0 Answers
Related