[Bug c++/107574] [10/11/12 Regression] ICE: tree check in cp_fold_convert with ptr to member field cast inside a class not completed and inherent since r9-50-gd760b06868d660bc
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Mar 4 17:51:22 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107574
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:b7b50918fe52206e188c8c60c60e0d6a516e8572
commit r12-9216-gb7b50918fe52206e188c8c60c60e0d6a516e8572
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Feb 2 18:15:37 2023 -0500
c++: can't eval PTRMEM_CST in incomplete class [PR107574]
Here we're attempting to evaluate a PTRMEM_CST in a class that hasn't
been completed yet, but that doesn't work:
/* We can't lower this until the class is complete. */
if (!COMPLETE_TYPE_P (DECL_CONTEXT (member)))
return cst;
and then this unlowered PTRMEM_CST is used as EXPR in
tree op1 = build_nop (ptrdiff_type_node, expr);
and we crash in a subsequent cp_fold_convert which gets
type=ptrdiff_type_node,
expr=PTRMEM_CST and does
else if (TREE_CODE (expr) == PTRMEM_CST
&& same_type_p (TYPE_PTRMEM_CLASS_TYPE (type),
PTRMEM_CST_CLASS (expr)))
where TYPE_PTRMEM_CLASS_TYPE (type) is going to crash since the type
is ptrdiff_type_node. We could just add a TYPE_PTRMEM_P check before
accessing TYPE_PTRMEM_CLASS_TYPE but I think it's nicer to explain why
we couldn't evaluate the expression.
PR c++/107574
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_constant_expression): Emit an error when
a PTRMEM_CST cannot be evaluated.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/ptrmem-cst1.C: New test.
(cherry picked from commit de81e06273c613d7e06cbe2c8d9e72826c638056)
More information about the Gcc-bugs
mailing list