在 C++ 中使用非 const 引用的构造函数捕获异常类型

Catching an exception type with constructor from not-const reference in C++

考虑一个结构 A,删除了复制构造函数,但取而代之的是来自非 const 引用的构造函数。是否可以抛出一个 A 的对象,然后像示例程序中那样按值捕获它:

struct A {
    A() {}
    A(A&) {}
    A(const A&) = delete;
};

int main() {
    try {
        throw A{};
    }
    catch( A ) {
    }
}

GCC 和 Clang 都允许这样的用法。尽管 MSVC 打印错误:

C2316: 'A': cannot be caught as the destructor and/or copy constructor are inaccessible or deleted

演示:https://gcc.godbolt.org/z/P4c6Ea9fz

确实 A(const A&) 已删除,但 A(A&) 可在此处访问。是 MSVC 的错误诊断吗?

这是一个 MSVC 错误:异常对象永远不会 cv-qualified,处理程序变量从 lvalue 指的是它们。 (标准实际上并没有说明左值的类型是什么,但没有理由认为它应该是 const 限定的。)