Re: function templates are not being compiled !
- From: "Tom Widmer [VC++ MVP]" <tom_usenet@xxxxxxxxxxx>
- Date: Thu, 21 Jul 2005 14:09:30 +0100
Vladimir Nesterovsky wrote:
template <class T> void f() { g(); }
int main() { }
That code is ill-formed, since there is no g() visible, but it is up to the compiler whether it diagnoses the error or not.
Tom,
"g()" might be a call to a "void g(T t = T());" and therefore it's template dependant.
No, it might not, since default arguments are never used as part of template argument deduction, and in any case, the use of "g" does not match any uses of a name that make it a dependent-name in the C++ standard. It might indeed be an attempted call to void g(int i = 4), double g(std::string foo = "Hello") or int g(), but since there is no such function declared before the definition of f(), any such definition won't be found by name lookup, and therefore the code is ill-formed.
Another similar example:
template <class T>
void f()
{
g();
}void g()
{
}int main()
{
f<int>();
}Unfortunately, VC7.1 compiles that successfully, even though it is ill-formed, and does require a diagnostic. This is because VC7.1 doesn't have non-dependent name lookup implemented. That code fails to compile on other popular, more standards compliant compilers, like GCC 3.4+ and Intel C++.
Tom .
- Follow-Ups:
- Re: function templates are not being compiled !
- From: Vladimir Nesterovsky
- Re: function templates are not being compiled !
- References:
- function templates are not being compiled !
- From: Alfonso Morra
- Re: function templates are not being compiled !
- From: Tom Widmer [VC++ MVP]
- Re: function templates are not being compiled !
- From: Vladimir Nesterovsky
- function templates are not being compiled !
- Prev by Date: Re: Linker Error
- Next by Date: Re: SAL annotations - how they work?
- Previous by thread: Re: function templates are not being compiled !
- Next by thread: Re: function templates are not being compiled !
- Index(es):
Relevant Pages
|