c++: Check satisfaction before non-dep convs. [CWG2369]
authorJason Merrill <jason@redhat.com>
Mon, 17 Aug 2020 20:36:33 +0000 (16:36 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 19 Aug 2020 20:08:17 +0000 (16:08 -0400)
commitf1612b8ae8a60f62cf5456b3357a341550534a7e
tree1bd0b125354fadd755b4f4ac1af3d9e35292288a
parente6e01618e83bcd9eb3a2b27df30ed87106a748b4
c++: Check satisfaction before non-dep convs. [CWG2369]

It's very hard to use concepts to protect a template from hard errors due to
unwanted instantiation if constraints aren't checked until after doing all
substitution and checking of non-dependent conversions.

It was pretty straightforward to insert the satisfaction check into the
logic, but I needed to make the 3-parameter version of
satisfy_declaration_constraints call push_tinst_level like the 2-parameter
version already does.  For simplicity, I also made it add any needed outer
template arguments from the TEMPLATE_DECL to the args.

The testsuite changes are mostly because this change causes unsatisfaction
to cause deduction to fail rather than reject the candidate later in
overload resolution.

gcc/cp/ChangeLog:

DR 2369
* cp-tree.h (push_tinst_level, push_tinst_level_loc): Declare.
* constraint.cc (satisfy_declaration_constraints):
Use add_outermost_template_args and push_tinst_level.
* pt.c (add_outermost_template_args): Handle getting
a TEMPLATE_DECL as the first argument.
(push_tinst_level, push_tinst_level_loc): No longer static.
(fn_type_unification): Check satisfaction before non-dependent
conversions.

gcc/testsuite/ChangeLog:

DR 2369
* g++.dg/concepts/diagnostic10.C: Adjust expexcted errors.
* g++.dg/concepts/diagnostic13.C: Adjust expexcted errors.
* g++.dg/concepts/diagnostic2.C: Adjust expexcted errors.
* g++.dg/concepts/diagnostic3.C: Adjust expexcted errors.
* g++.dg/concepts/diagnostic4.C: Adjust expexcted errors.
* g++.dg/concepts/diagnostic5.C: Adjust expexcted errors.
* g++.dg/concepts/diagnostic9.C: Adjust expexcted errors.
* g++.dg/concepts/expression2.C: Adjust expexcted errors.
* g++.dg/concepts/fn5.C: Adjust expexcted errors.
* g++.dg/concepts/placeholder5.C: Adjust expexcted errors.
* g++.dg/concepts/pr67595.C: Adjust expexcted errors.
* g++.dg/cpp2a/concepts-pr78752-2.C: Adjust expexcted errors.
* g++.dg/cpp2a/concepts-pr84140.C: Adjust expexcted errors.
* g++.dg/cpp2a/concepts-recursive-sat3.C: Adjust expexcted errors.
* g++.dg/cpp2a/concepts-requires18.C: Adjust expexcted errors.
* g++.dg/cpp2a/concepts-requires19.C: Adjust expexcted errors.
* g++.dg/cpp2a/concepts3.C: Adjust expexcted errors.
* g++.dg/cpp2a/concepts-nondep1.C: New test.
* g++.dg/cpp2a/concepts-nondep1a.C: New test.
22 files changed:
gcc/cp/constraint.cc
gcc/cp/cp-tree.h
gcc/cp/pt.c
gcc/testsuite/g++.dg/concepts/diagnostic10.C
gcc/testsuite/g++.dg/concepts/diagnostic13.C
gcc/testsuite/g++.dg/concepts/diagnostic2.C
gcc/testsuite/g++.dg/concepts/diagnostic3.C
gcc/testsuite/g++.dg/concepts/diagnostic4.C
gcc/testsuite/g++.dg/concepts/diagnostic5.C
gcc/testsuite/g++.dg/concepts/diagnostic9.C
gcc/testsuite/g++.dg/concepts/expression2.C
gcc/testsuite/g++.dg/concepts/fn5.C
gcc/testsuite/g++.dg/concepts/placeholder5.C
gcc/testsuite/g++.dg/concepts/pr67595.C
gcc/testsuite/g++.dg/cpp2a/concepts-nondep1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-nondep1a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-pr78752-2.C
gcc/testsuite/g++.dg/cpp2a/concepts-pr84140.C
gcc/testsuite/g++.dg/cpp2a/concepts-recursive-sat3.C
gcc/testsuite/g++.dg/cpp2a/concepts-requires18.C
gcc/testsuite/g++.dg/cpp2a/concepts-requires19.C
gcc/testsuite/g++.dg/cpp2a/concepts3.C