On 6 Okt., 13:06, Jiang <goo.mai...@yahoo.com> wrote:
Is the above supplied program ill-formed because a definition of "f"
is missing ([basic.def.odr]p3)? If the program is valid, is there
wording that supports it?
The program is well-formed, since in 14.7.1 we have:
"Unless a function template specialization has been
explicitly instantiated or explicitly specialized,
the function template specialization is implicitly
instantiated when the specialization is referenced
in a context that requires a function definition
to exist."
What you are referring to is a statement that applies to function
templates, but it does not apply to a non-template function.
The wording is not specified in a form that enforces a
compiler to realize a dependency analysis before assuming
that it can build-up references to entities.
For the same reason the following program is ill-formed:
extern int x;
template<typename T>
void g() {
int v = x;
}
int main() { }
This program requires the definition of x, even though g() is
not instantiated. The requirements for this are satisfied:
a) x occurs in a context that does belong to a potentially-
evaluated expression.
b) Within this context x appears in an expression where
it does not satisfy the criteria for a constant expression.
expression". A string literal expression appears in
evaluable expression.
template is unevaluated expression or not.