https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92186
Bug ID: 92186
Summary: [concepts] requires expression outside of concept
definition cannot return false
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: kariya_mitsuru at hotmail dot com
Target Milestone: ---
The sample code below cannot be compiled by current trunk.
==========================
template <typename T>
int foo()
{
if (requires(T i) {
i++;
}) {
return 42;
} else {
return 99;
}
}
int main()
{
return foo<bool>();
}
==========================
cf. https://wandbox.org/permlink/6S5cGSAJHBL86cfi
According to C++ standard draft N4835 [expr.prim.req] p.6,
> The substitution of template arguments into a requires-expression
> may result in the formation of invalid types or expressions in its
> requirements or the violation of the semantic constraints of those
> requirements.
> In such cases, the requires-expression evaluates to false; it does
> not cause the program to be ill-formed.
So I think that the code should be compiled successfully.
Note that the code below can be compiled.
==========================
template <typename T>
concept can_increment = requires(T i) {
i++;
};
template <typename T>
int foo()
{
if (can_increment<T>) {
return 42;
} else {
return 99;
}
}
int main()
{
return foo<bool>();
}
==========================
cf. https://wandbox.org/permlink/VCqlkJwZHKNxZIaE