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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:15:43+00:00 2026-06-18T11:15:43+00:00

My book says this: Lambdas with function bodies that contain anything other than a

  • 0

My book says this:

Lambdas with function bodies that contain anything other than a single return statement that do not specify a return type return void.

but this:

auto f = []{
  int i=0; i++;
  return std::string("foo");
};
std::cout << f() << std::endl;

actually compiles and prints out “foo”, but that lambda expr has more than just a single return statement so it should return void, because it does not manually specify “-> std::string” as a return type.

What’s going on here?

I’m using Apple’s compiler in the latest Xcode 4.6, based on Clang 3.2 it seems:

clang –version

Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix

  • 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-06-18T11:15:45+00:00Added an answer on June 18, 2026 at 11:15 am

    The book accurately reflects the rules in draft n3290 of the Standard. Perhaps your compiler implemented a different draft.

    In section 5.1.2p4, the draft reads

    If a lambda-expression does not include a trailing-return-type, it is
    as if the trailing-return-type denotes the following type:

    • if the compound-statement is of the form
      { attribute-specifier-seqopt return expression ; }
      the type of the returned expression after lvalue-to-rvalue conversion, array-to-pointer conversion, and function-to-pointer conversion;
    • otherwise, void.

    The syntactic construct attribute-specifier-seq may be alignas or the double-bracketed attributes. Not variable declarations.

    Draft n3485, which followed publication of C++11 (i.e. it is work in progress toward C++1y), contains the same wording. I don’t know if there was a different rule in some draft earlier than n3290.

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

Sidebar

Related Questions

I am attempting to learn J and the book I am using says this
I'm reading the book Multithreading Applications in Win32 The book says return node->next will
I have read in a Java book that says: Because a String is immutable,
The book I am reading says that after allocating an object I need to
One Book(Object Oriented Programming with C++ by E.Balagurusamy) says that const size = 10;
I'm reading a book that recommends clicking a check box that says Place code
I'm reading a C++ book which says this: C++ passes arrays to functions by
The Subversion SVN book says : ...Another way of thinking about this pattern is
I'm taking a tutorial for X-code that says this: Go into the code and
The Practice of Programming book says: One of the most serious problems with function

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.