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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:14:10+00:00 2026-06-09T16:14:10+00:00

Consider the following code: class Foo; Foo& CreateFoo(); void Bar() { CreateFoo(); } In

  • 0

Consider the following code:

class Foo;

Foo& CreateFoo();


void Bar()
{
   CreateFoo();
}

In Visual Studio this will result in an error C2027 that Foo is an undefined type. In most other compilers it compiles fine. It is only an issue if the return value of CreateFoo is not assigned. If I change the line to:

Foo& foo = CreateFoo();

it compiles fine in Visual Studio. Also if Foo is defined rather than just forward-declared, then it will compile fine with no assignment.

Which should be the correct behavior? Is there anything in the C++ standard that addresses this, or is this something that is left to the implementation? I looked and didn’t see anything that talks about this.

Update:
A bug report has been filed.

  • 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-09T16:14:11+00:00Added an answer on June 9, 2026 at 4:14 pm

    This looks like the relevant part of the Standard (section 5.2.2):

    A function call is an lvalue if the result type is an lvalue reference type or an rvalue reference to function
    type, an xvalue if the result type is an rvalue reference to object type, and a prvalue otherwise.

    If a function call is a prvalue of object type:

    • if the function call is either

      • the operand of a decltype-specifier or

      • the right operand of a comma operator that is the operand of a decltype-specifier,

      a temporary object is not introduced for the prvalue. The type of the prvalue may be incomplete.
      [ Note: as a result, storage is not allocated for the prvalue and it is not destroyed; thus, a class type is
      not instantiated as a result of being the type of a function call in this context. This is true regardless of
      whether the expression uses function call notation or operator notation (13.3.1.2). — end note ] [ Note:
      unlike the rule for a decltype-specifier that considers whether an id-expression is parenthesized (7.1.6.2),
      parentheses have no special meaning in this context. — end note ]

    • otherwise, the type of the prvalue shall be complete.

    Since this function result type is an lvalue reference type, the function call evaluates to an lvalue, and the completeness requirement does not apply.

    The code is legal, at least in C++11, which no released version of Visual C++ implements fully.

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

Sidebar

Related Questions

Consider the following code: public class Bar { Foo foo; void Go() { foo
Consider the following code: #include <iostream> class Bar { public: void foo(bool b =
Consider the following code: class Foo(var name: String = bar) Now i try to
Consider the following example code: class Foo { }; class Bar : public Foo
Consider the following code: class Program { void Foo<T>() { } static void Main(string[]
Consider the following Python (3.x) code: class Foo(object): def bar(self): pass foo = Foo()
Consider the following code: abstract class Foo<T> where T : Foo<T>, new() { void
Consider the following code (C# 4.0): public class Foo : LambdaExpression { } This
Consider the following code: class Foo { Foo() {} }; class Bar { Foo
Consider the following code: class A { public: void foo() { auto functor =

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.