From patchwork Sat Apr 4 21:38:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Septicake X-Patchwork-Id: 132693 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 9DD594BA23D6 for ; Sat, 4 Apr 2026 21:39:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DD594BA23D6 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=GeTEAgkX X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com [209.85.217.48]) by sourceware.org (Postfix) with ESMTPS id A62534BA2E2B for ; Sat, 4 Apr 2026 21:38:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A62534BA2E2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A62534BA2E2B Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=209.85.217.48 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1775338696; cv=pass; b=Cfr24UZGHQwrSByPuJ4MYLDPgpI3pj9PD5xJNuMCnuM3HUCVMJEqAHf99rDF5vzF2cpdv9cryIGFc4v5g+Md2SDb54RGQbOcaYAaKxVow/9bW3ccGradBvprRnCmlmHqEv6wO9xzNPWQa7sAN3gUYxE7jPCCF52XPRNop0Kh0sM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1775338696; c=relaxed/simple; bh=nN8zFhKGMxInW5KzWEDFA1tKGUydYZLPtzB3j0jS8gc=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=x1F8mctfws+fJxGZIAbfuqgPqXZJjWBRTlfT7RSpIjE4GQxJ8fCzcJd/Pm8bB+Ru7NYYN/PZ+FZTPUJPamK9BGuC+wghMy5oMgdBdCK7xYKVQ5yuEQUj/pAOGvfr3nUxZnHZ5xMOFFb9dRoUXcGLJgMyEub+CRJRqk1p3HRjoug= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A62534BA2E2B Received: by mail-vs1-f48.google.com with SMTP id ada2fe7eead31-60591ade110so1939303137.1 for ; Sat, 04 Apr 2026 14:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775338696; cv=none; d=google.com; s=arc-20240605; b=WR8NozBZRGrRRLEK8eMcIa4NCOXM6Uc7YlstVFSU/BjhDIWFelus7gi+BvhQgn4s2H DoNFISAmjeFibfOeyQ9h2AVjqhZRZFfhlUFIDJAy3VU2Yx1t6Vyw0GssLEcovyjGqBge VV91SnZhw7Jci6LACkwn/hrW/0cQw9fkffoFsRjF4oFolilTkXJM+AOswxZi91wRHqjZ bJ6lDFL18cBDCBPEFkm9aQSKAwNF6XmXGQWPEsousJnegx0c3F5pkFhUJca1H70Nx2yn D9kXLUGygS9a6sj3ZSxhMGe2MLT2RLhom7gq4PPR0QXVLA7yS3hRQhKZwFeoOLE0w7FL Zj4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=+czjhYXQQbRosxdyEUD2PT+O2AHQOzxJ/XblKU7uYM0=; fh=oaSuqtdHlfrFL6BsfRwO9JDEf/VmsNPtxcnsvnORFSk=; b=SGgWPHdKF47J8B+bEHpPjppVRf4kWv50uTF+u26Kgc6BVMowumAqfNGHs/bEbBZ9Ld SRJm1fcogGt01jdDE31QzJL/4r7gMrMV0v9J+aAyomrXLGNQ2451i+f2rdNCajNsVD3O 6MfTVu/+hv2rrqisJEA03UPLsE7otKzg0JO+jJ3rU62nkCgMxEGlBlsDDfIISsM6lLAi uBUyIy9O4Twy0TfUpIjsahV7D4OnlBCVqbxcjKnZS/EyooMnI/cai9xIbZebS3AXsPKV ziZMKxcZroA/rMGi/D9ZLLDxIoQ5vZVI0XIb3wQCQDCF3Gd4mcxJrDCgGnl9Iyl7V4Gw wHwQ==; darn=gcc.gnu.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775338696; x=1775943496; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=+czjhYXQQbRosxdyEUD2PT+O2AHQOzxJ/XblKU7uYM0=; b=GeTEAgkX7/v+BmMi3t5iXMJfHtIDieq1Avwao9tCDk6Ug224WD7tT1et2ukS6JZDe8 fWzlx6/LF90UW5+pYFwN/LExm2aHC1drEEbqyz71DiQj25xzpnuXgebVycOvMST5I+Me O3DsxnGm+Dh5UiNFbCbyniLASC/Srnlzz0Y0ZC7ZXWVT2IHXUSdowQi2fFRBjf7FlAf9 p7QOr9vjWeci6K/x9OgL7/l3bzoBjRTiolfPAXPsWdRFj0NdE+XKKehpDYqhADNmR0Wy 6deKdrP3zOxbMaokBwci3cP70kAkJ16oyU/pa1r6wx55ufl4qdPDkDDwXdzk9aURAzzs G7DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775338696; x=1775943496; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+czjhYXQQbRosxdyEUD2PT+O2AHQOzxJ/XblKU7uYM0=; b=oHnTfTJgi5qFY6XzMYuRtHjtB/l8B54cS27jhHJ/8QqbXm49/WOLvXxskTIJFXEKSq WWCY104EemH8jV6lsR9z9uGr4ZgpgbzNeO9ZUwZqyclRRzFSMH7rov97Z9KIuB3GE3TM JQICpUTJHO3nx07WazlvLGhp7ADx5HkoMACQOqcH5LYaTzWHzPzZMafDTJbfihRztUf9 9CmVZz7g7jesgJSbOSwJkfVY2Hvqzxx/Klln5SQ4etTZ9S7Pt86BV7R9TyAK/2WP/KbB n4tOVhpL9dtFdKLdTVqcHB9TKpCz/+A0SSzBxj3jeX5tirEJK1KAxiDkpPL3WCWzpSoT 3viQ== X-Forwarded-Encrypted: i=1; AJvYcCUNTbEU4GD16jkxyii0dny5u14fK3D8Rv0Tef9XUvL++ZAmql7d9XY/m0gozMhOaP/ZxEiYzfhTG6Fkiw==@gcc.gnu.org X-Gm-Message-State: AOJu0YypPjSbteqx1r5Yx0N481+KBBViZ9xEYdXNpXCq34uUVunx55WL JKLmccb+WqjsS7hSBXA9ZXLzMMM6Ng3KhxYeVdUffUnT239qVNTqT4B2CucM7rogkNqjzPzEtSC rJWeNaEriQqm8klw4bTj/FK41sBdv8Oo= X-Gm-Gg: AeBDietD05Amahqa8RURwgBZV6LJYJeSQNkS+WGYHOU9yWb1/Ngvnz/bPp8HhmqFLfF XCRPlP207BqhFkwec7iiZ/xyH9eSlSIiIooXlmJYz8DO6s62aTVwrpBM7qVaEjmbll4ZsXYvMQd 27GDVxzWO9t4jyEJPWlSbdFJWpMnuDUyAHYCGLsNEaznnDVs7Djgni1VWp9Bj6xsh6d1SWmMyDc jk366s7dSG0v5hwKi1UVzo6hp7QKmMCUShRIGryqLaFUh2jtxPXdHFjZ0zo9E3tP/zdKVtDuin6 wQ== X-Received: by 2002:a05:6102:6043:b0:604:f640:301e with SMTP id ada2fe7eead31-605a4e0219cmr2892213137.12.1775338696058; Sat, 04 Apr 2026 14:38:16 -0700 (PDT) MIME-Version: 1.0 From: Septicake Date: Sat, 4 Apr 2026 17:38:04 -0400 X-Gm-Features: AQROBzCRmyxrKjkg4rmHj5cvLqqg0TJv0xcFt8ZOpPVJwbSBvKA8WQQebilCr4U Message-ID: Subject: [PATCH] libstdc++: Allow for function parameters in annotations_of[_with_type] [P3795R2] To: "libstdc++@gcc.gnu.org" , gcc-patches@gcc.gnu.org X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GB_FREEMAIL_NUM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org This patch adds function parameters as an allowed reflection info that can be passed to eval_annotations_of, and therefore the annotations_of and annotations_of_with_type metafunctions, following the update from P3795R2. The error message when an invalid reflection info has been passed in has also been updated to reflect this change. Tested and bootstrapped on x86_64-pc-linux-gnu. gcc/ * cp/reflect.cc (eval_annotations_of): Allow function parameters and update error message accordingly gcc/testsuite/ * g++.dg/reflect/annotations18.C: New test * g++.dg/reflect/annotations19.C: Likewise * g++.dg/reflect/annotations20.C: Likewise From 8894d4bbca547afe170a3faba03fbfdb2da23bed Mon Sep 17 00:00:00 2001 From: Septicake Date: Sat, 4 Apr 2026 15:46:40 -0400 Subject: [PATCH] libstdc++: Allow for function parameters in annotations_of[_with_type] [P3795R2] Signed-off-by: Septicake --- gcc/cp/reflect.cc | 8 +++++--- gcc/testsuite/g++.dg/reflect/annotations18.C | 14 ++++++++++++++ gcc/testsuite/g++.dg/reflect/annotations19.C | 20 ++++++++++++++++++++ gcc/testsuite/g++.dg/reflect/annotations20.C | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/reflect/annotations18.C create mode 100644 gcc/testsuite/g++.dg/reflect/annotations19.C create mode 100644 gcc/testsuite/g++.dg/reflect/annotations20.C diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index df7f0b54b5b..f9dd331dd82 100644 --- a/gcc/cp/reflect.cc +++ b/gcc/cp/reflect.cc @@ -3818,15 +3818,17 @@ eval_annotations_of (location_t loc, const constexpr_ctx *ctx, tree r, || eval_is_type_alias (r) == boolean_true_node || eval_is_variable (r, kind) == boolean_true_node || eval_is_function (r) == boolean_true_node + || eval_is_function_parameter (r, kind) == boolean_true_node || eval_is_namespace (r) == boolean_true_node || eval_is_enumerator (r) == boolean_true_node || eval_is_base (r, kind) == boolean_true_node || eval_is_nonstatic_data_member (r) == boolean_true_node)) return throw_exception (loc, ctx, "reflection does not represent a type," - " type alias, variable, function, namespace," - " enumerator, direct base class relationship," - " or non-static data member", + " type alias, variable, function, function" + " parameter, namespace, enumerator, direct" + " base class relationship, or non-static" + " data member.", fun, non_constant_p, jump_target); if (type) diff --git a/gcc/testsuite/g++.dg/reflect/annotations18.C b/gcc/testsuite/g++.dg/reflect/annotations18.C new file mode 100644 index 00000000000..8400ee30ac5 --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/annotations18.C @@ -0,0 +1,14 @@ +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } +// Test annotations_of on function parameter reflections + +#include + +using namespace std::meta; + +void foo([[=2]] int); + +void foo([[=1]] int) {} + +static_assert (define_static_array(annotations_of(parameters_of(^^foo)[0])).size() == 2); +static_assert ([: constant_of(annotations_of(parameters_of(^^foo)[0])[0]) :] == 2); diff --git a/gcc/testsuite/g++.dg/reflect/annotations19.C b/gcc/testsuite/g++.dg/reflect/annotations19.C new file mode 100644 index 00000000000..2d9b9cc3a16 --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/annotations19.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } +// Test annotations_of_with_type works as expected + +#include +#include +#include + +using namespace std::meta; + +void foo([[=1, =2.0f, =2.3f]] int) { + constexpr auto a_p = define_static_array(annotations_of_with_type(parameters_of(^^foo)[0], ^^float)); + + static_assert(a_p.size() == 2); + static_assert((annotations_of_with_type(parameters_of(^^foo)[0], ^^float) + | std::views::transform(constant_of) + | std::ranges::to()) + == std::vector { reflect_constant(2.0f), + reflect_constant(2.3f) }); +} diff --git a/gcc/testsuite/g++.dg/reflect/annotations20.C b/gcc/testsuite/g++.dg/reflect/annotations20.C new file mode 100644 index 00000000000..80db4a1bbbf --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/annotations20.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } +// Test that annotations match between +// variable and parameter reflections + +#include + +using namespace std::meta; + +void foo([[=2]] int); + +void foo([[=1]] int i) { + constexpr info p_r = parameters_of(^^foo)[0]; + constexpr info i_r = ^^i; + + static_assert(define_static_array(annotations_of(p_r)).size() == 2); + static_assert(define_static_array(annotations_of(i_r)).size() == 2); + static_assert(annotations_of(p_r) == annotations_of(i_r)); +} -- 2.43.0