patterns icon indicating copy to clipboard operation
patterns copied to clipboard

Does not compile under MSVC 2019

Open Warwolt opened this issue 5 years ago • 1 comments

While not explicitly stated as being a supported compiler, the Microsoft Visual C++ compiler should fall under "standard conformant C++17 compiler".

Trying to compile gives an error on C++17 checking: https://godbolt.org/z/frsGsb

Additionally, if this is circumvented by commenting out the check in config.hpp , some explicit GCC pragmas in as_tuple.hpp are unrecognized by MSVC and needed to be commented out as well.

Finally, when I tried to compile the fizzbuzz example, I got the following error: Context does not allow for disambiguation of overloaded function

Microsoft (R) Build Engine version 16.7.0+b89cb5fde for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  main.cpp
C:\dev\c++\my_proj\third_party\patterns\include\mpark\patterns/match.hpp(736,30): message : Context does not allow for disambiguation of overloaded function [C:\dev\c++\my_proj\build\prog.vcxproj]
C:\dev\c++\my_proj\third_party\patterns\include\mpark\patterns/match.hpp(987): message : see reference to function template instantiation 'auto mpark::patterns::try_match<int,int,std::tuple<_Ty &&,_Ty &&>,mpark::patter
ns::detail::Match<R,int,int>::()::<lambda_1>::()::<lambda_1>>(const mpark::patterns::Ds<int,int> &,Values &&,F &&)' being compiled [C:\dev\c++\my_proj\build\prog.vcxproj]
          with
          [
              _Ty=int,
              R=mpark::patterns::detail::Deduce,
              Values=std::tuple<int &&,int &&>,
              F=mpark::patterns::detail::Match<mpark::patterns::detail::Deduce,int,int>::()::<lambda_1>::()::<lambda_1>
          ]
C:\dev\c++\my_proj\src\main.cpp(46): message : see reference to function template instantiation 'decltype(auto) mpark::patterns::detail::Match<R,int,int>::operator ()<mpark::patterns::detail::Pattern<false,int,int>,Rhs
&&,mpark::patterns::detail::Case<mpark::patterns::detail::Pattern<false,int,mpark::patterns::Identifier<18446744073709551615,void>>,fizzbuzz::<lambda_2> &&>,mpark::patterns::detail::Case<mpark::patterns::detail::Pattern<false,mpark::patt
erns::Identifier<18446744073709551615,void>,int>,fizzbuzz::<lambda_3> &&>,mpark::patterns::detail::Case<mpark::patterns::detail::Pattern<false,mpark::patterns::Identifier<18446744073709551615,void>,mpark::patterns::Identifier<18446744073
709551615,void>>,fizzbuzz::<lambda_4> &&>>(mpark::patterns::detail::Case<mpark::patterns::detail::Pattern<false,int,int>,Rhs &&> &&,mpark::patterns::detail::Case<mpark::patterns::detail::Pattern<false,int,mpark::patterns::Identifier<1844
6744073709551615,void>>,fizzbuzz::<lambda_2> &&> &&,mpark::patterns::detail::Case<mpark::patterns::detail::Pattern<false,mpark::patterns::Identifier<18446744073709551615,void>,int>,fizzbuzz::<lambda_3> &&> &&,mpark::patterns::detail::Cas
e<mpark::patterns::detail::Pattern<false,mpark::patterns::Identifier<18446744073709551615,void>,mpark::patterns::Identifier<18446744073709551615,void>>,fizzbuzz::<lambda_4> &&> &&) &&' being compiled [C:\dev\c++\game_dev\opengl_platforme
r\build\prog.vcxproj]
          with
          [
              R=mpark::patterns::detail::Deduce,
              Rhs=fizzbuzz::<lambda_1>
          ]

Again, while MSVC isn't explicitly supported, I think it could be worthwhile to state that in practice only GCC and Clang are supported and tested.

Cool project never the less!

Warwolt avatar Dec 17 '20 02:12 Warwolt

__cplusplus on MSVC is 199711L. /Zc:__cplusplus is required to get a proper C++ version. (https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/)

Alternatively, config.hpp can be modified as follows.

#ifdef _MSVC_LANG
#  define MP_CPLUSPLUS _MSVC_LANG
#else
#  define MP_CPLUSPLUS __cplusplus
#endif

#if MP_CPLUSPLUS < 201703L
#error "MPark.Patterns requires C++17 support."
#endif

as_tuple.hpp can be edited to address C4068 as follows.

#ifdef __GNUG__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
  template <typename T,
            std::size_t... Is,
            typename = decltype(T{(Is, fill{})...})>
  constexpr bool is_n_constructible(std::index_sequence<Is...>,
                                    lib::priority<0>) {
    return true;
  }
#ifdef __GNUG__
#pragma GCC diagnostic pop
#endif

The fizzbuzz example compiles in MSVC 2022 Version 17.8.3 (C++17/20/latest).

pascal754 avatar Dec 13 '23 05:12 pascal754