Topic: Should failure to instantiate a function template abort
Author: richard_corden@hotmail.com (Richard Corden)
Date: Wed, 10 Aug 2005 14:44:47 GMT Raw View
Hi,
Gene Bushuyev wrote:
[...]
> But the question is not whether it's possible to circumvent this problem in
> std::distance or any other function for that matter. The question is what is
> the intention of the standard, because after long discussion it's still not
> clear. Should the failure to implicitly instantiate the return type during
> argument deduction during overload resolution be a program error or does
> 14.8.3/1 kick in and function should be simply excluded from the overload
> set of candidates (SFINAE), no error reported.
Although this example looks like SFNAE kicks in, it doesn't. As soon as
instantiation of a class begins SFNAE no longer applies. The error is
actually occurring before overload resolution takes place while the
compiler is trying to specialise the function type to see if it can be
added to the overload set.
template <typename T>
struct A
{
friend class B;
};
template <typename T>
typename T::TYPE foo (T); // Does use SFNAE
template <typename T>
typename A<T>::TYPE foo (T); // Does not use SFNAE
void foo (int);
void bar ()
{
foo (0);
}
// ...
typedef int B;
If the compiler did allow you to instantiate class bodies, it would then
have a lot of difficulty back tracking. In this example, a completely
unrelated typedef would now generate an error since there is already a
'class B' declared in the namespace.
Regards,
Richard
--
Richard Corden
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]