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

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