[Bug c++/97740] [13/14 Regression] Weird error message about accessing a private member of my own class inside of std::string_view inside of constexpr
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 30 14:25:06 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97740
--- Comment #15 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:d84dd6434adf8808901a74ded3db64590ae650bc
commit r14-12488-gd84dd6434adf8808901a74ded3db64590ae650bc
Author: Patrick Palka <ppalka@redhat.com>
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 <jason@redhat.com>
(cherry picked from commit 3e2077d8c7a0acba2d54bd0666ae578fe114cd72)
More information about the Gcc-bugs
mailing list