From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4CD03385828C for ; Tue, 27 Sep 2022 19:50:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4CD03385828C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664308239; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZG1RpcglFOnFKhP6G+OabvbyvUWOszZE0ZFMMzXYxjk=; b=grAq6ay3rCHOkIOdxfA8nN47Ky0d2j6gYMgJhz/FcQMA/nWQ/nINz7KGtiXBlUzFwnBDp7 2+Aqg5fi/bWeqDQHKjcDXT2LpSc/I2tXNGwGmoHk0/Q3RldEHIVf29PudSpsYd2+WkAio1 yxG0dlM91w7eBLXB+sQLqbGUgPQacZo= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-30-vD9g-vWONUC4Hgk5lix_1w-1; Tue, 27 Sep 2022 15:50:37 -0400 X-MC-Unique: vD9g-vWONUC4Hgk5lix_1w-1 Received: by mail-qv1-f70.google.com with SMTP id nl18-20020a056214369200b004ac52c4b0a4so6505494qvb.13 for ; Tue, 27 Sep 2022 12:50:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=ZG1RpcglFOnFKhP6G+OabvbyvUWOszZE0ZFMMzXYxjk=; b=oyu9aD/g9OZAhpnWIC8QILDHMgAJ10k7XRwatVA9qYZO+r5HoI8sYLFJ8b4TCP2eOT ppDYAtwMLX+Gj4ZZhgQqXWi6nKGXgTNELoEUU4gmNTlc47GszrpKNbqeG5bn87LyZUFw iOe950WSqdPHRWzeKhejTexgz4N7KF9EN0HFpSoxwV984YcTRGVJHisIdpQGyRjGW5ka RBr6xugqr4Y6a3/Ib+7o0Gt4DttMIP0GIKrAWXv+57AVFvex4sx418+l9WaZ3M+9Hn3L YqhyILpiQ802ULvI8ZVh0c2Zg4OFY8cey+OdPPXfs/6P5yyNedh+bgH10RATR1X2Qi3P dXlQ== X-Gm-Message-State: ACrzQf2Mvr89cfVAk2CGXSnna0E57BKAzuN4P46uj+4ntdKEyzQd2Lzo oJqdjFpXxMOL26q7cAdUAO2TE9Smzs15Txrvv50pVEvQRmeYACJQDael0zZVHvEz1o+MhiJRO3J GYhgEwU/MzpjEkh5mqhgeXctaixiJD27Q7H9NtMaPzTc2teHqrav8j/K0l58xMP0JRHs= X-Received: by 2002:a37:aa13:0:b0:6ce:9be8:fea2 with SMTP id t19-20020a37aa13000000b006ce9be8fea2mr19636999qke.414.1664308236723; Tue, 27 Sep 2022 12:50:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM56K+sj+WSwhghShlYkVuAQVGedqnVqBXUdgfRZNuIKaZ1R8hdJoCrK9whFAlRRr0jxllGibg== X-Received: by 2002:a37:aa13:0:b0:6ce:9be8:fea2 with SMTP id t19-20020a37aa13000000b006ce9be8fea2mr19636976qke.414.1664308236278; Tue, 27 Sep 2022 12:50:36 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id f6-20020ac81346000000b00342f844e30fsm1378920qtj.31.2022.09.27.12.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 12:50:33 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 2/2] c++: implement __remove_cv, __remove_reference and __remove_cvref Date: Tue, 27 Sep 2022 15:50:30 -0400 Message-Id: <20220927195030.2024439-2-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.rc1.2.g4b79ee4b0c In-Reply-To: <20220927195030.2024439-1-ppalka@redhat.com> References: <20220927195030.2024439-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This uses TRAIT_TYPE from the previous patch to implement efficient built-ins for std::remove_cv, std::remove_reference and std::remove_cvref. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Add __remove_cv, __remove_reference and __remove_cvref. * c-common.h (enum rid): Add RID_REMOVE_CV, RID_REMOVE_REFERENCE and RID_REMOVE_CVREF. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Handle CPTK_REMOVE_CV, CPTK_REMOVE_REFERENCE and CPTK_REMOVE_CVREF. * cp-objcp-common.cc (names_builtin_p): Likewise. * cp-tree.h (enum cp_trait_kind): Add CPTK_REMOVE_CV, CPTK_REMOVE_REFERENCE and CPTK_REMOVE_CVREF. * cxx-pretty-print.cc (pp_cxx_trait): Handle CPTK_REMOVE_CV, CPTK_REMOVE_REFERENCE and CPTK_REMOVE_CVREF. * parser.cc (cp_keyword_starts_decl_specifier_p): Return true for RID_REMOVE_CV, RID_REMOVE_REFERENCE and RID_REMOVE_CVREF. (cp_parser_trait): Handle RID_REMOVE_CV, RID_REMOVE_REFERENCE and RID_REMOVE_CVREF. (cp_parser_simple_type_specifier): Likewise. * semantics.cc (finish_trait_type): Likewise. libstdc++-v3/ChangeLog: * include/bits/unique_ptr.h (unique_ptr<_Tp[], _Dp>): Remove __remove_cv and use __remove_cv_t instead. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test __remove_cv, __remove_reference and __remove_cvref. * g++.dg/ext/remove_cv.C: New test. * g++.dg/ext/remove_reference.C: New test. * g++.dg/ext/remove_cvref.C: New test. --- gcc/c-family/c-common.cc | 3 +++ gcc/c-family/c-common.h | 1 + gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-objcp-common.cc | 3 +++ gcc/cp/cp-tree.h | 5 +++- gcc/cp/cxx-pretty-print.cc | 9 +++++++ gcc/cp/parser.cc | 18 ++++++++++++++ gcc/cp/semantics.cc | 10 ++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 9 +++++++ gcc/testsuite/g++.dg/ext/remove_cv.C | 26 +++++++++++++++++++++ gcc/testsuite/g++.dg/ext/remove_cvref.C | 26 +++++++++++++++++++++ gcc/testsuite/g++.dg/ext/remove_reference.C | 26 +++++++++++++++++++++ libstdc++-v3/include/bits/unique_ptr.h | 5 +--- 13 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/remove_cv.C create mode 100644 gcc/testsuite/g++.dg/ext/remove_cvref.C create mode 100644 gcc/testsuite/g++.dg/ext/remove_reference.C diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index cda6910e8c5..6e0af863a49 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -547,6 +547,9 @@ const struct c_common_resword c_common_reswords[] = D_CXXONLY }, { "__reference_converts_from_temporary", RID_REF_CONVERTS_FROM_TEMPORARY, D_CXXONLY }, + { "__remove_cv", RID_REMOVE_CV, D_CXXONLY }, + { "__remove_reference", RID_REMOVE_REFERENCE, D_CXXONLY }, + { "__remove_cvref", RID_REMOVE_CVREF, D_CXXONLY }, /* C++ transactional memory. */ { "synchronized", RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 50a4691cda6..d5c98d306ce 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -187,6 +187,7 @@ enum rid RID_IS_CONVERTIBLE, RID_IS_NOTHROW_CONVERTIBLE, RID_REF_CONSTRUCTS_FROM_TEMPORARY, RID_REF_CONVERTS_FROM_TEMPORARY, + RID_REMOVE_CV, RID_REMOVE_REFERENCE, RID_REMOVE_CVREF, /* C++11 */ RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT, diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 266ec581a20..ca73aff3f38 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_BASES: case CPTK_DIRECT_BASES: case CPTK_UNDERLYING_TYPE: + case CPTK_REMOVE_CV: + case CPTK_REMOVE_REFERENCE: + case CPTK_REMOVE_CVREF: /* We shouldn't see these non-expression traits. */ gcc_unreachable (); /* We deliberately omit the default case so that when adding a new diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 380f288a7f1..2d3f206b530 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -467,6 +467,9 @@ names_builtin_p (const char *name) case RID_IS_NOTHROW_CONVERTIBLE: case RID_REF_CONSTRUCTS_FROM_TEMPORARY: case RID_REF_CONVERTS_FROM_TEMPORARY: + case RID_REMOVE_CV: + case RID_REMOVE_REFERENCE: + case RID_REMOVE_CVREF: return true; default: break; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index c9adf1b3822..5c8f585b821 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1411,7 +1411,10 @@ enum cp_trait_kind CPTK_IS_CONVERTIBLE, CPTK_IS_NOTHROW_CONVERTIBLE, CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, - CPTK_REF_CONVERTS_FROM_TEMPORARY + CPTK_REF_CONVERTS_FROM_TEMPORARY, + CPTK_REMOVE_CV, + CPTK_REMOVE_REFERENCE, + CPTK_REMOVE_CVREF, }; /* The types that we are processing. */ diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc index d484019a539..9ca158f1453 100644 --- a/gcc/cp/cxx-pretty-print.cc +++ b/gcc/cp/cxx-pretty-print.cc @@ -2724,6 +2724,15 @@ pp_cxx_trait (cxx_pretty_printer *pp, tree t) case CPTK_UNDERLYING_TYPE: pp_cxx_ws_string (pp, "__underlying_type"); break; + case CPTK_REMOVE_CV: + pp_cxx_ws_string (pp, "__remove_cv"); + break; + case CPTK_REMOVE_REFERENCE: + pp_cxx_ws_string (pp, "__remove_reference"); + break; + case CPTK_REMOVE_CVREF: + pp_cxx_ws_string (pp, "__remove_cvref"); + break; default: gcc_unreachable (); } diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 9f5e2c292b3..d592d783250 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -1147,6 +1147,9 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) /* C++11 extensions. */ case RID_DECLTYPE: case RID_UNDERLYING_TYPE: + case RID_REMOVE_CV: + case RID_REMOVE_REFERENCE: + case RID_REMOVE_CVREF: case RID_CONSTEXPR: /* C++20 extensions. */ case RID_CONSTINIT: @@ -11027,6 +11030,18 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) kind = CPTK_REF_CONVERTS_FROM_TEMPORARY; binary = true; break; + case RID_REMOVE_CV: + kind = CPTK_REMOVE_CV; + type = true; + break; + case RID_REMOVE_REFERENCE: + kind = CPTK_REMOVE_REFERENCE; + type = true; + break; + case RID_REMOVE_CVREF: + kind = CPTK_REMOVE_CVREF; + type = true; + break; default: gcc_unreachable (); } @@ -19867,6 +19882,9 @@ cp_parser_simple_type_specifier (cp_parser* parser, return type; case RID_UNDERLYING_TYPE: + case RID_REMOVE_CV: + case RID_REMOVE_REFERENCE: + case RID_REMOVE_CVREF: type = cp_parser_trait (parser, token->keyword); if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index ea00805c97d..a73a07d468d 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12236,6 +12236,16 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2) { case CPTK_UNDERLYING_TYPE: return finish_underlying_type (type1); + case CPTK_REMOVE_CV: + return cv_unqualified (type1); + case CPTK_REMOVE_REFERENCE: + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_CVREF: + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + return cv_unqualified (type1); default: gcc_unreachable (); } diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 17dabf648cf..f343e153e56 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -137,3 +137,12 @@ #if !__has_builtin (__is_nothrow_convertible) # error "__has_builtin (__is_nothrow_convertible) failed" #endif +#if !__has_builtin (__remove_cv) +# error "__has_builtin (__remove_cv) failed" +#endif +#if !__has_builtin (__remove_reference) +# error "__has_builtin (__remove_reference) failed" +#endif +#if !__has_builtin (__remove_cvref) +# error "__has_builtin (__remove_cvref) failed" +#endif diff --git a/gcc/testsuite/g++.dg/ext/remove_cv.C b/gcc/testsuite/g++.dg/ext/remove_cv.C new file mode 100644 index 00000000000..941aa9e4c11 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_cv.C @@ -0,0 +1,26 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_cv(void), void)); +SA(__is_same(__remove_cv(int*), int*)); + +SA(__is_same(__remove_cv(int&), int&)); +SA(__is_same(__remove_cv(const int&), const int&)); +SA(__is_same(__remove_cv(volatile int&), volatile int&)); +SA(__is_same(__remove_cv(const volatile int&), const volatile int&)); + +SA(__is_same(__remove_cv(int&&), int&&)); +SA(__is_same(__remove_cv(const int&&), const int&&)); +SA(__is_same(__remove_cv(volatile int&&), volatile int&&)); +SA(__is_same(__remove_cv(const volatile int&&), const volatile int&&)); + +SA(__is_same(__remove_cv(int[3]), int[3])); +SA(__is_same(__remove_cv(const int[3]), int[3])); +SA(__is_same(__remove_cv(volatile int[3]), int[3])); +SA(__is_same(__remove_cv(const volatile int[3]), int[3])); + +SA(__is_same(__remove_cv(int(int)), int(int))); +SA(__is_same(__remove_cv(int(*const)(int)), int(*)(int))); +SA(__is_same(__remove_cv(int(*volatile)(int)), int(*)(int))); +SA(__is_same(__remove_cv(int(*const volatile)(int)), int(*)(int))); diff --git a/gcc/testsuite/g++.dg/ext/remove_cvref.C b/gcc/testsuite/g++.dg/ext/remove_cvref.C new file mode 100644 index 00000000000..22725c08f63 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_cvref.C @@ -0,0 +1,26 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_cvref(void), void)); +SA(__is_same(__remove_cvref(int*), int*)); + +SA(__is_same(__remove_cvref(int&), int)); +SA(__is_same(__remove_cvref(const int&), int)); +SA(__is_same(__remove_cvref(volatile int&), int)); +SA(__is_same(__remove_cvref(const volatile int&), int)); + +SA(__is_same(__remove_cvref(int&&), int)); +SA(__is_same(__remove_cvref(const int&&), int)); +SA(__is_same(__remove_cvref(volatile int&&), int)); +SA(__is_same(__remove_cvref(const volatile int&&), int)); + +SA(__is_same(__remove_cvref(int[3]), int[3])); +SA(__is_same(__remove_cvref(const int[3]), int[3])); +SA(__is_same(__remove_cvref(volatile int[3]), int[3])); +SA(__is_same(__remove_cvref(const volatile int[3]), int[3])); + +SA(__is_same(__remove_cvref(int(int)), int(int))); +SA(__is_same(__remove_cvref(int(*const)(int)), int(*)(int))); +SA(__is_same(__remove_cvref(int(*volatile)(int)), int(*)(int))); +SA(__is_same(__remove_cvref(int(*const volatile)(int)), int(*)(int))); diff --git a/gcc/testsuite/g++.dg/ext/remove_reference.C b/gcc/testsuite/g++.dg/ext/remove_reference.C new file mode 100644 index 00000000000..af3c354b670 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_reference.C @@ -0,0 +1,26 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_reference(void), void)); +SA(__is_same(__remove_reference(int*), int*)); + +SA(__is_same(__remove_reference(int&), int)); +SA(__is_same(__remove_reference(const int&), const int)); +SA(__is_same(__remove_reference(volatile int&), volatile int)); +SA(__is_same(__remove_reference(const volatile int&), const volatile int)); + +SA(__is_same(__remove_reference(int&&), int)); +SA(__is_same(__remove_reference(const int&&), const int)); +SA(__is_same(__remove_reference(volatile int&&), volatile int)); +SA(__is_same(__remove_reference(const volatile int&&), const volatile int)); + +SA(__is_same(__remove_reference(int[3]), int[3])); +SA(__is_same(__remove_reference(const int[3]), const int[3])); +SA(__is_same(__remove_reference(volatile int[3]), volatile int[3])); +SA(__is_same(__remove_reference(const volatile int[3]), const volatile int[3])); + +SA(__is_same(__remove_reference(int(int)), int(int))); +SA(__is_same(__remove_reference(int(*const)(int)), int(*const)(int))); +SA(__is_same(__remove_reference(int(*volatile)(int)), int(*volatile)(int))); +SA(__is_same(__remove_reference(int(*const volatile)(int)), int(*const volatile)(int))); diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 1086f408374..34c3a766179 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -541,14 +541,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __uniq_ptr_data<_Tp, _Dp> _M_t; - template - using __remove_cv = typename remove_cv<_Up>::type; - // like is_base_of<_Tp, _Up> but false if unqualified types are the same template using __is_derived_Tp = __and_< is_base_of<_Tp, _Up>, - __not_, __remove_cv<_Up>>> >; + __not_, __remove_cv_t<_Up>>> >; public: using pointer = typename __uniq_ptr_impl<_Tp, _Dp>::pointer; -- 2.38.0.rc1.2.g4b79ee4b0c