Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 806511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:15:16+00:00 2026-05-15T00:15:16+00:00

In C++0x SFINAE rules have been simplified such that any invalid expression or type

  • 0

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<class T> T* foo(T,T); // lets not over-complicate things for now
  void foo(char);
  void foo(int);
};


template<class U> struct S
{
  template<int> struct size_map 
  { typedef int type; };


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


  void f(...);
};

int main()
{
  S<X> 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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:15:17+00:00Added an answer on May 15, 2026 at 12:15 am
    template<class T> void f(T, 
        typename size_map<sizeof(&U::foo)>::type* = 0); 
    

    This doesn’t work, because U does not participate in deduction. While U is a dependent type, during deduction for f it’s treated like a fixed type spelled with a nondependent name. You need to add it to the parameter list of f

    /* fortunately, default arguments are allowed for 
     * function templates by C++0x */
    template<class T, class U1 = U> void f(T, 
        typename size_map<sizeof(&U1::foo)>::type* = 0); 
    

    So in your case because U::foo does not depend on parameters of f itself, you receive an error while implicitly instantiating S<X> (try to comment out the call, and it should still fail). The FCD says at 14.7.1/1

    The implicit instantiation of a class template specialization causes the implicit instantiation of the declarations, but not of the definitions or default arguments, of the class member functions, member classes, static data members and member templates;

    That is, if you implicitly instantiate S<X> the following function template declaration will be instantiated

    template<class T> void S<X>::f(T, 
      typename size_map<sizeof(&X::foo)>::type* = 0); 
    

    Analysis on that template declaration will then find that it can’t resolve the reference to X::foo and error out. If you add U1, the template declaration will not yet try to resolve the reference to U1::foo (since U1 is a parameter of f), and will thus remain valid and SFINAE when f is tried to be called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on some solutions for some questions that have been recently posted
I have been having some inexplicable SFINAE problems in a program I'm writing, so
I have this code that relies on SFINAE and default template arguments. It works
After reading the answer to this question , I learned that SFINAE can be
I have an SFINAE test for checking if an class has a function. The
For some complicated reason, I want to convert any supported type T (coming from
I have a header file, whose functionality relies heavily on the success of SFINAE.
I have a problem in my application where I'd like to assert that a
Let's say I have some templated class depending on type T . T could
SFINAE allows us to detect if a type has certain data members or member

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.