Home > Enterprise >  (MSVC) When implementing template method of template class outside of the class, C2244: Unable to ma
(MSVC) When implementing template method of template class outside of the class, C2244: Unable to ma

Time:05-30

Running into an issue with some code that compiles on GCC and Clang, but not MSVC (VS2022). Seems similar to this, but that was several years ago and this issue is specifically caused by the use of derived_from_specialization_of in the method template, so I'm not sure if it's the same issue.

I'm wondering what the reason for this is, and if the issue is with my code or MSVC.

DEMO

Example:

#include <concepts>

template <template <class...> class Template, class... Args>
void derived_from_specialization_impl(const Template<Args...>&);

template <class T, template <class...> class Template>
concept derived_from_specialization_of = requires(const T& t) {
    derived_from_specialization_impl<Template>(t);
};

template <class T>
class A
{
public:
    A() = default;
};

template <derived_from_specialization_of<A> T>
class B;

template <derived_from_specialization_of<B> T>
class C
{
public:
    C() = default;
};

template <derived_from_specialization_of<A> T>
class B
{
public:
    B() = default;

    template <derived_from_specialization_of<B> U>
    C<U> Foo();

    template <derived_from_specialization_of<B> U>
    C<U> Bar()
    {
        return C<U>();
    }
};

template <derived_from_specialization_of<A> T>
template <derived_from_specialization_of<B> U>
C<U> B<T>::Foo() 
{
    return C<U>();
}

CodePudding user response:

what the reason for this is, and if the issue is with my code or MSVC.

This seems to be a bug in MSVC. You've correctly provided the out-of-class definition for the member function template Foo<>.

Using auto and trailing return type doesn't seem to solve the issue in msvc. You can file a bug report for this.

  • Related