c++: Improve handling of ill-formed constraints [PR94186].
authorJason Merrill <jason@redhat.com>
Tue, 24 Mar 2020 22:25:17 +0000 (18:25 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 24 Mar 2020 22:25:18 +0000 (18:25 -0400)
commitfddfd3ce555965864b6116cf541f6355d2057d3d
tree59426fff8e2a75642580e04b299ca9fd727e783f
parent5c1617418432466f3f91d282d356bdec91e9dbd2
c++: Improve handling of ill-formed constraints [PR94186].

It would have been trivial to make the error for non-bool constraint in
satisfy_atom unconditional, but that didn't give context for the error or
printing with the dependent form and template arguments.  So I changed a
couple of places so that, when a hard error is encountered during quiet
substitution/satisfaction, we go through again noisily; this builds up the
necessary context.

The similar change to tsubst_nested_requirement does not build up the
necessary context; rather than try to fix that now I changed
get_constraint_error_location to give up and use input_location if there's
no CONSTR_CONTEXT.  In the case of concepts-pr67697.C, we still have a good
source location because the NESTED_REQ has a correct EXPR_LOCATION, but this
patch doesn't improve context printing for this case as it does for the
above.

gcc/cp/ChangeLog
2020-03-24  Jason Merrill  <jason@redhat.com>

PR c++/94186
* constraint.cc (constraint_satisfaction_value): Repeat noisily on
error.
(tsubst_nested_requirement): Likewise.
(get_constraint_error_location): Allow missing context.
(diagnose_atomic_constraint): Diagnose non-bool constraint here.
(satisfy_atom): Not here.  Only diagnose non-constant when noisy.
gcc/cp/ChangeLog
gcc/cp/constraint.cc
gcc/testsuite/g++.dg/concepts/pr84330.C
gcc/testsuite/g++.dg/cpp2a/concepts-nonbool1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-requires1.C
gcc/testsuite/g++.dg/cpp2a/concepts-requires2.C