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).
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