https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97740

--- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-15 branch has been updated by Patrick Palka
<[email protected]>:

https://gcc.gnu.org/g:1669dbb9363dadf7a52d9f1090f13fa33c680c6a

commit r15-10317-g1669dbb9363dadf7a52d9f1090f13fa33c680c6a
Author: Patrick Palka <[email protected]>
Date:   Wed Sep 3 10:10:00 2025 -0400

    c++: constant non-dep init folding vs FIELD_DECL access [PR97740]

    Here although the local templated variables x and y have the same
    reduced constant value, only x's initializer {a.get()} is well-formed
    as written since A::m has private access.  We correctly reject y's
    initializer {&a.m} (at instantiation time), but we also reject x's
    initializer because we happen to constant fold it ahead of time, which
    means at instantiation time it's already represented as a COMPONENT_REF
    to a FIELD_DECL, and so when substituting this COMPONENT_REF we naively
    double check that the given FIELD_DECL is accessible, which fails.

    This patch sidesteps around this particular issue by not checking access
    when substituting a COMPONENT_REF to a FIELD_DECL.  If the target of a
    COMPONENT_REF is already a FIELD_DECL (i.e. before substitution), then I
    think we can assume access has been already checked appropriately.

            PR c++/97740

    gcc/cp/ChangeLog:

            * pt.cc (tsubst_expr) <case COMPONENT_REF>: Don't check access
            when the given member is already a FIELD_DECL.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-97740a.C: New test.
            * g++.dg/cpp0x/constexpr-97740b.C: New test.

    Reviewed-by: Jason Merrill <[email protected]>
    (cherry picked from commit 3e2077d8c7a0acba2d54bd0666ae578fe114cd72)

Reply via email to