public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction
@ 2021-07-06 16:24 fchelnokov at gmail dot com
  2021-07-12 11:02 ` [Bug c++/101344] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: fchelnokov at gmail dot com @ 2021-07-06 16:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101344
           Summary: braced-init-list not supported in an aggregate
                    deduction
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

Please consider the program as follows. GCC correctly initializes struct A, but
in more simple case of struct B it fails:

```
template<typename T, int N>
struct A { T t[N]; };

template<typename T>
struct B { T t[2]; };

int main()
{
   A a{{1, 2}}; // ok in gcc
   B b{{1, 2}}; // error in gcc (ok in other compilers, e.g. msvc)
   return a.t[0];
}
```

I believe, struct B initialization shall work here same way.

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

* [Bug c++/101344] braced-init-list not supported in an aggregate deduction
  2021-07-06 16:24 [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction fchelnokov at gmail dot com
@ 2021-07-12 11:02 ` redi at gcc dot gnu.org
  2021-08-12 15:20 ` ppalka at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-12 11:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-07-12
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
N.B. the code requires -std=gnu++20 to compile.

(In reply to Fedor Chelnokov from comment #0)
>    A a{{1, 2}}; // ok in gcc
>    B b{{1, 2}}; // error in gcc (ok in other compilers, e.g. msvc)

FWIW MSVC seems to be the only compiler that accepts it. Clang and Intel do not
accept either line, due to incomplete C++20 support.

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

* [Bug c++/101344] braced-init-list not supported in an aggregate deduction
  2021-07-06 16:24 [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction fchelnokov at gmail dot com
  2021-07-12 11:02 ` [Bug c++/101344] " redi at gcc dot gnu.org
@ 2021-08-12 15:20 ` ppalka at gcc dot gnu.org
  2021-08-12 15:27 ` [Bug c++/101344] [11/12 Regression] " ppalka at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-08-12 15:20 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
                 CC|                            |ppalka at gcc dot gnu.org
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=101803
             Status|NEW                         |ASSIGNED

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Another rejects-valid example (I think):

template<class T=void>
struct C { int m; int t[2]; };

C b{1, {2, 3}};

The relevant wording seems to be
https://eel.is/c++draft/over.match.class.deduct#1.5.  Rather than only
"considering" brace elision for int[2] (and other non-dependent aggregate
type), we seem to require it.

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

* [Bug c++/101344] [11/12 Regression] braced-init-list not supported in an aggregate deduction
  2021-07-06 16:24 [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction fchelnokov at gmail dot com
  2021-07-12 11:02 ` [Bug c++/101344] " redi at gcc dot gnu.org
  2021-08-12 15:20 ` ppalka at gcc dot gnu.org
@ 2021-08-12 15:27 ` ppalka at gcc dot gnu.org
  2021-08-18 12:39 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-08-12 15:27 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |10.1.0, 10.2.0, 10.3.0
      Known to fail|                            |11.1.0, 11.2.0, 12.0
            Summary|braced-init-list not        |[11/12 Regression]
                   |supported in an aggregate   |braced-init-list not
                   |deduction                   |supported in an aggregate
                   |                            |deduction

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
We started rejecting the comment #2 example after r11-1615

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

* [Bug c++/101344] [11/12 Regression] braced-init-list not supported in an aggregate deduction
  2021-07-06 16:24 [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction fchelnokov at gmail dot com
                   ` (2 preceding siblings ...)
  2021-08-12 15:27 ` [Bug c++/101344] [11/12 Regression] " ppalka at gcc dot gnu.org
@ 2021-08-18 12:39 ` cvs-commit at gcc dot gnu.org
  2021-08-18 12:51 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-18 12:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

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

commit r12-2991-gbe4a4fb516688d7cfe28a80a4aa333f4ecf0b518
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Aug 18 08:37:45 2021 -0400

    c++: aggregate CTAD and brace elision [PR101344]

    Here the problem is ultimately that collect_ctor_idx_types always
    recurses into an eligible sub-CONSTRUCTOR regardless of whether the
    corresponding pair of braces was elided in the original initializer.
    This causes us to reject some completely-braced forms of aggregate
    CTAD as in the first testcase below, because collect_ctor_idx_types
    effectively assumes that the original initializer is always minimally
    braced (and so the aggregate deduction candidate is given a function
    type that's incompatible with the original completely-braced initializer).

    In order to fix this, collect_ctor_idx_types needs to somehow know the
    shape of the original initializer when iterating over the reshaped
    initializer.  To that end this patch makes reshape_init flag sub-ctors
    that were built to undo brace elision in the original ctor, so that
    collect_ctor_idx_types that determine whether to recurse into a sub-ctor
    by simply inspecting this flag.

    This happens to also fix PR101820, which is about aggregate CTAD using
    designated initializers, for much the same reasons.

    A curious case is the "intermediately-braced" initialization of 'e3'
    (which we reject) in the first testcase below.  It seems to me we're
    behaving as specified here (according to [over.match.class.deduct]/1)
    because the initializer element x_1={1, 2, 3, 4} corresponds to the
    subobject e_1=E::t, hence the type T_1 of the first function parameter
    of the aggregate deduction candidate is T(&&)[2][2], but T can't be
    deduced from x_1 using this parameter type (as opposed to say T(&&)[4]).

            PR c++/101344
            PR c++/101820

    gcc/cp/ChangeLog:

            * cp-tree.h (CONSTRUCTOR_BRACES_ELIDED_P): Define.
            * decl.c (reshape_init_r): Set it.
            * pt.c (collect_ctor_idx_types): Recurse into a sub-CONSTRUCTOR
            iff CONSTRUCTOR_BRACES_ELIDED_P.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/class-deduction-aggr11.C: New test.
            * g++.dg/cpp2a/class-deduction-aggr12.C: New test.

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

* [Bug c++/101344] [11/12 Regression] braced-init-list not supported in an aggregate deduction
  2021-07-06 16:24 [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction fchelnokov at gmail dot com
                   ` (3 preceding siblings ...)
  2021-08-18 12:39 ` cvs-commit at gcc dot gnu.org
@ 2021-08-18 12:51 ` ppalka at gcc dot gnu.org
  2021-09-19 23:17 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-08-18 12:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Whoops, wrong PR number.. the above commit should refer to PR101803 not
PR101820.  I'll correct this tomorrow, after the ChangeLog entry is generated

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

* [Bug c++/101344] [11/12 Regression] braced-init-list not supported in an aggregate deduction
  2021-07-06 16:24 [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction fchelnokov at gmail dot com
                   ` (4 preceding siblings ...)
  2021-08-18 12:51 ` ppalka at gcc dot gnu.org
@ 2021-09-19 23:17 ` pinskia at gcc dot gnu.org
  2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-19 23:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.3

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

* [Bug c++/101344] [11/12 Regression] braced-init-list not supported in an aggregate deduction
  2021-07-06 16:24 [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction fchelnokov at gmail dot com
                   ` (5 preceding siblings ...)
  2021-09-19 23:17 ` pinskia at gcc dot gnu.org
@ 2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
  2021-10-06 14:18 ` ppalka at gcc dot gnu.org
  2021-10-07  6:55 ` fchelnokov at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-06 14:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

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

commit r11-9079-gdc867191914eff2993312fc25c48db4b7c6289e9
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Aug 18 08:37:45 2021 -0400

    c++: aggregate CTAD and brace elision [PR101344]

    Here the problem is ultimately that collect_ctor_idx_types always
    recurses into an eligible sub-CONSTRUCTOR regardless of whether the
    corresponding pair of braces was elided in the original initializer.
    This causes us to reject some completely-braced forms of aggregate
    CTAD as in the first testcase below, because collect_ctor_idx_types
    effectively assumes that the original initializer is always minimally
    braced (and so the aggregate deduction candidate is given a function
    type that's incompatible with the original completely-braced initializer).

    In order to fix this, collect_ctor_idx_types needs to somehow know the
    shape of the original initializer when iterating over the reshaped
    initializer.  To that end this patch makes reshape_init flag sub-ctors
    that were built to undo brace elision in the original ctor, so that
    collect_ctor_idx_types that determine whether to recurse into a sub-ctor
    by simply inspecting this flag.

    This happens to also fix PR101820, which is about aggregate CTAD using
    designated initializers, for much the same reasons.

    A curious case is the "intermediately-braced" initialization of 'e3'
    (which we reject) in the first testcase below.  It seems to me we're
    behaving as specified here (according to [over.match.class.deduct]/1)
    because the initializer element x_1={1, 2, 3, 4} corresponds to the
    subobject e_1=E::t, hence the type T_1 of the first function parameter
    of the aggregate deduction candidate is T(&&)[2][2], but T can't be
    deduced from x_1 using this parameter type (as opposed to say T(&&)[4]).

            PR c++/101344
            PR c++/101803

    gcc/cp/ChangeLog:

            * cp-tree.h (CONSTRUCTOR_BRACES_ELIDED_P): Define.
            * decl.c (reshape_init_r): Set it.
            * pt.c (collect_ctor_idx_types): Recurse into a sub-CONSTRUCTOR
            iff CONSTRUCTOR_BRACES_ELIDED_P.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/class-deduction-aggr11.C: New test.
            * g++.dg/cpp2a/class-deduction-aggr12.C: New test.

    (cherry picked from commit be4a4fb516688d7cfe28a80a4aa333f4ecf0b518)

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

* [Bug c++/101344] [11/12 Regression] braced-init-list not supported in an aggregate deduction
  2021-07-06 16:24 [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction fchelnokov at gmail dot com
                   ` (6 preceding siblings ...)
  2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
@ 2021-10-06 14:18 ` ppalka at gcc dot gnu.org
  2021-10-07  6:55 ` fchelnokov at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-10-06 14:18 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

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

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 11.3 and 12.

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

* [Bug c++/101344] [11/12 Regression] braced-init-list not supported in an aggregate deduction
  2021-07-06 16:24 [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction fchelnokov at gmail dot com
                   ` (7 preceding siblings ...)
  2021-10-06 14:18 ` ppalka at gcc dot gnu.org
@ 2021-10-07  6:55 ` fchelnokov at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: fchelnokov at gmail dot com @ 2021-10-07  6:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
Thanks!

Related discussion: https://stackoverflow.com/q/67280884/7325599

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

end of thread, other threads:[~2021-10-07  6:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 16:24 [Bug c++/101344] New: braced-init-list not supported in an aggregate deduction fchelnokov at gmail dot com
2021-07-12 11:02 ` [Bug c++/101344] " redi at gcc dot gnu.org
2021-08-12 15:20 ` ppalka at gcc dot gnu.org
2021-08-12 15:27 ` [Bug c++/101344] [11/12 Regression] " ppalka at gcc dot gnu.org
2021-08-18 12:39 ` cvs-commit at gcc dot gnu.org
2021-08-18 12:51 ` ppalka at gcc dot gnu.org
2021-09-19 23:17 ` pinskia at gcc dot gnu.org
2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
2021-10-06 14:18 ` ppalka at gcc dot gnu.org
2021-10-07  6:55 ` fchelnokov at gmail dot com

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