]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: satisfaction value of type typedef to bool [PR95386]
authorPatrick Palka <ppalka@redhat.com>
Fri, 29 May 2020 17:09:20 +0000 (13:09 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sat, 30 May 2020 04:18:39 +0000 (00:18 -0400)
In the testcase below, the satisfaction value of fn1<int>'s constraint
is INTEGER_CST '1' of type BOOLEAN_TYPE value_type, which is a typedef
to the standard boolean_type_node.  But satisfaction_value expects to
see exactly boolean_true_node or integer_one_node, which this value is
neither, causing us to trip over the assert therein.

This patch relaxes satisfaction_value to accept any INTEGER_CST which
satisfies integer_zerop or integer_onep.

gcc/cp/ChangeLog:

PR c++/95386
* constraint.cc (satisfaction_value): Relax to accept any
INTEGER_CST that satisfies integer_zerop or integer_onep.

gcc/testsuite/ChangeLog:

PR c++/95386
* g++.dg/concepts/pr95386.C: New test.

gcc/cp/constraint.cc
gcc/testsuite/g++.dg/concepts/pr95386.C [new file with mode: 0644]

index 85513fecf4378966269e12bdbc998bee08092d83..18190c820dd8bdd2ded1ef4242b2c89c6db9cce4 100644 (file)
@@ -2492,11 +2492,12 @@ satisfy_disjunction (tree t, tree args, subst_info info)
 tree
 satisfaction_value (tree t)
 {
-  if (t == error_mark_node)
+  if (t == error_mark_node || t == boolean_true_node || t == boolean_false_node)
     return t;
-  if (t == boolean_true_node || t == integer_one_node)
+  gcc_assert (TREE_CODE (t) == INTEGER_CST);
+  if (integer_onep (t))
     return boolean_true_node;
-  if (t == boolean_false_node || t == integer_zero_node)
+  if (integer_zerop (t))
     return boolean_false_node;
 
   /* Anything else should be invalid.  */
diff --git a/gcc/testsuite/g++.dg/concepts/pr95386.C b/gcc/testsuite/g++.dg/concepts/pr95386.C
new file mode 100644 (file)
index 0000000..3c683e5
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/95386
+// { dg-do compile { target concepts } }
+
+template <typename> struct blah {
+ typedef bool value_type;
+ constexpr operator value_type() { return false; }
+};
+
+template <class T> void fn1(T) requires (!blah<T>());
+
+void fn2() { fn1(0); }