[{"id":3681582,"web_url":"http://patchwork.ozlabs.org/comment/3681582/","msgid":"<71ad9a57-d534-49f5-a2cb-45daef308c34@redhat.com>","list_archive_url":null,"date":"2026-04-23T17:20:31","subject":"Re: [PATCH] c++: introduce lookup_annotation","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"On 4/23/26 12:54 PM, Marek Polacek wrote:\n> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?\n\nOK.\n\n> -- >8 --\n> This patch introduces a new helper for looking up annotations.\n> \n> gcc/cp/ChangeLog:\n> \n> \t* cp-tree.h (lookup_annotation): Declare.\n> \t* decl.cc (grokfndecl): Use lookup_annotation.\n> \t(grokdeclarator): Likewise.\n> \t* name-lookup.cc (push_local_extern_decl_alias): Likewise.\n> \t* parser.cc (cp_parser_decomposition_declaration): Likewise.\n> \t* reflect.cc (eval_annotations_of): Likewise.\n> \t* tree.cc (lookup_annotation): New.\n> ---\n>   gcc/cp/cp-tree.h      |  1 +\n>   gcc/cp/decl.cc        | 14 +++++---------\n>   gcc/cp/name-lookup.cc |  6 ++----\n>   gcc/cp/parser.cc      |  2 +-\n>   gcc/cp/reflect.cc     |  3 ++-\n>   gcc/cp/tree.cc        |  8 ++++++++\n>   6 files changed, 19 insertions(+), 15 deletions(-)\n> \n> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h\n> index 3d1f6f99aad..70132b586d8 100644\n> --- a/gcc/cp/cp-tree.h\n> +++ b/gcc/cp/cp-tree.h\n> @@ -8808,6 +8808,7 @@ extern tree cxx_copy_lang_qualifiers\t\t(const_tree, const_tree);\n>   extern void cxx_print_statistics\t\t(void);\n>   extern bool maybe_warn_zero_as_null_pointer_constant (tree, location_t);\n>   extern bool annotation_p\t\t\t(tree) ATTRIBUTE_PURE;\n> +extern tree lookup_annotation\t\t\t(tree);\n>   \n>   /* in ptree.cc */\n>   extern void cxx_print_xnode\t\t\t(FILE *, tree, int);\n> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc\n> index c3d589e8c23..6415f0b4bc2 100644\n> --- a/gcc/cp/decl.cc\n> +++ b/gcc/cp/decl.cc\n> @@ -12232,7 +12232,7 @@ grokfndecl (tree ctype,\n>   \t  && initialized == SD_INITIALIZED\n>   \t  && DECL_ATTRIBUTES (t))\n>   \tfor (tree a = DECL_ATTRIBUTES (t);\n> -\t     (a = lookup_attribute (\"internal \", \"annotation \", a));\n> +\t     (a = lookup_annotation (a));\n>   \t     a = TREE_CHAIN (a))\n>   \t  {\n>   \t    gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);\n> @@ -15938,10 +15938,9 @@ grokdeclarator (const cp_declarator *declarator,\n>   \t{\n>   \t  if (flag_reflection\n>   \t      && declarator->std_attributes != error_mark_node\n> -\t      && lookup_attribute (\"internal \", \"annotation \",\n> -\t\t\t\t   declarator->std_attributes)\n> +\t      && lookup_annotation (declarator->std_attributes)\n>   \t      && *attrlist != error_mark_node\n> -\t      && lookup_attribute (\"internal \", \"annotation \", *attrlist))\n> +\t      && lookup_annotation (*attrlist))\n>   \t    /* If there are annotations in both lists, ensure\n>   \t       declarator->std_attributes go after *attrlist.  See\n>   \t       PR124399.  */\n> @@ -16663,9 +16662,7 @@ grokdeclarator (const cp_declarator *declarator,\n>   \t  {\n>   \t    if (flag_reflection && !funcdef_flag && decl)\n>   \t      {\n> -\t\tif (attrlist\n> -\t\t    && lookup_attribute (\"internal \", \"annotation \",\n> -\t\t\t\t\t *attrlist))\n> +\t\tif (attrlist && lookup_annotation (*attrlist))\n>   \t\t  {\n>   \t\t    /* Remove the annotations to avoid spurious warning\n>   \t\t       below.  */\n> @@ -16676,8 +16673,7 @@ grokdeclarator (const cp_declarator *declarator,\n>   \t\t  }\n>   \t\tfor (tree arg = DECL_ARGUMENTS (decl);\n>   \t\t     arg; arg = DECL_CHAIN (arg))\n> -\t\t  if (lookup_attribute (\"internal \", \"annotation \",\n> -\t\t\t\t\tDECL_ATTRIBUTES (arg)))\n> +\t\t  if (lookup_annotation (DECL_ATTRIBUTES (arg)))\n>   \t\t    error_at (DECL_SOURCE_LOCATION (arg),\n>   \t\t\t      \"annotation applied to parameter %qD of \"\n>   \t\t\t      \"non-defining friend declaration\", arg);\n> diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc\n> index 568e615918c..ef844088381 100644\n> --- a/gcc/cp/name-lookup.cc\n> +++ b/gcc/cp/name-lookup.cc\n> @@ -3692,15 +3692,13 @@ push_local_extern_decl_alias (tree decl)\n>   {\n>     if (flag_reflection)\n>       {\n> -      if (lookup_attribute (\"internal \", \"annotation \",\n> -\t\t\t    DECL_ATTRIBUTES (decl)))\n> +      if (lookup_annotation (DECL_ATTRIBUTES (decl)))\n>   \terror_at (DECL_SOURCE_LOCATION (decl),\n>   \t\t  \"annotation applied to block scope extern %qD\",\n>   \t\t  decl);\n>         if (TREE_CODE (decl) == FUNCTION_DECL)\n>   \tfor (tree arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))\n> -\t  if (lookup_attribute (\"internal \", \"annotation \",\n> -\t\t\t\tDECL_ATTRIBUTES (arg)))\n> +\t  if (lookup_annotation (DECL_ATTRIBUTES (arg)))\n>   \t    error_at (DECL_SOURCE_LOCATION (arg),\n>   \t\t      \"annotation applied to parameter %qD of block scope \"\n>   \t\t      \"extern\", arg);\n> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc\n> index d07dc01650f..dc67cfd9f7c 100644\n> --- a/gcc/cp/parser.cc\n> +++ b/gcc/cp/parser.cc\n> @@ -18327,7 +18327,7 @@ cp_parser_decomposition_declaration (cp_parser *parser,\n>   \t      attr = NULL_TREE;\n>   \t    if (attr && first_attr == -1)\n>   \t      first_attr = v.length ();\n> -\t    if (lookup_attribute (\"internal \", \"annotation \", attr))\n> +\t    if (lookup_annotation (attr))\n>   \t      error (\"annotation on structured binding\");\n>   \t  }\n>   \tv.safe_push (e);\n> diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc\n> index 09e99b5ef83..27e1efee106 100644\n> --- a/gcc/cp/reflect.cc\n> +++ b/gcc/cp/reflect.cc\n> @@ -3966,7 +3966,8 @@ eval_annotations_of (location_t loc, const constexpr_ctx *ctx, tree r,\n>     else\n>       gcc_unreachable ();\n>     vec<constructor_elt, va_gc> *elts = nullptr;\n> -  for (tree a = r; (a = lookup_attribute (\"internal \", \"annotation \", a));\n> +  for (tree a = r;\n> +       (a = lookup_annotation (a));\n>          a = TREE_CHAIN (a))\n>       {\n>         gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);\n> diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc\n> index d3e202e8b04..c510a5bf2d0 100644\n> --- a/gcc/cp/tree.cc\n> +++ b/gcc/cp/tree.cc\n> @@ -7086,6 +7086,14 @@ annotation_p (tree attr)\n>     return is_attribute_p (\"annotation \", get_attribute_name (attr));\n>   }\n>   \n> +/* Lookup the annotation in ATTR, if present.  */\n> +\n> +tree\n> +lookup_annotation (tree attr)\n> +{\n> +  return lookup_attribute (\"internal \", \"annotation \", attr);\n> +}\n> +\n>   \f\n>   /* Release memory we no longer need after parsing.  */\n>   void\n> \n> base-commit: 8b110daf57a8b9966a07ce5f18a2fbb1949a434e","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=JHLeUbPi;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=JHLeUbPi","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.133.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g1jYL0zfkz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 24 Apr 2026 03:21:08 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id D28204BAD165\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 17:21:06 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by sourceware.org (Postfix) with ESMTP id 787A04BA7988\n for <gcc-patches@gcc.gnu.org>; Thu, 23 Apr 2026 17:20:37 +0000 (GMT)","from mail-qv1-f70.google.com (mail-qv1-f70.google.com\n [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-588-ExAb311MNiGhyQhZ7nkAmQ-1; Thu, 23 Apr 2026 13:20:35 -0400","by mail-qv1-f70.google.com with SMTP id\n 6a1803df08f44-8a14905811cso37946876d6.2\n for <gcc-patches@gcc.gnu.org>; Thu, 23 Apr 2026 10:20:34 -0700 (PDT)","from [192.168.50.130]\n (130-44-146-247.s12789.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com.\n [130.44.146.247]) by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-8b02ae61332sm155555456d6.24.2026.04.23.10.20.32\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Thu, 23 Apr 2026 10:20:32 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org D28204BAD165","OpenDKIM Filter v2.11.0 sourceware.org 787A04BA7988"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 787A04BA7988","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 787A04BA7988","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776964837; cv=none;\n b=fJzuRuCzvU3ZOJojNJ+49yBrmATpYmucoZ1wHcLo5ip1TJ83y6lhp4g9fnjKD+yX/Q6lfUiWwNTCHuU8wU20lA/jpa8exlYXbvuqWDAD7WhfdC2colOssUvALLXMuABq/oD4aFJxcqlLMXnOOaPGzm7lyESu5soT2PyUr+ZbKj4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776964837; c=relaxed/simple;\n bh=Oiw2R+TlUo7At+Bi6nJnH0soJMialj/zbGX4rGT8lYE=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=UmgpVluvcKBs8Uxa8nahprxU/urht1FBQtjDJ+dj6a/6YWV07QzYBa3huYOzBpFIwDsYzlghqAyZIdwKpn/svz7GOC+2Pojxf2J0UUDAFR62T1UsximatuLspDffDNaqH4/aBjk14u1a07NfsLWRlf5W81oVLkoqIVaawPpv61U=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776964837;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=ZSljkbpziiV73MaDUmP+4rx1ZpNGeQ6CuZYlsHc/cD4=;\n b=JHLeUbPibD3h8sKaGsqczH81xIoXlzMVpMRNh4AxQfSOTMSrXcUm60h8tQDDL6ZMPvgIGV\n 3ck/QMmoEavuFokwaJ2V9+wGDvAE16iPjm9oFUrt5YX3aQIRwkItrOYRWewZhGAf5AM63a\n 9Razlb/so04SIKFizwKA7xiVKbeLJLk=","X-MC-Unique":"ExAb311MNiGhyQhZ7nkAmQ-1","X-Mimecast-MFC-AGG-ID":"ExAb311MNiGhyQhZ7nkAmQ_1776964834","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776964834; x=1777569634;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=KzBkuE3gvlHlDBkDNz3FJ4iA9Xg+2sXNTBMgl+1/IzA=;\n b=q7A34OUw9HEjjMx2JefEUEtWJ0va9ojyOCjo2HDHKGUIicVC4x0M75WllFgXnHawjc\n gn5rdR2zUJtHQ+k2WJvTb3a2rWp04tNCkCTh+PknThj+6Ye5R5y8wE1gQgBxi0aLtzJa\n hwGfWfkwOGtlbUbpojonMTW9mx0XtcHJKlHgV1/WOGptFnvGkhk6NjN61OheUXgYdd94\n XXd3qSYouCDGmX732wqlS8DIotTViwIwd60nIULkzYQrFB1ZqmYsQAddOyDGEnBmilFm\n EQlxbBkt0nCdg4RRqKFGaKcv1qc68lwgLtVvraiXMpiEX/+refK/3X1e5tO4aFluAnKk\n xuWw==","X-Forwarded-Encrypted":"i=1;\n AFNElJ8zxcuFs/Py2Kur8tPdPdd1xfEaorMCFd7bkMojV4ssyf1cd7QJuFxYG2LPdHQiFLaASO29RrR1zuatow==@gcc.gnu.org","X-Gm-Message-State":"AOJu0Yyqces/TtrQiNRI9BFhyIAF1aBFVaoECnIJO3LGcDjWdM4edzah\n pzI9dCyd18jVFDk4ZdnRMxO0GX6v4N0xlvnZ53Z5xiif8Ltxfe0jHVavAuQwDNlmEkVTTQnA+Qs\n fanEt/7lBm5wjv4uGoILUARudOy/W309T6D7oERaVrdaxSe3QQeOr12qz+hM=","X-Gm-Gg":"AeBDievZODxxcaSJyxmD6gy+wsRJctAmiRGsLfu7sfKA8NWlTMLGH3zVIOnYV4kCS2V\n KZGt6NWeh/LXdiss8zgw41tk1VZiCeQi2bB8mqhe8chT8bg9eJA8/OveJ1nW7+NlkW2ZepduU8q\n p3GmLeZw+M4ElIo/WOs3wfDhkf7SNJcodaR+L2sE4SRa9mB9REaCIptCt+S/5InJLpoTTR/IAkD\n TFdYoCxfgpiQFqoXfwQ3zExTPfxaAZx4kXcaKi7pLiFnEmQSuVB8S4xpQg0o8rZrFIVMXLrA9Fe\n AhBD00WEkMBDyVH0L4s0MA/w4UCzcjT8r7NLfFly9bS9wwbe+6eVFuf3e70M47r8q1u9vM83hWE\n qJA2rlCqGerjAberDgdzzWIPl6jsZI8i26XbyxG1tsUUFXUU3fIbx8lIqM2DRF6eavWtClekLx6\n bqv++7iza9r/seHqX12Desu9nUaDvmTe4Dgjd0kRbvrg==","X-Received":["by 2002:a05:6214:2a47:b0:8a7:16f8:442a with SMTP id\n 6a1803df08f44-8b028139a98mr435680716d6.39.1776964834054;\n Thu, 23 Apr 2026 10:20:34 -0700 (PDT)","by 2002:a05:6214:2a47:b0:8a7:16f8:442a with SMTP id\n 6a1803df08f44-8b028139a98mr435680216d6.39.1776964833414;\n Thu, 23 Apr 2026 10:20:33 -0700 (PDT)"],"Message-ID":"<71ad9a57-d534-49f5-a2cb-45daef308c34@redhat.com>","Date":"Thu, 23 Apr 2026 13:20:31 -0400","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] c++: introduce lookup_annotation","To":"Marek Polacek <polacek@redhat.com>, GCC Patches\n <gcc-patches@gcc.gnu.org>, Jakub Jelinek <jakub@redhat.com>,\n Patrick Palka <ppalka@redhat.com>","References":"<20260423165422.1725245-1-polacek@redhat.com>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"<20260423165422.1725245-1-polacek@redhat.com>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"KGSnpH0qrO4oBVy_RdaXW9N9eOpa-QHoEsKfOs6n1V8_1776964834","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]