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++/100157] Support `__type_pack_element` like Clang
Date: Wed, 19 Apr 2023 19:37:11 +0000	[thread overview]
Message-ID: <bug-100157-4-dZpzv8eUQL@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-100157-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #12 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:58b7dbf865b146a4e65dbda9be6df78f212c03b6

commit r14-92-g58b7dbf865b146a4e65dbda9be6df78f212c03b6
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Apr 19 15:36:34 2023 -0400

    c++: Define built-in for std::tuple_element [PR100157]

    This adds a new built-in to replace the recursive class template
    instantiations done by traits such as std::tuple_element and
    std::variant_alternative.  The purpose is to select the Nth type from a
    list of types, e.g. __type_pack_element<1, char, int, float> is int.
    We implement it as a special kind of TRAIT_TYPE.

    For a pathological example tuple_element_t<1000, tuple<2000 types...>>
    the compilation time is reduced by more than 90% and the memory used by
    the compiler is reduced by 97%.  In realistic examples the gains will be
    much smaller, but still relevant.

    Unlike the other built-in traits, __type_pack_element uses template-id
    syntax instead of call syntax and is SFINAE-enabled, matching Clang's
    implementation.  And like the other built-in traits, it's not mangleable
    so we can't use it directly in function signatures.

    N.B. Clang seems to implement __type_pack_element as a first-class
    template that can e.g. be used as a template-template argument.  For
    simplicity we implement it in a more ad-hoc way.

    Co-authored-by: Jonathan Wakely <jwakely@redhat.com>

            PR c++/100157

    gcc/cp/ChangeLog:

            * cp-trait.def (TYPE_PACK_ELEMENT): Define.
            * cp-tree.h (finish_trait_type): Add complain parameter.
            * cxx-pretty-print.cc (pp_cxx_trait): Handle
            CPTK_TYPE_PACK_ELEMENT.
            * parser.cc (cp_parser_constant_expression): Document default
            arguments.
            (cp_parser_trait): Handle CPTK_TYPE_PACK_ELEMENT.  Pass
            tf_warning_or_error to finish_trait_type.
            * pt.cc (tsubst) <case TRAIT_TYPE>: Handle non-type first
            argument.  Pass complain to finish_trait_type.
            * semantics.cc (finish_type_pack_element): Define.
            (finish_trait_type): Add complain parameter.  Handle
            CPTK_TYPE_PACK_ELEMENT.
            * tree.cc (strip_typedefs): Handle non-type first argument.
            Pass tf_warning_or_error to finish_trait_type.
            * typeck.cc (structural_comptypes) <case TRAIT_TYPE>: Use
            cp_tree_equal instead of same_type_p for the first argument.

    libstdc++-v3/ChangeLog:

            * include/bits/utility.h (_Nth_type): Conditionally define in
            terms of __type_pack_element if available.
            * testsuite/20_util/tuple/element_access/get_neg.cc: Prune
            additional errors from the new built-in.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/type_pack_element1.C: New test.
            * g++.dg/ext/type_pack_element2.C: New test.
            * g++.dg/ext/type_pack_element3.C: New test.

  parent reply	other threads:[~2023-04-19 19:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-20 17:44 [Bug c++/100157] New: " vittorio.romeo at outlook dot com
2021-04-21  6:21 ` [Bug c++/100157] " rguenth at gcc dot gnu.org
2022-06-29 23:27 ` redi at gcc dot gnu.org
2022-06-29 23:33 ` redi at gcc dot gnu.org
2022-06-29 23:38 ` redi at gcc dot gnu.org
2022-06-30 10:39 ` m.cencora at gmail dot com
2022-06-30 11:11 ` redi at gcc dot gnu.org
2022-06-30 11:19 ` redi at gcc dot gnu.org
2022-06-30 11:44 ` m.cencora at gmail dot com
2022-06-30 12:46 ` vittorio.romeo at outlook dot com
2022-06-30 13:05 ` redi at gcc dot gnu.org
2022-06-30 13:08 ` redi at gcc dot gnu.org
2022-06-30 13:09 ` vittorio.romeo at outlook dot com
2022-06-30 13:14 ` redi at gcc dot gnu.org
2022-11-29 15:28 ` pdimov at gmail dot com
2023-04-19 19:37 ` cvs-commit at gcc dot gnu.org [this message]
2023-04-26  6:55 ` rguenth at gcc dot gnu.org
2023-04-26  8:08 ` redi 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-100157-4-dZpzv8eUQL@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).