The following program which uses auto arguments to generate function templates and then explicitly instantiates them will compile fine in g++ and clang (x86-64 trunk, -std=c++20) but gives errors C2945 and C3190 in MSVC (x64 v19.latest /std:c++20).
https://godbolt.org/z/xsWcezzz6
#include <cstdint>
#include <concepts>
template <typename T>
concept MyType = std::same_as<T,uint16_t> || std::same_as<T,uint32_t>;
class A {
public:
void Foo(uint32_t arg1, MyType auto arg2);
void Bar(uint32_t agr1, MyType auto arg2, decltype(arg2) arg3);
};
void A::Foo(uint32_t arg1, MyType auto arg2) {} // define
template void A::Foo(uint32_t, uint16_t); // explicit instantiate for uint16_t
template void A::Foo(uint32_t, uint32_t); // explicit instantiate for uint32_t
void A::Bar(uint32_t arg1, MyType auto arg2, decltype(arg2) arg3) {} // define
template void A::Bar(uint32_t, uint16_t, uint16_t); // explicit instantiate for uint16_t
template void A::Bar(uint32_t, uint32_t, uint32_t); // explicit instantiate for uint32_t
int main() {}
MSVC error explanation is given as:
(26): error C3190: 'void A::Bar(uint32_t,uint16_t,uint16_t)' with the provided template arguments is not the explicit instantiation of any member function of 'A' (26): error C2945: explicit instantiation does not refer to a template-class specialization (27): error C3190: 'void A::Bar(uint32_t,uint32_t,uint32_t)' with the provided template arguments is not the explicit instantiation of any member function of 'A' (27): error C2945: explicit instantiation does not refer to a template-class specialization.
Am I doing something wrong that GCC/Clang is letting me get away with, or is it an MSVC bug which I should report? Are there any known workarounds?