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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:45:43+00:00 2026-05-13T15:45:43+00:00

Suppose I have the following snipplet: Foo foo; …. return bar(); Now, does the

  • 0

Suppose I have the following snipplet:

Foo foo;
....
return bar();

Now, does the C++ standard guarantees me that bar() will be called before foo::~Foo() ? Or is this the compiler/implementation’s choice?

Thanks!

  • 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-13T15:45:43+00:00Added an answer on May 13, 2026 at 3:45 pm

    It is guaranteed behaviour. The actual execution is unrolled as follows:

    0: enter block (scope)
    1: Foo::Foo()
    2. evaluation of bar(); as expression in return statement
    3. save result of the expression as value returned from function
    4. finalize return statement to leave function to its caller (request exit from current scope)
    5: exit block (scope) with call to  Foo::~Foo()
    

    Here are some references from the standard:

    • What program execution guarantees, generally

    1.9 Program execution

    10 An instance of each object with automatic storage duration (3.7.2) is
    associated with each entry into its
    block.

    • The foo is of automatic storage duration and:

    3.7.2 Automatic storage duration

    1 Local objects explicitly declared auto or register or not explicitly declared
    static or extern have automatic storage duration. The storage for
    these objects lasts until the block in which they are created exits.

    • What is actual effect of return statement

    6.6.3 The return statement

    2 (…) the value of the expression is returned to the caller of the function

    and

    6.6 Jump statements (return belongs to jump statements)

    2 On exit from a scope (however accomplished), destructors (12.4) are called for all
    constructed objects with automatic storage duration (3.7.2)

    • What guarantees that the effect occurs

    6.7 Declaration statement

    2 Variables with automatic storage duration declared in the block are
    destroyed on exit from the block

    and

    12.4 Destructors

    10 Destructors are invoked implicitly (1) for a constructed
    object with static storage duration
    (3.7.1) at program termination
    (3.6.3), (2) for a constructed object
    with automatic storage duration
    (3.7.2) when the block in which the
    object is created exits (6.7)

    It is not easy to grasp single idea form details scattered around all the C++ standard. Hopefully, quick overview will help you to make such analysis yourself too.

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

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here is the solution :) Because you are using a… May 14, 2026 at 6:08 pm
  • Editorial Team
    Editorial Team added an answer Those macros will have two versions, one that is just… May 14, 2026 at 6:08 pm
  • Editorial Team
    Editorial Team added an answer From the git-commit man page: -u[], --untracked-files[=] Show untracked files… May 14, 2026 at 6:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.