Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC 2017 and define PYBIND11_CPP17 #833

Closed
RedSkotina opened this issue May 4, 2017 · 4 comments
Closed

MSVC 2017 and define PYBIND11_CPP17 #833

RedSkotina opened this issue May 4, 2017 · 4 comments

Comments

@RedSkotina
Copy link

PYBIND11_CPP17 not defined for msvc 2017 but msvc 2017 has support for extended constexpr and std::variant with compiler option /std:c++latest
I try explicit define PYBIND11_CPP17 on msvc and run test succesufull. (as far as I understand)

https://github.com/pybind/pybind11/blob/master/include/pybind11/common.h#L19

// Neither MSVC nor Intel support enough of C++14 yet (in particular, as of MSVC 2015 and ICC 17
// beta, neither support extended constexpr, which we rely on in descr.h), so don't enable pybind
// CPP14 features for them.
#if !defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#  if __cplusplus >= 201402L
#    define PYBIND11_CPP14
#    if __cplusplus > 201402L /* Temporary: should be updated to >= the final C++17 value once known */
#      define PYBIND11_CPP17
#    endif
#  endif
#endif

Can you add PYBIND11_CPP17 support for msvc 2017 (with and without /std:c++latest )?

@jagerman
Copy link
Member

jagerman commented May 4, 2017

If what you want is support for stl.h enabling <optional> and <variant> under MSVC 2017, a patch for that sounds pretty reasonable. Are these always available, or does availability depend on a particular /std: flag?

As an aside, we can't reasonably define PYBIND11_CPP17, until MSVC supports considerably more of C++17 (for the most part, MSVC 2017's C++17 support is limited to stl features and almost devoid of core language features). We can't even set PYBIND11_CPP14: MSVC still chokes on the C++14 codepath in descr.h. While it claims to support relaxed constexpr, it doesn't seem to support it robustly: the combination of relaxed constexpr and constexpr auto return types in descr.h doesn't work. I did try turning on it when MSVC 2017 came out; it failed, and so the define is still off.

@RedSkotina
Copy link
Author

RedSkotina commented May 6, 2017

some info:
1.

/std:c++14
The /std:c++14 switch enables the set of C++14 features implemented by the Visual C++ compiler, modulo conformance bug fixes and ongoing feature work (such as for constexpr, expression SFINAE, 2-phase name lookup, etc.) Using the /std:c++14 switch will always instruct Visual C++ to compile your code according to the C++14 standards and associated Defect Reports. This is the default language version in this update.

/std:c++latest
The /std:c++latest switch will move forward the set of features implemented by Visual C++ with each new version of the C++ standards Working Draft. Currently it will track features that we add for the proposed post-C++14 draft standard. When the next standard is approved, the semantics opted-in with the /std:c++latest will be covered by /std:c++17 (assuming that the next standard is C++17, but the standards committee working group never ceases to surprise) and /std:c++latest will move forward to track the next draft standard’s features. In another words, with /std:c++latest, you will always get the set of all new features currently implemented and on by default.

Now std::variant, std::optional, std::any available as part of c++17 ONLY with /std:c++latest. Later it must be available with /std:c++17 (we dont have such parameter now)
How we can detect this parameters ?

visual studio 14 aka visual studio 2015 update 3 documentation :

_MSVC_LANG Defined as an integer literal that specifies the C++ language standard targeted by the compiler. When compiled as C++, the macro is the integer literal value 201402 if the /std:c++14 compiler option is set, or by default, and it is set to a higher, unspecified value when the /std:c++latest compiler option is set. Otherwise, the macro is undefined. The _MSVC_LANG macro and /std (Specify Language Standard Version) compiler options are available beginning in Visual Studio 2015 Update 3.

msvc 2017 test

e:\code\zog\langtest>cl /nologo /EHsc /std:c++14 main.cpp
e:\code\zog\langtest>main
_MSVC_LANG = 201402
e:\code\zog\langtest>cl /nologo /EHsc /std:c++latest main.cpp
e:\code\zog\langtest>main
_MSVC_LANG = 201403
  1. I try explicit define PYBIND11_CPP14 with /std:c++latest . It is fail, as you say with partitial constexpr support.
    But with explicit define PYBIND11_CPP17 and /std:c++latest and PYBIND11_HAS_VARIANT i can compile simple example with variant.
    to be continue...

@jagerman
Copy link
Member

jagerman commented May 8, 2017

#841 should address this, by setting CPP14 for MSVC and, if you use /std:c++latest under MSVC 2017, CPP17. It appears to work (and passes the optional/variant tests), but give it a try and confirm that it works for you.

@jagerman
Copy link
Member

jagerman commented May 9, 2017

Fixed via #841.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants