]> gcc.gnu.org Git - gcc.git/commit
c++: thinko in extract_local_specs [PR108998]
authorPatrick Palka <ppalka@redhat.com>
Fri, 3 Mar 2023 16:37:02 +0000 (11:37 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 3 Mar 2023 16:37:02 +0000 (11:37 -0500)
commit341e6cd8d603a334fd34657a6b454176be1c6437
tree660890b062fdd5a3231c2eb283edff991f327765
parent9056d0df830c5a295d7594d517d409d10476990d
c++: thinko in extract_local_specs [PR108998]

In order to fix PR100295, r13-4730-g18499b9f848707 attempted to make
extract_local_specs walk the given pattern twice, ignoring unevaluated
operands the first time around so that we prefer to process a local
specialization in an evaluated context if it appears in one (we process
each local specialization once even if it appears multiple times in the
pattern).

But there's a thinko in the patch, namely that we don't actually walk
the pattern twice since we don't clear the visited set for the second
walk (to avoid processing a local specialization twice) and so the root
node (and any node leading up to an unevaluated operand) is considered
visited already.  So the patch effectively made extract_local_specs
ignore unevaluated operands altogether, which this testcase demonstrates
isn't quite safe (extract_local_specs never sees 'aa' and we don't record
its local specialization, so later we try to specialize 'aa' on the spot
with the args {{int},{17}} which causes us to nonsensically substitute
its auto with 17.)

This patch fixes this by refining the second walk to start from the
trees we skipped over during the first walk.

PR c++/108998

gcc/cp/ChangeLog:

* pt.cc (el_data::skipped_trees): New data member.
(extract_locals_r): Push to skipped_trees any unevaluated
contexts that we skipped over.
(extract_local_specs): For the second walk, start from each
tree in skipped_trees.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-generic11.C: New test.
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/lambda-generic11.C [new file with mode: 0644]
This page took 0.05824 seconds and 5 git commands to generate.