c++: Normalize nested-requirements twice at parse time [PR97093]
commit40234200864b6c0d0079abbcdc7a4139b60257ff
authorPatrick Palka <ppalka@redhat.com>
Sat, 5 Dec 2020 18:44:20 +0000 (5 13:44 -0500)
committerPatrick Palka <ppalka@redhat.com>
Sat, 5 Dec 2020 18:47:40 +0000 (5 13:47 -0500)
treef5803bb5c25ed4dbd1f6bdf5b89dd49e5a6f2f90
parent904ac8577521b8152b97e9b549c1a1ca569a3d1f
c++: Normalize nested-requirements twice at parse time [PR97093]

The re-normalization performed from diagnose_nested_requirement doesn't
always work because we may have already lost the necessary template
context that determines the set of in-scope template parameters used by
the nested-requirement.  This leads to normalization producing atoms
that have incomplete/bogus parameter mappings, which breaks satisfaction.

To fix this, we could just use the normal form that we previously
computed at parse time, but this normal form lacks the diagnostic
information that leads to good error messages.

Instead, this patch makes diagnose_nested_requirement normalize twice at
parse time -- once without diagnostic information and once with -- so
that routines can use the "regular" normal form when performing
satisfaction quietly and the "diagnostic" normal form when performing
satisfaction noisily.  Moreover, this patch makes tsubst_nested_requirement
always first perform satisfaction quietly so that the satisfaction cache
can get consistently utilized.

This patch also adds some sanity checks to build_parameter_mapping that
would have caught the underlying bug sooner (and deterministically).

gcc/cp/ChangeLog:

PR c++/97093
* constraint.cc (parameter_mapping_equivalent_p): Add some
sanity checks.  Clarify comment.
(tsubst_nested_requirement): Always perform satisfaction
quietly first.  If that yields an erroneous result, emit a
context message and replay satisfaction noisily with the
diagnostic normal form.
(finish_nested_requirement): Normalize the constraint-expression
twice, once with diagnostic information and once without.  Store
them in a TREE_LIST within the TREE_TYPE.
(diagnose_nested_requirement): When replaying satisfaction, use
the diagnostic normal form instead of renormalizing on the spot.

gcc/testsuite/ChangeLog:

PR c++/97093
* g++.dg/cpp2a/concepts-requires22.C: New test.
gcc/cp/constraint.cc
gcc/testsuite/g++.dg/cpp2a/concepts-requires22.C [new file with mode: 0644]