If the address of a function can not be resolved during deduction, is it SFINAE or a compiler error?

Posted by Faisal Vali on Stack Overflow See other posts from Stack Overflow or by Faisal Vali
Published on 2010-05-23T14:24:08Z Indexed on 2010/05/23 14:30 UTC
Read the original article Hit count: 328

Filed under:
|
|

In C++0x SFINAE rules have been simplified such that any invalid expression or type that occurs in the "immediate context" of deduction does not result in a compiler error but rather in deduction failure (SFINAE).

My question is this:
If I take the address of an overloaded function and it can not be resolved, is that failure in the immediate-context of deduction?
(i.e is it a hard error or SFINAE if it can not be resolved)?

Here is some sample code:

struct X
{
  // template T* foo(T,T); // lets not over-complicate things for now
  void foo(char);
  void foo(int);
};


template struct S
{
  template struct size_map 
  { typedef int type; };


// here is where we take the address of a possibly overloaded function
  template void f(T, 
      typename size_map::type* = 0); 


  void f(...);
};

int main()
{
  S s;

// should this cause a compiler error because 'auto T = &X::foo' is invalid?
  s.f(3);  

}

Gcc 4.5 states that this is a compiler error, and clang spits out an assertion violation.

Here are some more related questions of interest:

Does the FCD-C++0x clearly specify what should happen here?
Are the compilers wrong in rejecting this code?
Does the "immediate-context" of deduction need to be defined a little better?

Thanks!

© Stack Overflow or respective owner

Related posts about c++0x

Related posts about sfinae