static_assert ingoring a constexpr function

Viewed 122

I am trying to implement policies conducting different input checks. One of these policies should be constexpr checking a few conditions on the input type.

I created a minimal example showing my intensions: I expect the compiler to return the given static_assert failure message when dealing with an improper input. VS seems to ignore the constexpr function my_policy (both overloads) and that's why I get error C2338. GCC and Clang work both as expected in all three cases.

Would you classify it as a VS bug? Is there a way to overcome the issue?

Best regards!

#include <array>
#include <tuple>

template <typename Container, std::size_t MinSize>
constexpr bool is_of_min_size()
{
    return (std::tuple_size_v<Container> >= MinSize);
}

template <typename Container>
constexpr void check()
{
    static_assert(is_of_min_size<Container, 2>(),
    "Container has less than two elements.");
}

template <typename Container>
constexpr void my_policy(Container)
{
    check<Container>();
}

template <typename Container>
constexpr void my_policy()
{
    check<Container>();
}

template <typename Container>
auto main_call(Container const& t)
{
    check<Container>(); //works as expected in all 3 compilers (first error: "Container has less than two elements.", later on: array index out of bounds)

    my_policy(t); //returns the expected static_assert failure message in gcc and clange (in gcc as second error), returns 'array index out of bounds' in vs (ignoring static_assert completely)

    my_policy<Container>(); //as for my_policy(t)

    return std::get<1>(t);
}

int main()
{
    using WrongType = std::array<double, 1>;

    main_call(WrongType{}) ; //result for this case described in the function main_call
}

Edit: main_call() should include one of these 3 cases - they are to test separately.

Edit 2: replacing return std::get<1>(t); by return 0; provides the expected static_assert failure message (which confuses me even more)

0 Answers
Related