Skip to content

Commit aef6e23

Browse files
author
Patrick Palka
committed
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.
1 parent 885ef72 commit aef6e23

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

gcc/cp/constraint.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,15 +2490,15 @@ satisfy_disjunction (tree t, tree args, subst_info info)
24902490
tree
24912491
satisfaction_value (tree t)
24922492
{
2493-
if (t == error_mark_node)
2493+
if (t == error_mark_node || t == boolean_true_node || t == boolean_false_node)
24942494
return t;
2495-
if (t == boolean_true_node || t == integer_one_node)
2496-
return boolean_true_node;
2497-
if (t == boolean_false_node || t == integer_zero_node)
2498-
return boolean_false_node;
24992495

2500-
/* Anything else should be invalid. */
2501-
gcc_assert (false);
2496+
gcc_assert (TREE_CODE (t) == INTEGER_CST
2497+
&& same_type_p (TREE_TYPE (t), boolean_type_node));
2498+
if (integer_zerop (t))
2499+
return boolean_false_node;
2500+
else
2501+
return boolean_true_node;
25022502
}
25032503

25042504
/* Build a new template argument list with template arguments corresponding
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// PR c++/95386
2+
// { dg-do compile { target concepts } }
3+
4+
template <typename> struct blah {
5+
typedef bool value_type;
6+
constexpr operator value_type() { return false; }
7+
};
8+
9+
template <class T> void fn1(T) requires (!blah<T>());
10+
11+
void fn2() { fn1(0); }

0 commit comments

Comments
 (0)