https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103630
Bug ID: 103630
Summary: [9/10/11/12 Regression] std::make_exception_ptr<T&>(t)
is ill-formed
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: rejects-valid, wrong-code
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
I'm not 100% this is valid, but it used to work before the changes for PR
68297:
#include <exception>
int i = 0;
auto p = std::make_exception_ptr<int&>(i);
It fails now because the new implementation uses the template argument as
`_Ex*` and as `new _Ex` and those aren't valid for a reference type.
And if we fix that, there's another problem which is that it uses typeid(__ex)
which means we create an exception using the static type of the argument, but
which matches a handler of the dynamic type:
#include <exception>
#include <stdlib.h>
struct B { virtual ~B() = default; };
struct D : B { };
int main()
{
try {
D d;
auto p = std::make_exception_ptr<B&>(d);
std::rethrow_exception(p);
} catch (const D&) {
abort();
} catch (const B&) {
}
}
This throws a B but catches a D.