public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "de34 at live dot cn" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/102535] New: __is_trivially_constructible rejects some trivial cases in aggregate initializations
Date: Thu, 30 Sep 2021 02:45:01 +0000	[thread overview]
Message-ID: <bug-102535-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 102535
           Summary: __is_trivially_constructible rejects some trivial
                    cases in aggregate initializations
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: de34 at live dot cn
  Target Milestone: ---

It seems that gcc's __is_trivially_constructible (the underlying mechanism of
std::is_trivially_constructible in libstdc++) gives inconsistent answers to
whether aggregate initializations performed by direct-non-list-initializations
(available since C++20) affect triviality of operations.

#include <type_traits>
#include <iostream>

struct A { int x; };
struct B { float y; };
struct C { A a; B b; };

int main()
{
#if __cpp_aggregate_paren_init >= 201902L 
    std::cout
        << std::is_constructible_v<C, A> << '\n'               // 1
        << std::is_constructible_v<C, A, B> << '\n'            // 1
        << !std::is_constructible_v<C, B> << '\n'              // 1
        << std::is_trivially_constructible_v<C, A> << '\n'     // 1
        << std::is_trivially_constructible_v<C, A, B> << '\n'; // 0, seems
buggy
#endif
}

According to the definitions, initialization of a C variable from A or A and B
(both treated as xvalues according to [meta.unary.prop]/8) only calls trivial
move constructors. It seems unreasonable that
std::is_trivially_constructible_v<C, A> is true but
std::is_trivially_constructible_v<C, A, B> is false, they should be both true
in C++20.

This bug has been existing since gcc 10.1.0, and is not fixed in 12.0.0
20210721:
https://wandbox.org/permlink/L0ZLipQZLsCOqYcT
https://wandbox.org/permlink/lBwowJpeFshRC03z

             reply	other threads:[~2021-09-30  2:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30  2:45 de34 at live dot cn [this message]
2021-09-30 14:59 ` [Bug c++/102535] " ppalka at gcc dot gnu.org
2021-09-30 21:51 ` cvs-commit at gcc dot gnu.org
2021-10-05  8:36 ` cvs-commit at gcc dot gnu.org
2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
2021-10-12 11:00 ` cvs-commit at gcc dot gnu.org
2021-10-12 13:33 ` ppalka at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102535-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).