public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103299] New: accessing incorrect storage for union at constexpr context
@ 2021-11-17  9:08 unlvsur at live dot com
  2021-11-17 14:28 ` [Bug c++/103299] [10/11/12 Regression] accessing incorrect storage for designated init of anonymous " ppalka at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: unlvsur at live dot com @ 2021-11-17  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103299
           Summary: accessing incorrect storage for union at constexpr
                    context
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: unlvsur at live dot com
  Target Milestone: ---

struct compile_time_fp
{
        void* ct_fp{};
};

struct foo
{
        union
        {
        void* fp{};
        compile_time_fp ct_fp;
        };
};

inline constexpr foo foo_factory()
{
        if (__builtin_is_constant_evaluated())
        {
                return {.ct_fp={}};
        }
        else
        {
                return {};
        }
}

constexpr bool test_direct_construction()
{
        foo f{.ct_fp={}};
        f.ct_fp;
        return true;
}


constexpr bool test_factory_construction()
{
        foo_factory().ct_fp;
        return true;
}
static_assert(test_direct_construction());
static_assert(test_factory_construction());//should not fail


GCC fails for the 2nd one while msvc and clang all accept the code here.

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

* [Bug c++/103299] [10/11/12 Regression] accessing incorrect storage for designated init of anonymous union at constexpr context
  2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
@ 2021-11-17 14:28 ` ppalka at gcc dot gnu.org
  2021-11-17 14:37 ` [Bug c++/103299] [11/12 " ppalka at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-11-17 14:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |11.2.0, 12.0
           Keywords|                            |rejects-valid
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=102538
             Status|UNCONFIRMED                 |NEW
      Known to work|                            |10.1.0, 10.2.0, 10.3.0
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org
            Summary|accessing incorrect storage |[10/11/12 Regression]
                   |for union at constexpr      |accessing incorrect storage
                   |context                     |for designated init of
                   |                            |anonymous union at
                   |                            |constexpr context
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-11-17
   Target Milestone|---                         |10.4

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Started with r12-954, which has also been backported to the 11/10 branches.

Reduced rejects-valid testcase:

struct foo {
  union {
    int fp1{};
    char fp2;
  };
};

static_assert(foo{.fp2={}}.fp2 == 0);

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

* [Bug c++/103299] [11/12 Regression] accessing incorrect storage for designated init of anonymous union at constexpr context
  2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
  2021-11-17 14:28 ` [Bug c++/103299] [10/11/12 Regression] accessing incorrect storage for designated init of anonymous " ppalka at gcc dot gnu.org
@ 2021-11-17 14:37 ` ppalka at gcc dot gnu.org
  2021-11-18  7:46 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-11-17 14:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11/12 Regression]       |[11/12 Regression]
                   |accessing incorrect storage |accessing incorrect storage
                   |for designated init of      |for designated init of
                   |anonymous union at          |anonymous union at
                   |constexpr context           |constexpr context
   Target Milestone|10.4                        |11.3

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Actually I don't think the bug is present on the 10 branch since the full
r12-954 fix hasn't been backported there according to PR100489#c4.

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

* [Bug c++/103299] [11/12 Regression] accessing incorrect storage for designated init of anonymous union at constexpr context
  2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
  2021-11-17 14:28 ` [Bug c++/103299] [10/11/12 Regression] accessing incorrect storage for designated init of anonymous " ppalka at gcc dot gnu.org
  2021-11-17 14:37 ` [Bug c++/103299] [11/12 " ppalka at gcc dot gnu.org
@ 2021-11-18  7:46 ` rguenth at gcc dot gnu.org
  2021-11-19 17:17 ` ppalka at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-18  7:46 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug c++/103299] [11/12 Regression] accessing incorrect storage for designated init of anonymous union at constexpr context
  2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
                   ` (2 preceding siblings ...)
  2021-11-18  7:46 ` rguenth at gcc dot gnu.org
@ 2021-11-19 17:17 ` ppalka at gcc dot gnu.org
  2022-01-20 17:33 ` ppalka at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-11-19 17:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug c++/103299] [11/12 Regression] accessing incorrect storage for designated init of anonymous union at constexpr context
  2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
                   ` (3 preceding siblings ...)
  2021-11-19 17:17 ` ppalka at gcc dot gnu.org
@ 2022-01-20 17:33 ` ppalka at gcc dot gnu.org
  2022-03-18 19:17 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-20 17:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug c++/103299] [11/12 Regression] accessing incorrect storage for designated init of anonymous union at constexpr context
  2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
                   ` (4 preceding siblings ...)
  2022-01-20 17:33 ` ppalka at gcc dot gnu.org
@ 2022-03-18 19:17 ` jason at gcc dot gnu.org
  2022-03-21 20:47 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2022-03-18 19:17 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

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

* [Bug c++/103299] [11/12 Regression] accessing incorrect storage for designated init of anonymous union at constexpr context
  2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
                   ` (5 preceding siblings ...)
  2022-03-18 19:17 ` jason at gcc dot gnu.org
@ 2022-03-21 20:47 ` cvs-commit at gcc dot gnu.org
  2022-03-21 21:01 ` [Bug c++/103299] [11 " jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-21 20:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:24d51e749570dcb85bd43d3b528f58ad6141de26

commit r12-7741-g24d51e749570dcb85bd43d3b528f58ad6141de26
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Mar 21 09:57:28 2022 -0400

    c++: designated init and aggregate members [PR103337]

    Our C++20 designated initializer handling was broken with members of class
    type; we would find the relevant member and then try to find a member of
    the member with the same name.  Or we would sometimes ignore the designator
    entirely.  The former problem is fixed by the change to reshape_init_class,
    the latter by the change to reshape_init_r.

            PR c++/103337
            PR c++/102740
            PR c++/103299
            PR c++/102538

    gcc/cp/ChangeLog:

            * decl.cc (reshape_init_class): Avoid looking for designator
            after we found it.
            (reshape_init_r): Keep looking for designator.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/flexary3.C: Remove one error.
            * g++.dg/parse/pr43765.C: Likewise.
            * g++.dg/cpp2a/desig22.C: New test.
            * g++.dg/cpp2a/desig23.C: New test.
            * g++.dg/cpp2a/desig24.C: New test.
            * g++.dg/cpp2a/desig25.C: New test.

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

* [Bug c++/103299] [11 Regression] accessing incorrect storage for designated init of anonymous union at constexpr context
  2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
                   ` (6 preceding siblings ...)
  2022-03-21 20:47 ` cvs-commit at gcc dot gnu.org
@ 2022-03-21 21:01 ` jason at gcc dot gnu.org
  2022-03-22  5:18 ` cvs-commit at gcc dot gnu.org
  2022-03-26 23:29 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2022-03-21 21:01 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|12.0                        |
            Summary|[11/12 Regression]          |[11 Regression] accessing
                   |accessing incorrect storage |incorrect storage for
                   |for designated init of      |designated init of
                   |anonymous union at          |anonymous union at
                   |constexpr context           |constexpr context
      Known to work|                            |12.0

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed on trunk so far.

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

* [Bug c++/103299] [11 Regression] accessing incorrect storage for designated init of anonymous union at constexpr context
  2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
                   ` (7 preceding siblings ...)
  2022-03-21 21:01 ` [Bug c++/103299] [11 " jason at gcc dot gnu.org
@ 2022-03-22  5:18 ` cvs-commit at gcc dot gnu.org
  2022-03-26 23:29 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-22  5:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:2b2f575e6f27acc0c7ba6a3affc760bf2b96a84b

commit r11-9678-g2b2f575e6f27acc0c7ba6a3affc760bf2b96a84b
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Mar 21 09:57:28 2022 -0400

    c++: designated init and aggregate members [PR103337]

    Our C++20 designated initializer handling was broken with members of class
    type; we would find the relevant member and then try to find a member of
    the member with the same name.  Or we would sometimes ignore the designator
    entirely.  The former problem is fixed by the change to reshape_init_class,
    the latter by the change to reshape_init_r.

            PR c++/103337
            PR c++/102740
            PR c++/103299
            PR c++/102538

    gcc/cp/ChangeLog:

            * decl.c (reshape_init_class): Avoid looking for designator
            after we found it.
            (reshape_init_r): Keep looking for designator.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/flexary3.C: Remove one error.
            * g++.dg/parse/pr43765.C: Likewise.
            * g++.dg/cpp2a/desig22.C: New test.
            * g++.dg/cpp2a/desig23.C: New test.
            * g++.dg/cpp2a/desig24.C: New test.
            * g++.dg/cpp2a/desig25.C: New test.

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

* [Bug c++/103299] [11 Regression] accessing incorrect storage for designated init of anonymous union at constexpr context
  2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
                   ` (8 preceding siblings ...)
  2022-03-22  5:18 ` cvs-commit at gcc dot gnu.org
@ 2022-03-26 23:29 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2022-03-26 23:29 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 11.3

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

end of thread, other threads:[~2022-03-26 23:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17  9:08 [Bug c++/103299] New: accessing incorrect storage for union at constexpr context unlvsur at live dot com
2021-11-17 14:28 ` [Bug c++/103299] [10/11/12 Regression] accessing incorrect storage for designated init of anonymous " ppalka at gcc dot gnu.org
2021-11-17 14:37 ` [Bug c++/103299] [11/12 " ppalka at gcc dot gnu.org
2021-11-18  7:46 ` rguenth at gcc dot gnu.org
2021-11-19 17:17 ` ppalka at gcc dot gnu.org
2022-01-20 17:33 ` ppalka at gcc dot gnu.org
2022-03-18 19:17 ` jason at gcc dot gnu.org
2022-03-21 20:47 ` cvs-commit at gcc dot gnu.org
2022-03-21 21:01 ` [Bug c++/103299] [11 " jason at gcc dot gnu.org
2022-03-22  5:18 ` cvs-commit at gcc dot gnu.org
2022-03-26 23:29 ` jason 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).