public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "davveston at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/110958] New: [CWG 2137][accepts-invalid] Copy-list-initialization with single element of same class only considers converting constructors as viable
Date: Wed, 09 Aug 2023 10:44:39 +0000	[thread overview]
Message-ID: <bug-110958-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110958
           Summary: [CWG 2137][accepts-invalid] Copy-list-initialization
                    with single element of same class only considers
                    converting constructors as viable
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davveston at gmail dot com
  Target Milestone: ---

There are several (closed) bug reports relating to CWG 2137, particularly
highlighting the still present implementation divergence between e.g. GCC and
Clang. These mostly relate to whether or not a non-aggregate class initialized
via single element init-list of same-class resolves to the rules of
[over.match.list] or not. See e.g.
https://gcc.gnu.org/bugzilla//show_bug.cgi?id=85577 and its duplicates

I interpret the wording the same way as GCC, such that after CWG 2137
initializer list constructors take precedence over e.g. copy constructors
([over.match.list]/1.1).

However, when falling through to [over.match.list]/1.2, GCC seems to consider
only converting constructors as if following [over.match.ctor]/1, whereas by
[over.match.list]/1.2 explicit constructors are still viable, although leading
to an ill-formed program if picked as most viable. 

The following example is accepted by GCC:

struct S {
  S()            = default;
  S(S const&)    = default; // #1
  explicit S(S&) = delete;  // #2
};

S a; 
S b = {a}; // #3

As #3 picks #1 for the copy-list-initialization. As of CWG 2137 I believe it
should be rejected as ill-formed as #2 should be selected instead: ill-formed
not due to deleted definition but due to the last paragraph of
[over.match.list]/1.

(Holds for various GCC versions and C++ language versions).

                 reply	other threads:[~2023-08-09 10:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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-110958-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).