1

I'm getting a compilation error when defining the deduction guide below, but only when compiling with MSVC. With both GCC and Clang the compilation passes.

The Error I get with MSVC is "error C2955: 'A': use of class template requires template argument list"

Minimal reproduction example:

template <typename T>
struct A {
    T value;
};

template <typename T>
A(T) -> A<T>;

int main() {
    return 0;
}

The code and compilation results with all three compilers can be found at this godbolt link: https://godbolt.org/z/611hMKoYo

Is this a bug in MSVC or am I defining the deduction guide incorrectly and are GCC & Clang wrong?

Antiro42
  • 177
  • 8
  • 5
    You forgot to turn on C++17 mode with `/std:c++17`: https://godbolt.org/z/h854qEvKM. By default MSVC uses C++14 mode. – NathanOliver Feb 17 '23 at 14:54
  • Note that in C++20 you will not need this deduction guide because it is implicit for aggregate types. – AndyG Feb 17 '23 at 15:05
  • Thanks for the tip! I thought i was compiling with C++20 enabled, but it turned out there was a mistake in my cmake setup. – Antiro42 Feb 17 '23 at 15:19
  • Note that ``/std:c++20`` is not supported until VS 2019 (16.11) or VS 2022. See [this blog post](https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/). – Chuck Walbourn Feb 17 '23 at 19:09

0 Answers0