aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constraint.cc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2020-08-17 16:36:33 -0400
committerJason Merrill <jason@redhat.com>2020-08-19 16:08:17 -0400
commitf1612b8ae8a60f62cf5456b3357a341550534a7e (patch)
tree1bd0b125354fadd755b4f4ac1af3d9e35292288a /gcc/cp/constraint.cc
parente6e01618e83bcd9eb3a2b27df30ed87106a748b4 (diff)
downloadgcc-f1612b8ae8a60f62cf5456b3357a341550534a7e.zip
gcc-f1612b8ae8a60f62cf5456b3357a341550534a7e.tar.gz
gcc-f1612b8ae8a60f62cf5456b3357a341550534a7e.tar.bz2
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.
Diffstat (limited to 'gcc/cp/constraint.cc')
-rw-r--r--gcc/cp/constraint.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 48d52ec..7a2f3b9 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -2814,16 +2814,22 @@ satisfy_declaration_constraints (tree t, tree args, subst_info info)
info.in_decl = t;
gcc_assert (TREE_CODE (t) == TEMPLATE_DECL);
+
+ args = add_outermost_template_args (t, args);
+
+ tree result = boolean_true_node;
if (tree norm = normalize_template_requirements (t, info.noisy ()))
{
+ if (!push_tinst_level (t, args))
+ return result;
tree pattern = DECL_TEMPLATE_RESULT (t);
push_access_scope (pattern);
- tree result = satisfy_associated_constraints (norm, args, info);
+ result = satisfy_associated_constraints (norm, args, info);
pop_access_scope (pattern);
- return result;
+ pop_tinst_level ();
}
- return boolean_true_node;
+ return result;
}
static tree