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

  • SEARCH
  • Home
  • 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 981121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:29:31+00:00 2026-05-16T04:29:31+00:00

Edit: This is indeed a bug in the compiler, I’ve opened a defect and

  • 0

Edit:

This is indeed a bug in the compiler, I’ve opened a defect and got the following response.

Hello Motti,
Thank you for submitting this issue. As noted in the stackoverflow posting, this is a bug in our decltype implementation. Unfortunately, we cannot fix this bug in the next release of Visual Studio since the code is relatively uncommon, and we are particularly resource constrained.

Original question follows


I’m playing around with the C++0x features of VS10 and I ran into the following problem.

std::map<int, int> map()
{
    return std::map<int, int>();
}

template <class F>
auto call(F f) -> decltype(f())
{       
    auto ret = f();
    return ret;
}

void check() 
{
    auto m = call(map); 
}

I get the following warning:

warning C4172: returning address of local variable or temporary

However when I change the prototype of call to be the old style:

std::map<int, int> call(F f)

It’s fine, it’s also OK when call is not a template function (even when using deduced return types).

If I look at the type of ret it’s std::map<int, int> (no references or pointers).

Is this a bug in VS10 or am I missing something.

  • 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-16T04:29:32+00:00Added an answer on May 16, 2026 at 4:29 am

    call(map); implicitly converts map to a function pointer, to make the function:

    auto call( std::map<int,int>(*f)() ) -> decltype(f())
    

    It looks like VC10 isn’t meeting the c++0x FCD for decltype, which says:

    The type denoted by decltype(e) is defined as follows:

    • if e is an unparenthesized id-expression or a class member access [snip, it isn’t]

    • otherwise, if e is a function call (5.2.2) or [snip], decltype(e) is the return type of the statically chosen function;

    • otherwise, if e is an lvalue, decltype(e) is T&, where T is the type of e;

    • otherwise, decltype(e) is the type of e.

    5.2.2 makes it clear that calling through a function pointer is a "function call" so decltype(f()) should be std::map<int,int>. Instead, it’s treating f() like an lvalue espression, with the result std::map<int,int> &. The type of ret is being inferred correctly, but it’s being cast into a reference by the return.

    This bug doesn’t show up when you use a function expression instead of a function pointer expression, decltype(map()) correctly results in std::map<int,int>.

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

Sidebar

Related Questions

FINAL EDIT: It does indeed appear to be a compiler bug - see the
Edit: This problem was down to me passing the wrong view to the Touch
edit This question is solved! Having something weird. I'm using html { font-size: 100%
Edit: this question is outdated. The jsonlite package flattens automatically. I am dealing with
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
Edit This question has gone through a few iterations by now, so feel free
EDIT: This question is a duplicate of What is the difference between managed and
EDIT: This issue is already submitted on Github. Changing the Act part to this
[Edit: This problem applies only to 32-bit systems. If your computer, your OS and
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone

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.