Issue 63845
Summary Wrong evaluation of a `if constexpr requires`
Labels
Assignees
Reporter Fedr
    The following program

```
#include <array>
#include <vector>

template <typename T>
constexpr std::size_t get_length(const T &t) {
    return t.size();
}

template <typename T, std::size_t N>
constexpr auto get_length(const std::array<T, N> &) {
    return std::integral_constant<std::size_t, N>();
}

static_assert( get_length(std::array<int, 3>())() == 3 );
static_assert( requires { typename std::array<int, get_length(std::array<int, 3>())>; } );

auto foo(auto length) {
 // If length could be evaluated at compile time,
    if constexpr (requires { typename std::array<int, length>; })
        return std::array<int, length>{};
    // Otherwise,
    else
        return std::vector<int>(length);
}

int main() {
    auto x = foo(get_length(std::vector<int>(5)));
    x.resize(1); // array does not have resize
    auto y = foo(get_length(std::array<int, 3>()));
 static_assert( y.size() == 3 ); // in Clang y is vector?
}
```

is accepted by GCC and MSVC. But in Clang `y` is a `std::vector` for some reason. Online demo: https://gcc.godbolt.org/z/h53zc3bjv

Related discussion: https://stackoverflow.com/a/76673819/7325599

Could you please check?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to