public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94149] New: __is_constructible doesn't know about C++20 parenthesized init for arrays
@ 2020-03-11 18:41 redi at gcc dot gnu.org
  2020-03-11 18:47 ` [Bug c++/94149] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-11 18:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94149
           Summary: __is_constructible doesn't know about C++20
                    parenthesized init for arrays
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

In C++20 this is well-formed:

  using T = int[2];
  T t(1, 2);

which means that std::is_constructible_v<int[2], int, int> should be true.

The FE intrinsic gives the wrong answer, and the std::is_nothrow_constructible
library trait isn't going to work even if the intrinsic starts to give the
right answer.


i.e. this should compile with -std=gnu++2a

#include <type_traits>

int main()
{
  using T = int[2];
  T t(1, 2);

  static_assert(__is_constructible(T, int, int));
  static_assert(std::is_constructible_v<T, int, int>);
  static_assert(std::is_nothrow_constructible_v<T, int, int>);

  return t[0];
}


a.cc: In function 'int main()':
a.cc:8:17: error: static assertion failed
    8 |   static_assert(__is_constructible(T, int, int));
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:9:22: error: static assertion failed
    9 |   static_assert(std::is_constructible_v<T, int, int>);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:10:22: error: static assertion failed
   10 |   static_assert(std::is_nothrow_constructible_v<T, int, int>);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

* [Bug c++/94149] __is_constructible doesn't know about C++20 parenthesized init for arrays
  2020-03-11 18:41 [Bug c++/94149] New: __is_constructible doesn't know about C++20 parenthesized init for arrays redi at gcc dot gnu.org
@ 2020-03-11 18:47 ` redi at gcc dot gnu.org
  2020-03-11 19:58 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-11 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-03-11
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And of course __is_constructible(int[3], int, int) should work too.

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

* [Bug c++/94149] __is_constructible doesn't know about C++20 parenthesized init for arrays
  2020-03-11 18:41 [Bug c++/94149] New: __is_constructible doesn't know about C++20 parenthesized init for arrays redi at gcc dot gnu.org
  2020-03-11 18:47 ` [Bug c++/94149] " redi at gcc dot gnu.org
@ 2020-03-11 19:58 ` mpolacek at gcc dot gnu.org
  2020-03-11 20:29 ` ville.voutilainen at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-03-11 19:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
C++20 paren-init -> mine.

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

* [Bug c++/94149] __is_constructible doesn't know about C++20 parenthesized init for arrays
  2020-03-11 18:41 [Bug c++/94149] New: __is_constructible doesn't know about C++20 parenthesized init for arrays redi at gcc dot gnu.org
  2020-03-11 18:47 ` [Bug c++/94149] " redi at gcc dot gnu.org
  2020-03-11 19:58 ` mpolacek at gcc dot gnu.org
@ 2020-03-11 20:29 ` ville.voutilainen at gmail dot com
  2020-04-09 21:03 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ville.voutilainen at gmail dot com @ 2020-03-11 20:29 UTC (permalink / raw)
  To: gcc-bugs

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

Ville Voutilainen <ville.voutilainen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ville.voutilainen at gmail dot com

--- Comment #3 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
(In reply to Marek Polacek from comment #2)
> C++20 paren-init -> mine.

This goes from constructible_expr into
perform_direct_initialization_if_possible, which then goes into
implicit_conversion, which fails to build a conversion.

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

* [Bug c++/94149] __is_constructible doesn't know about C++20 parenthesized init for arrays
  2020-03-11 18:41 [Bug c++/94149] New: __is_constructible doesn't know about C++20 parenthesized init for arrays redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-03-11 20:29 ` ville.voutilainen at gmail dot com
@ 2020-04-09 21:03 ` mpolacek at gcc dot gnu.org
  2020-04-10 17:55 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-09 21:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, rejects-valid

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Patch posted:
<https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543670.html>

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

* [Bug c++/94149] __is_constructible doesn't know about C++20 parenthesized init for arrays
  2020-03-11 18:41 [Bug c++/94149] New: __is_constructible doesn't know about C++20 parenthesized init for arrays redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2020-04-09 21:03 ` mpolacek at gcc dot gnu.org
@ 2020-04-10 17:55 ` cvs-commit at gcc dot gnu.org
  2020-04-10 17:56 ` mpolacek at gcc dot gnu.org
  2020-04-21 21:19 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-04-10 17:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:62c25d7adb1a5664982449dda0e7f9ca63cf4735

commit r10-7681-g62c25d7adb1a5664982449dda0e7f9ca63cf4735
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Apr 9 16:31:59 2020 -0400

    c++: make __is_constructible work with paren-init of aggrs [PR94149]

    In C++20 this is well-formed:

      using T = int[2];
      T t(1, 2);

    which means that std::is_constructible_v<int[2], int, int> should be true.
    But constructible_expr immediately returned the error_mark_node when it
    saw a list with more than one element.  To give accurate results in
    C++20, we have to try initializing the aggregate from a parenthesized list
of
    values.

    To not repeat the same mistake as in c++/93790, if there's only one
    element, I'm trying {} only when () didn't succeed.  is_constructible5.C
    verifies this.

    In paren-init24.C std::is_nothrow_constructible_v doesn't work due to
     error: invalid 'static_cast' from type 'int' to type 'int [1]'
    and
     error: functional cast to array type 'int [2]'

    This needs to be fixed in libstdc++.

            PR c++/94149
            * method.c (constructible_expr): In C++20, try using parenthesized
            initialization of aggregates to determine the result of
            __is_constructible.

            * g++.dg/cpp2a/paren-init24.C: New test.
            * g++.dg/cpp2a/paren-init25.C: New test.
            * g++.dg/ext/is_constructible5.C: New test.

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

* [Bug c++/94149] __is_constructible doesn't know about C++20 parenthesized init for arrays
  2020-03-11 18:41 [Bug c++/94149] New: __is_constructible doesn't know about C++20 parenthesized init for arrays redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2020-04-10 17:55 ` cvs-commit at gcc dot gnu.org
@ 2020-04-10 17:56 ` mpolacek at gcc dot gnu.org
  2020-04-21 21:19 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-10 17:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

* [Bug c++/94149] __is_constructible doesn't know about C++20 parenthesized init for arrays
  2020-03-11 18:41 [Bug c++/94149] New: __is_constructible doesn't know about C++20 parenthesized init for arrays redi at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2020-04-10 17:56 ` mpolacek at gcc dot gnu.org
@ 2020-04-21 21:19 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-04-21 21:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

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

commit r10-7856-gd76925e46fad09fc9be6759cbf1f23c9a8344dbf
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Apr 21 22:18:51 2020 +0100

    libstdc++: Support arrays in std::is_nothrow_constructible (PR 94149)

    The front end now supports parenthesized initialization for arrays in
    C++20, so extend std::is_nothrow_constructible to support them too.

    gcc/testsuite:

            PR c++/94149
            * g++.dg/cpp2a/paren-init24.C: Fix FIXMEs.

    libstdc++-v3:

            PR c++/94149
            * include/std/type_traits (__is_nt_constructible_impl): Add partial
            specializations for bounded arrays with non-empty initializers.
            * testsuite/20_util/is_nothrow_constructible/value_c++20.cc: New
test.

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

end of thread, other threads:[~2020-04-21 21:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 18:41 [Bug c++/94149] New: __is_constructible doesn't know about C++20 parenthesized init for arrays redi at gcc dot gnu.org
2020-03-11 18:47 ` [Bug c++/94149] " redi at gcc dot gnu.org
2020-03-11 19:58 ` mpolacek at gcc dot gnu.org
2020-03-11 20:29 ` ville.voutilainen at gmail dot com
2020-04-09 21:03 ` mpolacek at gcc dot gnu.org
2020-04-10 17:55 ` cvs-commit at gcc dot gnu.org
2020-04-10 17:56 ` mpolacek at gcc dot gnu.org
2020-04-21 21:19 ` cvs-commit 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).