]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix push_access_scope and introduce RAII wrapper for it
authorPatrick Palka <ppalka@redhat.com>
Wed, 30 Jun 2021 17:12:36 +0000 (13:12 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 30 Jun 2021 17:12:36 +0000 (13:12 -0400)
commitc28e1d288ab727de6eb493e1aa2eadf5d5eef3ab
treee345163ba2fd085640f5288911c6c2bbe91fe8f1
parentb5bb7f328d56cccfb85932ff586138e5a4ef1436
c++: Fix push_access_scope and introduce RAII wrapper for it

When push_access_scope is passed a TYPE_DECL for a class type (which
can happen during e.g. satisfaction), we undesirably push only the
enclosing context of the class instead of the class itself.  This
causes us to mishandle e.g. testcase below due to us not entering the
scope of A before checking its constraints.

This patch adjusts push_access_scope accordingly, and introduces an
RAII wrapper for it.  We make use of this wrapper right away by
replacing the only user of push_nested_class_guard with this new
wrapper, which means we can remove push_nested_class_guard (whose
functionality is basically subsumed by the new wrapper).

gcc/cp/ChangeLog:

* constraint.cc (get_normalized_constraints_from_decl): Use
push_access_scope_guard instead of push_nested_class_guard.
* cp-tree.h (struct push_nested_class_guard): Replace with ...
(struct push_access_scope_guard): ... this.
* pt.c (push_access_scope): When the argument corresponds to
a class type, push the class instead of its context.
(pop_access_scope): Adjust accordingly.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-access2.C: New test.
gcc/cp/constraint.cc
gcc/cp/cp-tree.h
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp2a/concepts-access2.C [new file with mode: 0644]