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 <ppalka@redhat.com>
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))
--- /dev/null
+// PR c++/124989
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+using info = decltype(^^::);
+
+template <info R>
+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>();
+};