public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/103630] New: [9/10/11/12 Regression] std::make_exception_ptr<T&>(t) is ill-formed
Date: Thu, 09 Dec 2021 13:36:36 +0000	[thread overview]
Message-ID: <bug-103630-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2021-12-09 13:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-09 13:36 redi at gcc dot gnu.org [this message]
2021-12-09 13:37 ` [Bug libstdc++/103630] " redi at gcc dot gnu.org
2021-12-09 13:53 ` redi at gcc dot gnu.org
2021-12-09 23:29 ` cvs-commit at gcc dot gnu.org
2021-12-09 23:33 ` [Bug libstdc++/103630] [9/10/11 " redi at gcc dot gnu.org
2022-04-07 10:06 ` rguenth at gcc dot gnu.org
2022-04-12 20:18 ` cvs-commit at gcc dot gnu.org
2022-04-12 20:30 ` [Bug libstdc++/103630] [9/10 " redi at gcc dot gnu.org
2022-04-26 13:12 ` cvs-commit at gcc dot gnu.org
2022-04-26 13:14 ` [Bug libstdc++/103630] [9 " redi at gcc dot gnu.org
2022-05-09 16:40 ` cvs-commit at gcc dot gnu.org
2022-05-09 16:50 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103630-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).