aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2020-05-29 21:12:21 -0400
committerPatrick Palka <ppalka@redhat.com>2020-05-29 21:12:21 -0400
commitaef6e234a8a78db39b4ba034cc4c100c07c294a7 (patch)
tree7ddbd61f63e9768bb33c105e39f46babf39ca566 /gcc
parent885ef72f270cf8e58066681e70fb05d846ac426e (diff)
downloadgcc-aef6e234a8a78db39b4ba034cc4c100c07c294a7.zip
gcc-aef6e234a8a78db39b4ba034cc4c100c07c294a7.tar.gz
gcc-aef6e234a8a78db39b4ba034cc4c100c07c294a7.tar.bz2
c++: satisfaction value of type typedef to bool [PR95386]
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 changes satisfaction_value to accept INTEGER_CST of any boolean type. gcc/cp/ChangeLog: PR c++/95386 * constraint.cc (satisfaction_value): Accept INTEGER_CST of any boolean type. gcc/testsuite/ChangeLog: PR c++/95386 * g++.dg/concepts/pr95386.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/constraint.cc14
-rw-r--r--gcc/testsuite/g++.dg/concepts/pr95386.C11
2 files changed, 18 insertions, 7 deletions
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index eb72bfe..92ff283 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -2490,15 +2490,15 @@ 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)
- return boolean_true_node;
- if (t == boolean_false_node || t == integer_zero_node)
- return boolean_false_node;
- /* Anything else should be invalid. */
- gcc_assert (false);
+ gcc_assert (TREE_CODE (t) == INTEGER_CST
+ && same_type_p (TREE_TYPE (t), boolean_type_node));
+ if (integer_zerop (t))
+ return boolean_false_node;
+ else
+ return boolean_true_node;
}
/* Build a new template argument list with template arguments corresponding
diff --git a/gcc/testsuite/g++.dg/concepts/pr95386.C b/gcc/testsuite/g++.dg/concepts/pr95386.C
new file mode 100644
index 0000000..3c683e5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/pr95386.C
@@ -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); }