From: Jason Merrill Date: Wed, 3 Mar 2021 22:38:55 +0000 (-0500) Subject: c++: Normalization and deduction guide rewriting [PR96199] X-Git-Tag: releases/gcc-10.3.0~249 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a588c87ba309492b351c1a55b08d907b65913e2c;p=thirdparty%2Fgcc.git c++: Normalization and deduction guide rewriting [PR96199] This is a subset of r11-2748; we don't want to rewrite all deduction guides in GCC 10, but we do need the push_nested_class in normalization to avoid breaking cmcstl2. gcc/cp/ChangeLog: PR c++/96199 * cp-tree.h (struct push_nested_class_guard): New. * constraint.cc (get_normalized_constraints_from_decl): Use it. --- diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index f54c220253fb..89a2bb5223bd 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -841,6 +841,8 @@ get_normalized_constraints_from_decl (tree d, bool diag = false) if (tree *p = hash_map_safe_get (normalized_map, tmpl)) return *p; + push_nested_class_guard pncs (DECL_CONTEXT (d)); + tree args = generic_targs_for (tmpl); tree ci = get_constraints (decl); tree norm = get_normalized_constraints_from_info (ci, args, tmpl, diag); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 82716d33c491..9a66fe5884f4 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8132,6 +8132,24 @@ is_constrained_auto (const_tree t) return is_auto (t) && PLACEHOLDER_TYPE_CONSTRAINTS (t); } +/* RAII class to push/pop class scope T; if T is not a class, do nothing. */ + +struct push_nested_class_guard +{ + bool push; + push_nested_class_guard (tree t) + : push (t && CLASS_TYPE_P (t)) + { + if (push) + push_nested_class (t); + } + ~push_nested_class_guard () + { + if (push) + pop_nested_class (); + } +}; + #if CHECKING_P namespace selftest { extern void run_cp_tests (void);