From: Marek Polacek Date: Wed, 22 Apr 2026 21:17:05 +0000 (-0400) Subject: c++/reflection: erroneous access check on dependent splice [PR124989] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=503724ac5ac16f18b5ea27599cb2816ba61ca2af;p=thirdparty%2Fgcc.git c++/reflection: erroneous access check on dependent splice [PR124989] When processing &[:R:] in cp_parser_splice_expression, we call build_offset_ref with access checking turned off via push_ and pop_deferring_access_checks, but the same pair of calls is not present around the call to build_offset_ref in tsubst_splice_expr and so the following test fails to compile due to access control checking failures. PR c++/124989 gcc/cp/ChangeLog: * pt.cc (tsubst_splice_expr): Turn off access checking for the build_offset_ref call. gcc/testsuite/ChangeLog: * g++.dg/reflect/member24.C: New test. Reviewed-by: Patrick Palka --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 551c8bcbb68..fca63d3950d 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -16957,12 +16957,14 @@ tsubst_splice_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (SPLICE_EXPR_ADDRESS_P (t)) { + push_deferring_access_checks (dk_no_check); if (BASELINK_P (op)) op = build_offset_ref (BINFO_TYPE (BASELINK_ACCESS_BINFO (op)), op, /*address_p=*/true, complain); else if (DECL_NONSTATIC_MEMBER_P (op)) op = build_offset_ref (DECL_CONTEXT (op), op, /*address_p=*/true, complain); + pop_deferring_access_checks (); } if (outer_automatic_var_p (op)) diff --git a/gcc/testsuite/g++.dg/reflect/member24.C b/gcc/testsuite/g++.dg/reflect/member24.C new file mode 100644 index 00000000000..461b8b35f30 --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/member24.C @@ -0,0 +1,25 @@ +// PR c++/124989 +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } + +using info = decltype(^^::); + +template +constexpr auto pointer_of() +{ + return &[: R :]; +} + +struct X +{ + int a; +protected: + int b; +private: + int c; + +public: + static constexpr auto pa = pointer_of<^^X::a>(); + static constexpr auto pb = pointer_of<^^X::b>(); + static constexpr auto pc = pointer_of<^^X::c>(); +};