October 24, 2024
Chicago 12, Melborne City, USA
templates

Unable to match function definition when type in concept template is aliased


I think i found a bug in MSVC, but i wanted to confirm. I have the following simple reproducer:

template <typename T, typename R>
concept convertible_range =
    std::ranges::sized_range<R> && std::convertible_to<std::ranges::range_value_t<R>, T>;

template <typename T>
struct S {
    using value_type = T;
    template <convertible_range<value_type> R>
    void foo(R&&);
};

template <typename T>
template <convertible_range<T> R>
void S<T>::foo(R&&) {}

This compiles with gcc-14.1 but fails in all versions of MSVC++ with:

error C2244: ‘S::foo’: unable to match function definition to an existing declaration

Live example

The issue appears to be a combination of defining foo outside the class using the type alias in the declaration of foo in S. If i either:

  1. define the function in place:
struct S {
    using value_type = T;
    template <convertible_range<value_type> R>
    void foo(R&&) {}
};
  1. Change the declaration to use T directly:
template <typename T>
struct S {
    template <convertible_range<T> R> // Difference is here!
    void foo(R&&);
};

template <typename T>
template <convertible_range<T> R>
void S<T>::foo(R&&) {}

Then this compiles.

Is this an MSVC bug?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video