Visual C++ bug for aliasing templated struct variable in trailing return type (?)

51 Views Asked by At

I have some code that compiles on Clang but is rejected by Visual C++. I managed to break it down to this sample:

template <typename T>
static constexpr bool BoolValue = std::is_same_v<T, int>;

template <typename X>
struct Struct final
{
    template <typename T, typename U>
    static constexpr bool BoolValue = std::is_same_v<T, U>;

    template <typename Y>
    auto method() -> std::enable_if_t<BoolValue<X, Y>>;
};

template <typename X>
template <typename Y>
auto Struct<X>::method() -> std::enable_if_t<BoolValue<X, Y>> {}

It seems that the trailing return type in the final line should be referencing Struct::BoolValue, not ::BoolValue. It works on Clang, but is rejected by Visual C++ 2019 (latest version):

error C2977: 'BoolValue': too many template arguments
message : see declaration of 'BoolValue'
error C2993: 'unknown-type': is not a valid type for non-type template parameter '_Test'
error C2976: 'std::enable_if_t': too few template arguments
message : see declaration of 'std::enable_if_t'
error C2244: 'Struct<X>::method': unable to match function definition to an existing declaration
message : see declaration of 'Struct<X>::method'
message : definition
message : 'unknown-type Struct<X>::method(void)'
message : existing declarations
message : 'enable_if<Struct<X>::BoolValue<X,Y>,void>::type Struct<X>::method(void)'

I suspect this is a compiler bug, but I wanted to first check: is this code valid?

0

There are 0 best solutions below