public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109159] New: explicit constructor is used in copy-initialization
@ 2023-03-16 19:51 fchelnokov at gmail dot com
  2023-03-16 21:35 ` [Bug c++/109159] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: fchelnokov at gmail dot com @ 2023-03-16 19:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109159
           Summary: explicit constructor is used in copy-initialization
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following code must be accepted (as it does in Clang and MSVC):

struct A {
    A( float ) {}
    template<class U>
    explicit A( U ) {}
};

template<class T>
concept CopyFromIntList = requires( T t ) { t = { 1 }; };

static_assert( !CopyFromIntList<A> );

because 't = {1}' is invalid: chosen constructor is explicit in
copy-initialization.

But in GCC static_assert fails. Online demo:
https://gcc.godbolt.org/z/Pf47E6dno

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/109159] explicit constructor is used in copy-initialization
  2023-03-16 19:51 [Bug c++/109159] New: explicit constructor is used in copy-initialization fchelnokov at gmail dot com
@ 2023-03-16 21:35 ` pinskia at gcc dot gnu.org
  2023-03-16 21:35 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-16 21:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-03-16
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase without the constraint that GCC accepts:
struct A {
    A( float ) {}
    template<class U>
    explicit A( U ) {}
};

void f(A t)
{
  t = {1};
}

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/109159] explicit constructor is used in copy-initialization
  2023-03-16 19:51 [Bug c++/109159] New: explicit constructor is used in copy-initialization fchelnokov at gmail dot com
  2023-03-16 21:35 ` [Bug c++/109159] " pinskia at gcc dot gnu.org
@ 2023-03-16 21:35 ` pinskia at gcc dot gnu.org
  2023-03-16 21:42 ` [Bug c++/109159] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-16 21:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |UNCONFIRMED
     Ever confirmed|1                           |0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/109159] [10/11/12/13 Regression] explicit constructor is used in copy-initialization
  2023-03-16 19:51 [Bug c++/109159] New: explicit constructor is used in copy-initialization fchelnokov at gmail dot com
  2023-03-16 21:35 ` [Bug c++/109159] " pinskia at gcc dot gnu.org
  2023-03-16 21:35 ` pinskia at gcc dot gnu.org
@ 2023-03-16 21:42 ` pinskia at gcc dot gnu.org
  2023-03-16 21:46 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-16 21:42 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.5
           Keywords|                            |needs-bisection
            Summary|explicit constructor is     |[10/11/12/13 Regression]
                   |used in copy-initialization |explicit constructor is
                   |                            |used in copy-initialization

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/109159] [10/11/12/13 Regression] explicit constructor is used in copy-initialization
  2023-03-16 19:51 [Bug c++/109159] New: explicit constructor is used in copy-initialization fchelnokov at gmail dot com
                   ` (2 preceding siblings ...)
  2023-03-16 21:42 ` [Bug c++/109159] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
@ 2023-03-16 21:46 ` mpolacek at gcc dot gnu.org
  2023-03-17 21:16 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-16 21:46 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Keywords|needs-bisection             |
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
           Priority|P3                          |P2
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Oy, started with r9-3735-gb5ff4f5c0d61e5:

commit b5ff4f5c0d61e52e27a0727ae9e011aab525ccfd
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Oct 30 19:59:41 2018 +0000

    Implement P0892R2, explicit(bool).

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/109159] [10/11/12/13 Regression] explicit constructor is used in copy-initialization
  2023-03-16 19:51 [Bug c++/109159] New: explicit constructor is used in copy-initialization fchelnokov at gmail dot com
                   ` (3 preceding siblings ...)
  2023-03-16 21:46 ` mpolacek at gcc dot gnu.org
@ 2023-03-17 21:16 ` mpolacek at gcc dot gnu.org
  2023-03-20 20:54 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-17 21:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This hunk broke it:

@@ -3251,6 +3251,12 @@ add_template_candidate_real (struct z_candidate
**candidates, tree tmpl,
       goto fail;
     }

+  /* Now the explicit specifier might have been deduced; check if this
+     declaration is explicit.  If it is and we're ignoring non-converting
+     constructors, don't add this function to the set of candidates.  */
+  if ((flags & LOOKUP_ONLYCONVERTING) && DECL_NONCONVERTING_P (fn))
+    return NULL;


It doesn't check for BRACE_ENCLOSED_INITIALIZER_P (or some similar flag meaning
we're initializing from an initializer_list) and that's the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/109159] [10/11/12/13 Regression] explicit constructor is used in copy-initialization
  2023-03-16 19:51 [Bug c++/109159] New: explicit constructor is used in copy-initialization fchelnokov at gmail dot com
                   ` (4 preceding siblings ...)
  2023-03-17 21:16 ` mpolacek at gcc dot gnu.org
@ 2023-03-20 20:54 ` cvs-commit at gcc dot gnu.org
  2023-03-20 20:56 ` [Bug c++/109159] [10/11/12 " mpolacek at gcc dot gnu.org
  2023-03-27 14:06 ` mpolacek at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-20 20:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:a226590fefb35ed66adf73d85cefe49048a78ab8

commit r13-6765-ga226590fefb35ed66adf73d85cefe49048a78ab8
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Mar 17 18:25:13 2023 -0400

    c++: explicit ctor and list-initialization [PR109159]

    When I implemented explicit(bool) in r9-3735, I added this code to
    add_template_candidate_real:
    +  /* Now the explicit specifier might have been deduced; check if this
    +     declaration is explicit.  If it is and we're ignoring non-converting
    +     constructors, don't add this function to the set of candidates.  */
    +  if ((flags & LOOKUP_ONLYCONVERTING) && DECL_NONCONVERTING_P (fn))
    +    return NULL;
    but as this test demonstrates, that's incorrect when we're initializing
    from a {}: for list-initialization we consider explicit constructors and
    complain if one is chosen.

            PR c++/109159

    gcc/cp/ChangeLog:

            * call.cc (add_template_candidate_real): Add explicit decls to the
            set of candidates when the initializer is a braced-init-list.

    libstdc++-v3/ChangeLog:

            * testsuite/20_util/pair/cons/explicit_construct.cc: Adjust
dg-error.
            * testsuite/20_util/tuple/cons/explicit_construct.cc: Likewise.
            * testsuite/23_containers/span/explicit.cc: Likewise.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/explicit16.C: New test.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/109159] [10/11/12 Regression] explicit constructor is used in copy-initialization
  2023-03-16 19:51 [Bug c++/109159] New: explicit constructor is used in copy-initialization fchelnokov at gmail dot com
                   ` (5 preceding siblings ...)
  2023-03-20 20:54 ` cvs-commit at gcc dot gnu.org
@ 2023-03-20 20:56 ` mpolacek at gcc dot gnu.org
  2023-03-27 14:06 ` mpolacek at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-20 20:56 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11/12/13 Regression]    |[10/11/12 Regression]
                   |explicit constructor is     |explicit constructor is
                   |used in copy-initialization |used in copy-initialization

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/109159] [10/11/12 Regression] explicit constructor is used in copy-initialization
  2023-03-16 19:51 [Bug c++/109159] New: explicit constructor is used in copy-initialization fchelnokov at gmail dot com
                   ` (6 preceding siblings ...)
  2023-03-20 20:56 ` [Bug c++/109159] [10/11/12 " mpolacek at gcc dot gnu.org
@ 2023-03-27 14:06 ` mpolacek at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-27 14:06 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The patch caused non-bug bug 109247, so I don't think it's appropriate to
backport this (?).

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-03-27 14:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16 19:51 [Bug c++/109159] New: explicit constructor is used in copy-initialization fchelnokov at gmail dot com
2023-03-16 21:35 ` [Bug c++/109159] " pinskia at gcc dot gnu.org
2023-03-16 21:35 ` pinskia at gcc dot gnu.org
2023-03-16 21:42 ` [Bug c++/109159] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
2023-03-16 21:46 ` mpolacek at gcc dot gnu.org
2023-03-17 21:16 ` mpolacek at gcc dot gnu.org
2023-03-20 20:54 ` cvs-commit at gcc dot gnu.org
2023-03-20 20:56 ` [Bug c++/109159] [10/11/12 " mpolacek at gcc dot gnu.org
2023-03-27 14:06 ` mpolacek at gcc dot gnu.org

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