From patchwork Mon Nov 14 10:40:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 19669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2074340wru; Mon, 14 Nov 2022 02:41:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf6G0H9CJ1+v0smKJKq0lChYSgJyKV2g8dZZHGda2KYe0qGDRhBXTy+bUF3ULtubMWoufPDB X-Received: by 2002:a17:906:4e0b:b0:7ad:7d4a:ec2c with SMTP id z11-20020a1709064e0b00b007ad7d4aec2cmr9589570eju.710.1668422505676; Mon, 14 Nov 2022 02:41:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668422505; cv=none; d=google.com; s=arc-20160816; b=sZ2iMSYS19CgjRAlW7cYl9t9qe8TuMWrxMC3fShCMfFvre1M3ttjAA7TzvJ/FGbvIt 4sM6IW4tIy5exxyLvBGoUyBmieofeqNbYQd+aa4yP+niXkFdzAqWoOYcqgtYkPuwv3Tm q22y3eOKf1mpWYtvbYexbudUv2yO4t1/VbwP1os4nbdnJzTdkYgI6tODjtocOetxxs/L 8eWnKKxGhRVzL5guspvFiw9IujUiZGPpsyrOlYIwkIP4bPHLGXuTiNjl+6YlNSFtub2m hv6RWid4aZo0RNVL3lZUhD48P/s9PWqBL6y9qdyz+6t4SOA9p3B6g0R9Ban/HN+NiDeu 1Fpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=UfhzUbIkIVFx4E+T0eemWOcHaxQq9C2JT8mdAyAwSww=; b=0AOs0P/RihtZ9AmXRY2EempwKO3OOOPjCZVcbUduBacQtplb2LG3jif1Xmq8RHgYcn WkTwXnPwNFvvOeQ59XwQb8shePKYEQo4ndBgl/iP73q11zz4aQBwyAdJx4lvjUWLDbBH rf+jnQiBadKdGnhVvQ9Ieug7M2IyCJLaYfXy0caQpHgq3a/Pz9K/K66cdebR2fAAgALH NAt/l8xjHkLw+e9WvcN/bYUGxfhYtOSrnEpwJ7I9kkuO7DW7o4GoOrFIqFF/GfN6l14S vxWo1Jbb79UDp0xCBUmSvyN3CzLq8YeO4SRd2xJ8FgkpVlTq77cmainUkfRHiUdaFLfv 7bdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IleCRJi9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gn6-20020a1709070d0600b00791bcf8aa5esi8097127ejc.739.2022.11.14.02.41.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 02:41:45 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IleCRJi9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FD42385843E for ; Mon, 14 Nov 2022 10:41:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FD42385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668422504; bh=UfhzUbIkIVFx4E+T0eemWOcHaxQq9C2JT8mdAyAwSww=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=IleCRJi9cikVmp5udIigU1TNOMRaHH9qjFRJkE25/aUpJRm5d/ghZ0iHfmWfY7C1S UImQ1RSPtnKqtS1XJ1NIvCV1vVSrwhTmJ/H/QpFtAWyp+4Q8xFkQypldcz6BeRpaV3 RIMvU10RJpPfscdzsJb7pTB8FxZlQ4hLcnAhTKQU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 9B533385842C for ; Mon, 14 Nov 2022 10:41:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B533385842C Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-553-xMhAGlIaMxyNSa4u0UpqiQ-1; Mon, 14 Nov 2022 05:40:59 -0500 X-MC-Unique: xMhAGlIaMxyNSa4u0UpqiQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DDF1886461 for ; Mon, 14 Nov 2022 10:40:58 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CCEF422A9; Mon, 14 Nov 2022 10:40:58 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2AEAerxX2837922 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 14 Nov 2022 11:40:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2AEAerig2837921; Sun, 13 Nov 2022 22:40:53 -1200 Date: Sun, 13 Nov 2022 22:40:53 -1200 To: Jason Merrill , Patrick Palka , Jonathan Wakely Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Allow attributes on concepts - DR 2428 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749467797229092627?= X-GMAIL-MSGID: =?utf-8?q?1749467797229092627?= Hi! Working virtually out of Baker Island. The following patch adds parsing of attributes to concept definition, allows deprecated attribute to be specified (some ugliness needed because CONCEPT_DECL is a cp/*.def attribute and so can't be mentioned in c-family/ directly; used what is used for objc method decls, an alternative would be a langhook) and checks TREE_DEPRECATED in build_standard_check (not sure if that is the right spot, or whether it shouldn't be checked also for variable and function concepts and how to write testcase coverage for that). Lightly tested so far. 2022-11-13 Jakub Jelinek gcc/c-family/ * c-common.h (c_concept_decl): Declare. * c-attribs.cc (handle_deprecated_attribute): Allow deprecated attribute on CONCEPT_DECL if flag_concepts. gcc/c/ * c-decl.cc (c_concept_decl): New function. gcc/cp/ * cp-tree.h (finish_concept_definition): Add ATTRS parameter. * parser.cc (cp_parser_concept_definition): Parse attributes in between identifier and =. Adjust finish_concept_definition caller. * pt.cc (finish_concept_definition): Add ATTRS parameter. Call cplus_decl_attributes. * constraint.cc (build_standard_check): If CONCEPT_DECL is TREE_DEPRECATED, emit -Wdeprecated-declaration warnings. * tree.cc (c_concept_decl): New function. gcc/testsuite/ * g++.dg/cpp2a/concepts-dr2428.C: New test. Jakub --- gcc/c-family/c-common.h.jj 2022-10-27 21:00:53.698247586 -1200 +++ gcc/c-family/c-common.h 2022-11-13 21:49:37.934598359 -1200 @@ -831,6 +831,7 @@ extern tree (*make_fname_decl) (location /* In c-decl.cc and cp/tree.cc. FIXME. */ extern void c_register_addr_space (const char *str, addr_space_t as); +extern bool c_concept_decl (enum tree_code); /* In c-common.cc. */ extern bool in_late_binary_op; --- gcc/c-family/c-attribs.cc.jj 2022-10-09 19:31:57.177988375 -1200 +++ gcc/c-family/c-attribs.cc 2022-11-13 21:52:37.920152731 -1200 @@ -4211,7 +4211,8 @@ handle_deprecated_attribute (tree *node, || VAR_OR_FUNCTION_DECL_P (decl) || TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == CONST_DECL - || objc_method_decl (TREE_CODE (decl))) + || objc_method_decl (TREE_CODE (decl)) + || (flag_concepts && c_concept_decl (TREE_CODE (decl)))) TREE_DEPRECATED (decl) = 1; else if (TREE_CODE (decl) == LABEL_DECL) { --- gcc/c/c-decl.cc.jj 2022-11-12 23:29:08.181504470 -1200 +++ gcc/c/c-decl.cc 2022-11-13 21:50:38.178779716 -1200 @@ -12987,6 +12987,14 @@ c_register_addr_space (const char *word, ridpointers [rid] = id; } +/* C doesn't have CONCEPT_DECL. */ + +bool +c_concept_decl (enum tree_code) +{ + return false; +} + /* Return identifier to look up for omp declare reduction. */ tree --- gcc/cp/cp-tree.h.jj 2022-11-11 20:30:10.138056914 -1200 +++ gcc/cp/cp-tree.h 2022-11-13 20:58:39.443218815 -1200 @@ -8324,7 +8324,7 @@ struct diagnosing_failed_constraint extern cp_expr finish_constraint_or_expr (location_t, cp_expr, cp_expr); extern cp_expr finish_constraint_and_expr (location_t, cp_expr, cp_expr); extern cp_expr finish_constraint_primary_expr (cp_expr); -extern tree finish_concept_definition (cp_expr, tree); +extern tree finish_concept_definition (cp_expr, tree, tree); extern tree combine_constraint_expressions (tree, tree); extern tree append_constraint (tree, tree); extern tree get_constraints (const_tree); --- gcc/cp/parser.cc.jj 2022-11-08 22:39:13.325041007 -1200 +++ gcc/cp/parser.cc 2022-11-13 20:58:15.692542640 -1200 @@ -29672,6 +29672,8 @@ cp_parser_concept_definition (cp_parser return NULL_TREE; } + tree attrs = cp_parser_attributes_opt (parser); + if (!cp_parser_require (parser, CPP_EQ, RT_EQ)) { cp_parser_skip_to_end_of_statement (parser); @@ -29688,7 +29690,7 @@ cp_parser_concept_definition (cp_parser but continue as if it were. */ cp_parser_consume_semicolon_at_end_of_statement (parser); - return finish_concept_definition (id, init); + return finish_concept_definition (id, init, attrs); } // -------------------------------------------------------------------------- // --- gcc/cp/pt.cc.jj 2022-11-07 20:54:37.341399829 -1200 +++ gcc/cp/pt.cc 2022-11-13 21:01:18.333053377 -1200 @@ -29027,7 +29027,7 @@ placeholder_type_constraint_dependent_p the TEMPLATE_DECL. */ tree -finish_concept_definition (cp_expr id, tree init) +finish_concept_definition (cp_expr id, tree init, tree attrs) { gcc_assert (identifier_p (id)); gcc_assert (processing_template_decl); @@ -29061,6 +29061,9 @@ finish_concept_definition (cp_expr id, t DECL_CONTEXT (decl) = current_scope (); DECL_INITIAL (decl) = init; + if (attrs) + cplus_decl_attributes (&decl, attrs, 0); + set_originating_module (decl, false); /* Push the enclosing template. */ --- gcc/cp/constraint.cc.jj 2022-11-04 05:11:41.491946435 -1200 +++ gcc/cp/constraint.cc 2022-11-13 22:24:55.314809969 -1200 @@ -1396,6 +1396,8 @@ build_standard_check (tree tmpl, tree ar { gcc_assert (standard_concept_p (tmpl)); gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL); + if (TREE_DEPRECATED (DECL_TEMPLATE_RESULT (tmpl))) + warn_deprecated_use (DECL_TEMPLATE_RESULT (tmpl), NULL_TREE); tree parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (tmpl)); args = coerce_template_parms (parms, args, tmpl, complain); if (args == error_mark_node) --- gcc/cp/tree.cc.jj 2022-11-08 22:39:13.318041103 -1200 +++ gcc/cp/tree.cc 2022-11-13 21:51:21.851186254 -1200 @@ -6103,6 +6103,14 @@ c_register_addr_space (const char * /*wo { } +/* Return true if CODE is CONCEPT_DECL. */ + +bool +c_concept_decl (enum tree_code code) +{ + return code == CONCEPT_DECL; +} + /* Return the number of operands in T that we care about for things like mangling. */ --- gcc/testsuite/g++.dg/cpp2a/concepts-dr2428.C.jj 2022-11-13 22:27:56.977337907 -1200 +++ gcc/testsuite/g++.dg/cpp2a/concepts-dr2428.C 2022-11-13 22:28:07.767191065 -1200 @@ -0,0 +1,22 @@ +// DR 2428 +// { dg-do compile { target c++20 } } + +template +concept C1 [[deprecated]] = true; + +template +concept C2 __attribute__((deprecated)) = false; + +template +concept C3 [[deprecated]] = true; + +template +concept C4 __attribute__((deprecated)) = false; + +static_assert(C3); // { dg-warning "'C3' is deprecated" } +static_assert(C4); // { dg-error "static assertion failed" } + // { dg-warning "'C4' is deprecated" "" { target *-*-* } .-1 } + +template + requires C3 // { dg-warning "'C3' is deprecated" } +int fn1(T t) { return 0; }