[Bug c++/124978] Wrong type with decltype of auto template parameter
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jun 22 19:48:44 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124978
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-16 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:a5d39331b959364c25908669194377bac19316b8
commit r16-9144-ga5d39331b959364c25908669194377bac19316b8
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon Apr 27 17:56:18 2026 -0400
c++: fix decltype(id) for pointer-to-data-member access expr [PR124978]
Here after substitution into decltype(X), X is the expanded but not
constant-evaluated pointer-to-data-member access expression
*((const int *) *cw<Divide{42}>::value + (sizetype)
*cw<&Divide::value>::value)
and finish_decltype_type wrongly strips the outermost INDIRECT_REF under
the assumption that it's an implicit dereference of a reference, but here
it's an explicit pointer dereference. This causes the decltype to yield
const int* instead of the expected int.
This patch fixes this particular bug by checking REFERENCE_REF_P instead
of INDIRECT_REF_P which additionally verifies the dereferenced thing
actually has reference type. The decltype now yields the correct type
modulo an unnecessary const due to the separate bug PR115314.
PR c++/124978
PR c++/115314
gcc/cp/ChangeLog:
* semantics.cc (finish_decltype_type): Check REFERENCE_REF_P
instead of INDIRECT_REF_P before stripping implicit dereferences.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/nontype-class74.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit c607c686100689e3e68487cd8097c2fbd3904168)
More information about the Gcc-bugs
mailing list