https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92403
Bug ID: 92403
Summary: [concepts] requires expression in if constexpr
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pilarlatiesa at gmail dot com
Target Milestone: ---
This code is rejected by trunk, and I'd say it shouldn't
(https://godbolt.org/z/F7SOXw):
#include <cstddef>
#include <vector>
#include <array>
template<typename T>
void Resize(T &v, std::size_t const n)
{
if constexpr (requires { v.resize(n); })
v.resize(n);
}
int main()
{
std::vector<int> v;
std::array<int, 5u> a;
Resize(v, 10u);
Resize(a, 10u);
}
With GCC 7, 8, and 9 (with -fconcepts) it produces an ICE.