按值传递参数时在何处抛出异常

Where are exceptions thrown when arguments are passed by value

复制时我有一个类型抛出:

struct A { A(const A&) { throw 1; } };

void doit(A)
{
}

int main()
{
    A a;
    doit(a);
    return 0;
}

异常是在函数内部还是外部抛出?我可以将函数声明为 noexcept 吗?

参见 C++17 [expr.call]/4

... The initialization and destruction of each parameter occurs within the context of the calling function. [ Example: The access of the constructor, conversion functions or destructor is checked at the point of call in the calling function. If a constructor or destructor for a function parameter throws an exception, the search for a handler starts in the scope of the calling function; in particular, if the function called has a function-try-block (Clause 18) with a handler that could handle the exception, this handler is not considered. — end example ]

因此,如您所说,异常是抛出 "outside of the function"。你可以声明它 noexcept.