]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: For reflection look through DECL_LOCAL_DECL_P decls and fix up has_default_argum...
authorJakub Jelinek <jakub@redhat.com>
Tue, 17 Feb 2026 07:37:34 +0000 (08:37 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 17 Feb 2026 07:37:34 +0000 (08:37 +0100)
commite60f6111f63e8164158cd5ed2957e77532a63441
treef7e6a116d46740f50ec70d5cfdc754778c0a8640
parent6e52c1dbfb77ed09bc1352696384c80a45c70172
c++: For reflection look through DECL_LOCAL_DECL_P decls and fix up has_default_argument [PR123612]

Based on discussions in the PR that C++ 26 reflection is
entity based rather than declaration based, the following patch
ensures we reflect DECL_LOCAL_DECL_ALIAS of DECL_LOCAL_DECL_P vars
or function decls.
Additionally, while default arguments are intentionally not merged
from the block scope externs to their corresponding namespace scope
function decls, for std::meta::has_default_argument the wording
requires to return true even if there is at least one block scope
extern with default argument for the particular parameter.
So, the patch also records in a new flag whether a default argument
has been present in a block scope extern and propagates it through
further duplicate_decls.  eval_has_default_arguments then uses
both this new flag (for the block scope externs) and the preexisting
search for default arguments in the corresponding type.

2026-02-17  Jakub Jelinek  <jakub@redhat.com>

PR c++/123612
* cp-tree.h (DECL_HAS_DEFAULT_ARGUMENT_P): Define.
* decl.cc (merge_decl_arguments): For -freflection and
extern_alias set DECL_HAS_DEFAULT_ARGUMENT_P (oldarg)
if newdecl has a default argument for that parameter,
otherwise propagate the flag.
* reflect.cc (get_reflection): For DECL_LOCAL_DECL_P
use its DECL_LOCAL_DECL_ALIAS.
(eval_has_default_argument): Return boolean_true_node
also if DECL_HAS_DEFAULT_ARGUMENT_P flag is set.

* g++.dg/reflect/pr123612.C: New test.
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/reflect.cc
gcc/testsuite/g++.dg/reflect/pr123612.C [new file with mode: 0644]