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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:21:53+00:00 2026-05-29T10:21:53+00:00

I recently started to add the new noexcept specification to move constructors/assignments wherever possible.

  • 0

I recently started to add the new noexcept specification to move constructors/assignments wherever possible. Now I started to wonder what the exception specification of implicit generated member functions looks like. Since having noexcept move functions allows the use of more efficient code paths(e.g. when resizing a vector) I would hope that those are declared as noexcept whenever possible. I had problems understanding what the standard has to say about that and therefore tried the following code in g++4.6 (with -std=c++0x) to get some grip on it:

struct foobar{};
int main()
{
    foobar a, b;
    std::cout<<std::boolalpha
             <<noexcept(foobar())<<", "<<noexcept(foobar(a))<<", "
             <<noexcept(a = b)   <<", "<<noexcept(a = std::move(b))<<", "
             <<noexcept(foobar(std::move(a)))<<std::endl;
}

This gave me an output of True, True, True, False, False, meaning that default and copy constructor/assignment where noexcept, while move operation where not.

Now for my question:

Under what circumstances are implicit generated (or defaulted) member functions declared as noexcept? Furthermore is the obseved behaviour for foobar correct or simply a compiler bug in gcc4.6?

  • 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-29T10:21:54+00:00Added an answer on May 29, 2026 at 10:21 am

    Library bug — it shows true, true, true, true, true in gcc 4.7.

    And the bug is not that the generated move constructors aren’t noexcept, but that std::move is not marked as noexcept, as we can see with the additional tests:

    std::cout << noexcept(a = static_cast<foobar&&>(b)) << ", "  // true
              << noexcept(foobar(static_cast<foobar&&>(b))) << ", " // true
              << noexcept(std::move(b)) << std::endl;   // false
    

    Most of the library functions in gcc 4.6 was not noexcept-correct, and this has been addressed in gcc 4.7,


    As for when the implcitely generated member functions are noexcept, this is documented in §15.4/14. Basically, it is noexcept if all functions it will need to call are all noexcept.

    An implicitly declared special member function (Clause 12) shall have an exception-specification. If f is
    an implicitly declared default constructor, copy constructor, move constructor, destructor, copy assignment
    operator, or move assignment operator, its implicit exception-specification specifies the type-id T if and only
    if T is allowed by the exception-specification of a function directly invoked by f’s implicit definition; f shall
    allow all exceptions if any function it directly invokes allows all exceptions, and f shall allow no exceptions
    if every function it directly invokes allows no exceptions.

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

Sidebar

Related Questions

I recently started using Masterpages, the thing is I would like to add text
I recently started a new webforms project and decided to separate the business classes
I have recently started working on a web application at a new company and
I've recently started out with JSF (I'm also quite new to HTML) and I
I just recently started a new personal project, with a goal of having it
Recently a large project I work on started having a problem with the Add
I have recently started a new job, and the company uses Visual SourceSafe for
I recently started to add comments on properties declaration on my php classes. The
I started learning asp.net recently and when I try to add a script manager
I recently started using Git when creating a new project - until then I

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.