https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86347

            Bug ID: 86347
           Summary: Incorrect call order of allocation function in new
                    expression
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stinkingmadgod at gmail dot com
  Target Milestone: ---

As per [expr.new]/19 the statement new Type{expr}; should
1. call operator new
2. evaluate expr
3. initialize Type object

The example seems to suggest this isn't the case

struct Y
{
    Y() { std::cout << "Y()\n"; }
    Y(const Y&)
    {
        std::cout << "Y(const Y&)\n";
        throw "tantrum"; 
    }
};

struct X {
    X(Y y) noexcept { }
};

int main()
{
    try
    {
        [[maybe_unused]] Y y;
        new X{y};
    }
    catch(...)
    {

    }
}

Should have output
new
Y()
Y(const Y&)

But has output
Y()
Y(const Y&)

Without the throw statement, it has output
Y()
Y(const Y&)
new

Reply via email to