https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108503
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:d427407a199a0c276cb02d6bbb64e6ecc02e590d commit r13-5379-gd427407a199a0c276cb02d6bbb64e6ecc02e590d Author: Jakub Jelinek <ja...@redhat.com> Date: Thu Jan 26 10:41:10 2023 +0100 openmp, c++: Workaround fold_for_warn ICE on invalid OpenMP collapsed loops [PR108503] My recent change to deduce structured binding vars earlier caused the following invalid testcase to ICE. The problem is that because at cp_convert_omp_range_for when !processing_template_decl we aren't yet ready to finalize the structured bindings (e.g. can't emit there associated code) but need to deduce types of the vars so that we don't get errors if we parse invalid uses of those vars in inner loops of the collapsed construct. This is done by temporarily bumping processing_template_decl around the call to cp_finish_decomp. Unfortunately, as we can't finalize it yet, the types of the vars will be deduced, but their DECL_VALUE_EXPR is not finalized yet and if say fold_for_warn tries to constant expression evaluate them, it recurses on DECL_VALUE_EXPR and ICEs because it sees e.g. ARRAY_REF (with NULL type) on a VAR_DECL with class type. The following patch works around that by temporarily hiding the DECL_VALUE_EXPRs by clearing DECL_HAS_VALUE_EXPR_P in that case during cp_convert_omp_range_for and arranging for cp_finish_omp_range_for to set it back before doing the final cp_finish_decomp. 2023-01-25 Jakub Jelinek <ja...@redhat.com> PR c++/108503 * parser.cc (cp_convert_omp_range_for): If cp_finish_decomp has been called in !processing_template_decl with processing_template_decl temporarily set, clear DECL_HAS_VALUE_EXPR_P on the vars temporarily. (cp_finish_omp_range_for): And set it back again here. * g++.dg/gomp/pr108503.C: New test.