Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MSVC fails to deduce template argument

This C++17 code compiles with clang and g++ but MSVC fails to deduce the template argument:

#include <type_traits>

struct Prop {
  constexpr Prop() {};
};

constexpr const Prop i;

struct Klass {
  template <auto Klass::*MEMBER, const Prop &P,
            std::enable_if_t<std::is_member_pointer_v<decltype(MEMBER)>, bool> = true>
  void def() {}
  void fn();
  int var;
};

void Klass::fn() {}

int main() {
  Klass k;

  k.def<&Klass::fn, i>();
  k.def<&Klass::var, i>();
}

Removing only the std::enable_if fixes it, as well as removing only the second template argument (the non-type reference). This makes me think that this is a bug. Does anyone see anything that is ill-formed or does anyone have any tips for making it work with MSVC?

I need the enable_if because I have multiple similar templates (that are more complex, this is only a minimal repro).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

MSVC 19.37.32822

>Solution :

The program is well-formed and this seems to be a msvc bug.


Premature checking of template validity

does anyone have any tips for making it work with MSVC?

You can use /permissive- flag to make it work with msvc until the bug is fixed. Demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading