N4527 14.6 [temp.res]/p8
If a hypothetical instantiation of a template immediately following its definition would be ill-formed due to a construct that does not depend on a template parameter, the program is ill-formed; no diagnostic is required. If the interpretation of such a construct in the hypothetical instantiation is different from the interpretation of the corresponding construct in any actual instantiation of the template, the program is ill-formed; no diagnostic is required. [ Note: This can happen in situations including the following:
(8.1) — a type used in a non-dependent name is incomplete at the point at which a template is defined but is complete at the point at which an instantiation is performed, or
(8.2) — an instantiation uses a default argument or default template argument that had not been defined at the point at which the template was defined, or
(8.3) — constant expression evaluation (5.20) within the template instantiation uses
(8.3.1) — the value of a const object of integral or unscoped enumeration type or
(8.3.2) — the value of a constexpr object or
(8.3.3) — the value of a reference or
(8.3.4) — the definition of a constexpr function,
and that entity was not defined when the template was defined, or
So, are these codes ill-formed?
code 1:
extern double b;
template<class T>
void f(T=b){}
void g(){
f<double>();//ill-formed or not?
}
double b = 0;
void h(){
f<double>();//ill-formed or not?
}
code 2:
//translation 1
extern double b;
template<class T>
void f(T=b){}
void g(){
f<double>();//ill-formed or not?
}
//translation 2
double b = 0;
And Issue1850 Differences between definition context and point of instantiation
Various characteristics of entities referred to by a non-dependent reference in a template can change between the definition context and the point of instantiation of a specialization of that template. These include initialization (which affects whether an object can be used in a constant expression), function and template default arguments, and the completeness of types. There is implementation divergence as to whether these are checked in the definition context or at the point of instantiation. Presumably a rule is needed to make it ill-formed, no diagnostic required, if the validity of such a reference changes between the two contexts.
Can you show me more examples about how are characteristics of non-dependent names different between the two contexts? Typically about 8.2 and 8.3.1
f
will be the same. However, I can't think of a proper example that involves a defaulted function argument. – Buggyvoid g(long); void g(int, int); template<class T> void f() { g(0); } void g(int, int = 0) { }
Edit: two-phase lookup might foil this one regardless, though. – Zonazonal