2

This code compiles fine with GCC and Clang.
But does not compile with MSVC. https://godbolt.org/z/h4oM1oe35

#include <vector>
#inlcude <functional>

template <typename ItemT, template <typename...> class ContainerT>
void msvc_fails(const ContainerT<std::reference_wrapper<const ItemT>> &){}

template <typename ItemT>
void msvc_works(const std::vector<std::reference_wrapper<const ItemT>> &)
{}

template <typename ItemT, template <typename...> class ContainerT>
void msvc_fails_also(const ContainerT<const ItemT*> &)
{}


int main()
{
    struct item{};
    const auto &vec = std::vector<std::reference_wrapper<const item>>();

    msvc_fails(vec);
    msvc_works(vec);

    const auto &vecPtr = std::vector<const item*>();
    msvc_fails_also(vecPtr);
    
    return 0;
}

Is this a bug in MSVC?

Sergey Kolesnik
  • 3,009
  • 1
  • 8
  • 28
  • It seems like it was accepted after [gcc-7](https://godbolt.org/z/q7zenTT41) implemented [p0522r0](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0522r0.html). – 康桓瑋 May 18 '22 at 16:12
  • @Artyer yeah, I forgot to include `functional`, though GCC didn't bother – Sergey Kolesnik May 18 '22 at 17:51
  • Curious: why are you using `const auto &vec = std::vector>();` and `const auto &vecPtr = std::vector();`, instead of using `const std::vector> vec;` and `const std::vector vecPtr;`? – Remy Lebeau May 18 '22 at 20:23
  • @RemyLebeau no particular reason. Usually I prefer the style when long type names are on the right (auto -> long_type_name) – Sergey Kolesnik May 18 '22 at 20:55
  • 1
    It works if you have `ContainerT, std::allocator>>` or `template class ContainerT, typename... Rest> void msvc_fails(const ContainerT, Rest...> &)` – Artyer Dec 23 '22 at 17:27

0 Answers0