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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:15:43+00:00 2026-05-26T06:15:43+00:00

Is the order of execution of the three commented lines below guaranteed? struct S

  • 0

Is the order of execution of the three commented lines below guaranteed?

struct S
{
    S() { /* called 1st */ }
    ~S() { /* called 3rd */ }
};

boost::shared_ptr<S> f() 
{
    return boost::shared_ptr<S>(new S); 
}

int second() { return 0; /* called 2nd */ }

int test()
{
    return (f(), second());
}

With my compiler, the shared_ptr returned by f() seems to persist until after second() is called. But is this guaranteed by the standard and thus other compilers?

  • 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-26T06:15:44+00:00Added an answer on May 26, 2026 at 6:15 am

    Yes.

    Temporaries persist until the completion of the full-expression.

    [n3290: 12.2/3]: When an implementation introduces a temporary
    object of a class that has a non-trivial constructor (12.1,
    12.8), it shall ensure that a constructor is called for the temporary object. Similarly, the destructor shall be called for a temporary with
    a non-trivial destructor (12.4). Temporary objects are destroyed as
    the last step in evaluating the full-expression (1.9) that (lexically)
    contains the point where they were created. This is true even if that
    evaluation ends in throwing an exception. The value computations and
    side effects of destroying a temporary object are associated only with
    the full-expression, not with any specific subexpression.

    And:

    [n3290: 1.9/10]: A full-expression is an expression that is not a
    subexpression of another expression.
    If a language construct is
    defined to produce an implicit call of a function, a use of the
    language construct is considered to be an expression for the purposes
    of this definition. A call to a destructor generated at the end of the
    lifetime of an object other than a temporary object is an implicit
    full-expression. Conversions applied to the result of an expression in
    order to satisfy the requirements of the language construct in which
    the expression appears are also considered to be part of the
    full-expression. [..]

    This means that both f() and second() should exist until execution returns from test() with the result of evaluating the latter.

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

Sidebar

Related Questions

In regards to the order of execution of statements in SQL, is there any
Out of order execution in CPUs means that a CPU can reorder instructions to
Does anyone know of a site or page, or know the order of execution
Probably a trivial question, but in which order does Exception::getTrace return calls? Most recent
Is there any order of execution for the trigger inside a controlTemplate of Style?.
Look at the following program. The comments show the order of execution when I
I want to call three functions someTask1 , someTask2 and someTask3 in that order.
i have a problem with the order of execution of the threads created consecutively.
In c#, is there any difference in the excecution speed for the order in
I'm executing stored procedures using SET FMTONLY ON, in order to emulate what our

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.