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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:24:43+00:00 2026-05-29T16:24:43+00:00

This question is a dual of Constructor with by-value parameter & noexcept . That

  • 0

This question is a dual of “Constructor with by-value parameter & noexcept”. That question showed that lifetime management of a by-value function argument is handled by the calling function; therefore the caller handles any exceptions that happen and the called-function can mark itself noexcept. I’m wondering how the output end is handled with noexcept.

MyType  MyFunction( SomeType const &x ) noexcept;

//...

void  MyCaller()
{
    MyType  test1 = MyFunction( RandomSomeType() );
    MyType  test2{ MyFunction( RandomSomeType() ) };
    //...
    test1 = MyFunction( RandomSomeType() );
    test2 = std::move( MyFunction(RandomSomeType()) );
    MyFunction( RandomSomeType() );  // return value goes to oblivion
}

Let’s say that the return value is successfully created within MyFunction. And let’s say that the appropriate special member functions (copy/move-assignment/construction) of MyType may not be noexcept.

  1. Do the RVO/NRVO/Whatever-from-C++11 rules concerning the transfer of return values from the called function to the caller mean that the transfer always succeeds no-throw no matter the noexcept status of the appropriate special member function?
  2. If the answer to the previous question is “no,” then if the return value transfer throws, does the exception count against the called function or the caller?
  3. If the answer to the previous question is “the called function,” then the plain noexcept marker on MyFunction will cause a call to std::terminate. What should MyFunction‘s noexcept profile be changed to? When I asked about this on the Usenet, a respondent thought it should be std::is_nothrow_move_assignable<MyType>::value. (Note that MyCaller used several methods of using a return value, but MyFunction won’t know which one is in use! The answer has to cover all cases.) Does it make a difference if MyType is changed to be copyable but non-movable?

So if the worst-cases of the second and third questions are accurate, then any function that returns by value can’t have a plain noexcept if the return type has a throw-able move! Now types with throw-able moves should be rare, but template code still has to “dirty” itself with is_nothrow_move_assignable every time return-by-value is used.

I think making the called-function responsible is broken:

MyType  MyFunction( SomeType const &x ) noexcept( ??? )
{
    //...
    try {
        return SOME_EXPRESSION;

        // What happens if the creation of SOME_EXPRESSION succeeds, but the
        // move-assignment (or whatever) transferring the result fails?  Is
        // this try/catch triggered?  Or is there no place lexically this
        // function can block a throwing move!?
    } catch (...) {
        return MyType();

        // Note that even if default-construction doesn't throw, the
        // move-assignment may throw (again)!  Now what?
    }
}

This problem, to me at least, seems fixable at the caller’s end (just wrap the move-assignment with a try/catch) but unfixable from the called-function’s end. I think the caller has to handle this, even if we need to change the rules of C++ to do so. Or at least some sort of defect report is needed.

  • 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-29T16:24:44+00:00Added an answer on May 29, 2026 at 4:24 pm

    To answer part of your question, you can ask whether a certain type is nothrow constructible:

    #include <type_traits>
    
    MyType  MyFunction( SomeType const &x )
        noexcept(std::is_nothrow_move_constructible<MyType>::value)
    {
      // ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I realize this question sounds stupid (and yes I am using a dual
This is a rather broad question, but I'm a beginner-intermediate programmer that has just
Follow-to this question: The Dual Nature of svn:ignore Is there any way to accomplish
Alright, this is a sort of dual-purpose question. The main thing I hope to
This question is kind of an add-on to this question In C#, a switch
This question and answer shows how to send a file as a byte array
This question comes on the heels of the question asked here . The email
This question would probably apply equally as well to other languages with C-like multi-line
This question is a follow up to my previous question about getting the HTML
(This question is over 6 years old and probably no longer has any relevance.)

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.