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 3787574
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:51:44+00:00 2026-05-19T11:51:44+00:00

I just spent a couple of hours debugging a compiler error that I could

  • 0

I just spent a couple of hours debugging a compiler error that I could have fixed immediately if the compiler’s error message had been more helpful.

I’ve reduced it to a simple example:

template <typename T>
int f(int);

template <typename U>
auto g(U x) -> decltype(f(x));

int main()
{
    g(0);
}

The error is:

test.cpp: In function 'int main()':
test.cpp:9:8: error: no matching function for call to 'g(int)'
test.cpp:9:8: note: candidate is:
test.cpp:5:29: note: template<class U> decltype (f(x)) g(U)

Is this error not at best misleading and at worst, outright wrong? The way I see it, the problem is not that the given definition of g is not a match for the call, but that the definition is malformed (since in the expression f(x) in the decltype, it tries to call f without specifying f’s template parameter).

Wouldn’t a much more reasonable error message be something like:

no matching function for call to 'f(int)' in 'decltype(f(x))'
in instantiation of 'g(U)' with U = int

or even better:

failed to deduce template parameter 1 in call to 'f(int)' in 'decltype(f(x))'
in instantiation of 'g(U)' with U = int

I would have expected something like that…

  • 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-19T11:51:45+00:00Added an answer on May 19, 2026 at 11:51 am

    You are most likely hitting the “extended SFINAE” rules in C++0x; since the call to f(x) is not working within the instantiation of the return type of g (because of the inability to deduce T for the call to f), g has an invalid return type and thus is removed from the overload set silently. This is a feature, despite its harm to error message quality, because the compiler is assuming that g is an unrelated function that you aren’t intending to call. In this case, there are no other overloads of g, so the compiler should give a better message, though.

    There is more information on extended SFINAE available at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2634.html.

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

Sidebar

Related Questions

I have just spent a couple of hours trying to represent the decision tree
I just spent half an one our to find out what caused the Error-Message
I've spent a couple hours now trying to figure this out, but I just
I have spent hours reading a couple dozen different blogs and others q's here
I just started learning Zend (& OO PHP for that matter), I have spent
So I am pretty new to JQuery and just spent 5 hours getting this
I spent hours researching the problem, and just want to share a solution in
just a quick question: I am a CS undergrad and have only had experience
Just how much slower are events? I have written a streaming XML parser (that
I've spent couple of hours now trying to work out where's the problem with

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.