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 A0D37393BA74 for ; Tue, 15 Nov 2022 21:51:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0D37393BA74 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=1668549115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i7SuOfzJtMxDjH7RhqEn+x8mq7TnBWYATvYH1vi+co0=; b=dHOrH5ZETkyMVm9FACBtxTKdkpQaI9IbLZ8YZmcI4dxnn2iMsmhM17DdG8jaW1xjr0Dqct Mv8OWm4Yyh6k+rTYJLnD/i/hNX6pxvR1DtmxNs4Tm7pVIRdMR3rFdTCCLdA4CFry682XQy bn7fBrumVqHcyghO+G7A5KqeyyYv664= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-154-dNm2BygpO5qxevdOGSAXFg-1; Tue, 15 Nov 2022 16:51:54 -0500 X-MC-Unique: dNm2BygpO5qxevdOGSAXFg-1 Received: by mail-qv1-f72.google.com with SMTP id lb11-20020a056214318b00b004c63b9f91e5so5102725qvb.8 for ; Tue, 15 Nov 2022 13:51:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=i7SuOfzJtMxDjH7RhqEn+x8mq7TnBWYATvYH1vi+co0=; b=msPCjZZxwa7TzyaDjL8nOsAXK5UoUp24Iw1tQzFUZ5UfgvWXf+IsQbPCMHgV5IvBKR J3RtPoyXZ1NzQ7S8rXZqgNN1RzJLCEOD++bd9VXuhm3RXnxgd/UVedFcSZY7H0VZ2b/H 6/6Q3IxylV9KGN7V0t8Sex8XPJW3wU7/DS+Gs1XMG+WwzMyhin6LxE3SXTCPnln2NmOb 1EHUWbCl6zmcNCnC+PwxDYYjnDCOxpKt2b4T57bNomM3cMBuAq+/+IzyKRnRJ5Ds00+o kLPQH0rJtmJDv0GUCAKBTl40ilWJKFOr8BH4VzTT2YQkU63sRkjqkmmojmGEm/mjT9KU cF4w== X-Gm-Message-State: ANoB5pk/55bMMVCbxK42zhIK2fuFZJLaLXQR2NlH1Sa7BEN9M394o+bc R/RwvMzFVD0R8E3A8YCtVucaWDWfCMSYNPRJLalLuB2WNVcJ32eIe5AccQ1nSVolvRX/ePi3y63 niJkiwWgBvpgngrKjPg== X-Received: by 2002:ac8:7211:0:b0:3a5:c86a:aa46 with SMTP id a17-20020ac87211000000b003a5c86aaa46mr18623041qtp.534.1668549113573; Tue, 15 Nov 2022 13:51:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf5IuW2NsEGUj4x8Bc7XI3gK68GLbFbcdcAIUqr055F7C+PeYFnEud3N7dtR5mMUaFRzonNzqg== X-Received: by 2002:ac8:7211:0:b0:3a5:c86a:aa46 with SMTP id a17-20020ac87211000000b003a5c86aaa46mr18623009qtp.534.1668549113027; Tue, 15 Nov 2022 13:51:53 -0800 (PST) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id w8-20020ae9e508000000b006b953a7929csm8721148qkf.73.2022.11.15.13.51.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Nov 2022 13:51:52 -0800 (PST) Message-ID: <5a23209a-6eeb-17a2-0e50-5c57c348ec2f@redhat.com> Date: Tue, 15 Nov 2022 16:51:50 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH] c++, v2: Allow attributes on concepts - DR 2428 To: Jakub Jelinek , Patrick Palka , Jonathan Wakely , gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_NUMSUBJECT,NICE_REPLY_A,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 List-Id: On 11/14/22 22:54, Jakub Jelinek wrote: > On Tue, Nov 15, 2022 at 09:54:00AM +0100, Jakub Jelinek via Gcc-patches wrote: >> On Mon, Nov 14, 2022 at 07:00:54PM -0500, Jason Merrill wrote: >>>> 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) >>> >>> Several of the codes in c-common.def are C++-only, you might just move it >>> over? >>> >>>> 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). >>> >>> I wouldn't bother with var/fn concepts, they're obsolete. >> >> Ok, so like this? >> The previous version passed bootstrap/regtest on x86_64-linux and i686-linux, >> I'll of course test this one as well. > > Better with a patch. Sorry. OK. > 2022-11-15 Jakub Jelinek > > gcc/c-family/ > * c-common.def (CONCEPT_DECL): New tree, moved here from > cp-tree.def. > * c-common.cc (c_common_init_ts): Handle CONCEPT_DECL. > * c-attribs.cc (handle_deprecated_attribute): Allow deprecated > attribute on CONCEPT_DECL. > gcc/cp/ > * cp-tree.def (CONCEPT_DECL): Move to c-common.def. > * cp-objcp-common.cc (cp_common_init_ts): Don't handle CONCEPT_DECL > here. > * 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. > gcc/testsuite/ > * g++.dg/cpp2a/concepts-dr2428.C: New test. > > --- gcc/c-family/c-common.def.jj 2022-10-14 09:28:27.975164491 +0200 > +++ gcc/c-family/c-common.def 2022-11-15 09:34:01.384591076 +0100 > @@ -81,6 +81,14 @@ DEFTREECODE (CONTINUE_STMT, "continue_st > SWITCH_STMT_SCOPE, respectively. */ > DEFTREECODE (SWITCH_STMT, "switch_stmt", tcc_statement, 4) > > +/* Extensions for C++ Concepts. */ > + > +/* Concept definition. This is not entirely different than a VAR_DECL > + except that a) it must be a template, and b) doesn't have the wide > + range of value and linkage options available to variables. Used > + by C++ FE and in c-family attribute handling. */ > +DEFTREECODE (CONCEPT_DECL, "concept_decl", tcc_declaration, 0) > + > /* > Local variables: > mode:c > --- gcc/c-family/c-common.cc.jj 2022-11-13 12:29:08.165504692 +0100 > +++ gcc/c-family/c-common.cc 2022-11-15 09:34:48.828950083 +0100 > @@ -8497,6 +8497,8 @@ c_common_init_ts (void) > MARK_TS_EXP (FOR_STMT); > MARK_TS_EXP (SWITCH_STMT); > MARK_TS_EXP (WHILE_STMT); > + > + MARK_TS_DECL_COMMON (CONCEPT_DECL); > } > > /* Build a user-defined numeric literal out of an integer constant type VALUE > --- gcc/c-family/c-attribs.cc.jj 2022-11-14 13:35:34.184160348 +0100 > +++ gcc/c-family/c-attribs.cc 2022-11-15 09:30:57.370081060 +0100 > @@ -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)) > + || TREE_CODE (decl) == CONCEPT_DECL) > TREE_DEPRECATED (decl) = 1; > else if (TREE_CODE (decl) == LABEL_DECL) > { > --- gcc/cp/cp-tree.def.jj 2022-09-29 18:11:34.836666800 +0200 > +++ gcc/cp/cp-tree.def 2022-11-15 09:32:17.456996090 +0100 > @@ -495,11 +495,6 @@ DEFTREECODE (OMP_DEPOBJ, "omp_depobj", t > > /* Extensions for Concepts. */ > > -/* Concept definition. This is not entirely different than a VAR_DECL > - except that a) it must be a template, and b) doesn't have the wide > - range of value and linkage options available to variables. */ > -DEFTREECODE (CONCEPT_DECL, "concept_decl", tcc_declaration, 0) > - > /* Used to represent information associated with constrained declarations. */ > DEFTREECODE (CONSTRAINT_INFO, "constraint_info", tcc_exceptional, 0) > > --- gcc/cp/cp-objcp-common.cc.jj 2022-09-30 18:38:55.349607203 +0200 > +++ gcc/cp/cp-objcp-common.cc 2022-11-15 09:34:21.963313049 +0100 > @@ -473,7 +473,6 @@ cp_common_init_ts (void) > /* New decls. */ > MARK_TS_DECL_COMMON (TEMPLATE_DECL); > MARK_TS_DECL_COMMON (WILDCARD_DECL); > - MARK_TS_DECL_COMMON (CONCEPT_DECL); > > MARK_TS_DECL_NON_COMMON (USING_DECL); > > --- gcc/cp/cp-tree.h.jj 2022-11-15 08:17:07.561388452 +0100 > +++ gcc/cp/cp-tree.h 2022-11-15 09:30:57.371081046 +0100 > @@ -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-14 13:35:34.380157682 +0100 > +++ gcc/cp/parser.cc 2022-11-15 09:30:57.377080965 +0100 > @@ -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/constraint.cc.jj 2022-11-14 13:35:34.269159192 +0100 > +++ gcc/cp/constraint.cc 2022-11-15 09:30:57.382080897 +0100 > @@ -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/pt.cc.jj 2022-11-15 07:56:05.130350281 +0100 > +++ gcc/cp/pt.cc 2022-11-15 09:30:57.381080911 +0100 > @@ -29030,7 +29030,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); > @@ -29064,6 +29064,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/testsuite/g++.dg/cpp2a/concepts-dr2428.C.jj 2022-11-15 09:30:57.382080897 +0100 > +++ gcc/testsuite/g++.dg/cpp2a/concepts-dr2428.C 2022-11-15 09:30:57.382080897 +0100 > @@ -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; } > > > Jakub >