James said:
Not in this case. It's being used in a dependent context, so
name binding doesn't occur until instantiation. The applicable
part is the last couple of sentences in §14.6.4.1: "A
specialization for any template may have points of instantiation
in multiple translation units. If two different points of
instantiation give a template specialization different meanings
according to the one definition rule, the program is ill-formed,
no diagnostic required."
Ah, right. So 3.2 [basic.def.odr] p5:
in each definition of D, corresponding names, looked up
according to 3.4, shall refer to an entity defined within the
definition of D, or shall refer to the same entity, after
overload resolution (13.3) and after matching of partial
template specialization (14.8.3) [...]
must first be applied with D being the function template, just
to be pointed to 3.4; then (once back from 3.4, which leads to
14.6.4.1) again with D being each function template
instantiation (i.e. each template function).
But here we have just one name in the body of foo (ignoring the
trivial case of 'x'). If we have several, some being dependent
and some non-dependent, how is 3.2 to be interpreted? Shall
*all* non-dependent names resolve to the same entity in the
context of the template *definition*?
(Which seems to be a contradiction in
itself: ill-formed means that a diagnostic is required,
otherwise, it's undefined behavior.)
This isn't the only usage of "ill-formed, with no diagnostic
required". Another one we came upon recently is the case in
which no valid specialization of a template can be generated:
the template definition is ill-formed (and, so, the whole
program?) and no diagnostic is required:
template< typename T >
void f()
{
1 / ( sizeof( T ) == 0 ) ;
}
template< typename T >
void f()
{
static_assert( sizeof( T ) == 0, "" ) ;
}
It remains a bit unclear to me what does it concretely mean for
a template definition to be ill-formed when it is never
instantiated. Among other things:
* AFAICS, "ill-formed" applies to (is defined for) a program.
When the standard says the template definition is
ill-formed, does it mean that the program which contains it
is ill-formed?
* According to 1.4 [intro.compliance] bullet 3, it seems that
a program containing such a template definition invokes UB.
But is that the intent? It seems a bit over the top.
(Incidentally, there's also another point about terminology:
"diagnosable rule" suggests "rule that *may* be diagnosed", not
that "must be diagnosed". This example is about a rule which may
be diagnosed, but isn't diagnosable
)