10

MSVC doesn't accept this code, even the latest version on Godbolt:

#include <type_traits>

template <class R>
struct A {
    A();
};

template <class R>
requires std::is_reference_v<R>
struct A<R> {
    A();
};

template <class R>
A<R>::A() {}

template <class R>
requires std::is_reference_v<R>
A<R>::A() {}

I've never fully understood the rules for determining correspondence of templated declarations, so perhaps this is IFNDR for some reason, or perhaps this is just an MSVC bug. I'm leaning toward the latter, but either outcome is surprising. Is there any way to define member functions out of line when the same signature belongs to both a primary class template and to a specialization of it that differs only by being constrained, and have MSVC accept it? This seems like a pretty significant missing feature if not.

(I understand that pre-C++20 techniques can be used for defining the partial specialization but I'd like to avoid adding a dummy template parameter to the primary template.)

4
  • 5
    This is strange. Small declaration reorder fixed the issue: godbolt.org/z/bPczbehq8 Commented Sep 3 at 16:27
  • 4
    I would say MSVC bug. Commented Sep 3 at 17:05
  • @MarekR That looks like an answer to the question. At least partially (pun intended). Commented Sep 3 at 20:48
  • 1
    Similar question: stackoverflow.com/questions/68589314/… Commented Sep 4 at 9:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.