public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/106784] Add __is_convertible built-in
Date: Fri, 23 Sep 2022 16:17:00 +0000	[thread overview]
Message-ID: <bug-106784-4-p8uk481xxD@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106784-4@http.gcc.gnu.org/bugzilla/>

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

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

https://gcc.gnu.org/g:8a7bcf95a82c3dd68bd4bcfbd8432eb970575bc2

commit r13-2822-g8a7bcf95a82c3dd68bd4bcfbd8432eb970575bc2
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Sep 20 15:48:52 2022 -0400

    c++: Implement __is_{nothrow_,}convertible [PR106784]

    To improve compile times, the C++ library could use compiler built-ins
    rather than implementing std::is_convertible (and _nothrow) as class
    templates.  This patch adds the built-ins.  We already have
    __is_constructible and __is_assignable, and the nothrow forms of those.

    Microsoft (and clang, for compatibility) also provide an alias called
    __is_convertible_to.  I did not add it, but it would be trivial to do
    so.

    I noticed that our __is_assignable doesn't implement the "Access checks
    are performed as if from a context unrelated to either type" requirement,
    therefore std::is_assignable / __is_assignable give two different results
    here:

      class S {
        operator int();
        friend void g(); // #1
      };

      void
      g ()
      {
        // #1 doesn't matter
        static_assert(std::is_assignable<int&, S>::value, "");
        static_assert(__is_assignable(int&, S), "");
      }

    This is not a problem if __is_assignable is not meant to be used by
    the users.

    This patch doesn't make libstdc++ use the new built-ins, but I had to
    rename a class otherwise its name would clash with the new built-in.

            PR c++/106784

    gcc/c-family/ChangeLog:

            * c-common.cc (c_common_reswords): Add __is_convertible and
            __is_nothrow_convertible.
            * c-common.h (enum rid): Add RID_IS_CONVERTIBLE and
            RID_IS_NOTHROW_CONVERTIBLE.

    gcc/cp/ChangeLog:

            * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_CONVERTIBLE
            and CPTK_IS_NOTHROW_CONVERTIBLE.
            * cp-objcp-common.cc (names_builtin_p): Handle RID_IS_CONVERTIBLE
            RID_IS_NOTHROW_CONVERTIBLE.
            * cp-tree.h (enum cp_trait_kind): Add CPTK_IS_CONVERTIBLE and
            CPTK_IS_NOTHROW_CONVERTIBLE.
            (is_convertible): Declare.
            (is_nothrow_convertible): Likewise.
            * cxx-pretty-print.cc (pp_cxx_trait_expression): Handle
            CPTK_IS_CONVERTIBLE and CPTK_IS_NOTHROW_CONVERTIBLE.
            * method.cc (is_convertible): New.
            (is_nothrow_convertible): Likewise.
            * parser.cc (cp_parser_primary_expression): Handle
RID_IS_CONVERTIBLE
            and RID_IS_NOTHROW_CONVERTIBLE.
            (cp_parser_trait_expr): Likewise.
            * semantics.cc (trait_expr_value): Handle CPTK_IS_CONVERTIBLE and
            CPTK_IS_NOTHROW_CONVERTIBLE.
            (finish_trait_expr): Likewise.

    libstdc++-v3/ChangeLog:

            * include/std/type_traits: Rename __is_nothrow_convertible to
            __is_nothrow_convertible_lib.
            * testsuite/20_util/is_nothrow_convertible/value_ext.cc: Likewise.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/has-builtin-1.C: Enhance to test __is_convertible and
            __is_nothrow_convertible.
            * g++.dg/ext/is_convertible1.C: New test.
            * g++.dg/ext/is_convertible2.C: New test.
            * g++.dg/ext/is_nothrow_convertible1.C: New test.
            * g++.dg/ext/is_nothrow_convertible2.C: New test.

  parent reply	other threads:[~2022-09-23 16:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 10:41 [Bug c++/106784] New: " redi at gcc dot gnu.org
2022-08-31 13:38 ` [Bug c++/106784] " mpolacek at gcc dot gnu.org
2022-08-31 14:05 ` mpolacek at gcc dot gnu.org
2022-09-01 16:26 ` redi at gcc dot gnu.org
2022-09-20 21:24 ` mpolacek at gcc dot gnu.org
2022-09-21  0:02 ` redi at gcc dot gnu.org
2022-09-23 16:17 ` cvs-commit at gcc dot gnu.org [this message]
2022-09-23 16:18 ` mpolacek at gcc dot gnu.org
2022-09-24 14:10 ` redi at gcc dot gnu.org
2022-09-26 16:42 ` cvs-commit at gcc dot gnu.org
2023-04-29 17:44 ` pinskia 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-106784-4-p8uk481xxD@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).