Visitar URL original
/std:c++20 instead of /std:c++17 used for _wmimodule.cpp, but seems unnecessary · Issue #99191 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20221107212050/https://github.com/python/cpython/issues/99191
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

/std:c++20 instead of /std:c++17 used for _wmimodule.cpp, but seems unnecessary #99191

Open
CAM-Gerlach opened this issue Nov 7, 2022 · 2 comments
Labels
build The build process and cross-build OS-windows

Comments

@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented Nov 7, 2022

@python/windows-team

I noticed the VS project file _wmi.cxproj for _wmimodule.cpp added for 3.12 to support using WMI on Windows to get platform data in issue #89545 / PR #96289 specifies C++20 mode via the compiler flag /std:c++20. The flag (and partially-complete C++20 support) was only added in VS 2019 16.11, and produces a compiler warning in VS 2017 15.9 stating the flag was ignored.

This is the only file that requires it and there were no relevant hints in the issue, PR, or commit history as to why it was required. Despite the flag being ignored, there were no compiler errors or other warnings, and both the full test suite (minus a couple clearly unrelated issues) and running test_wmi and test_platform with -u all passed, and the same was true when I recompiled it with /std:c++17 (added in VS 2017 15.8 and used a couple other files), which naturally avoids the warning.

Therefore, it would seems specifying C++20 is unnecessary, and it can be changed to /std:c++17 to avoid compiler warnings and use a consistent C++ standard version with the other files, unless there's something I'm missing here (entirely possible, of course). Any reason this was added?

@CAM-Gerlach CAM-Gerlach added OS-windows build The build process and cross-build labels Nov 7, 2022
@vstinner
Copy link
Member

vstinner commented Nov 7, 2022

I guess that /std:c++17 is fine and maybe @zooba just picked the default when he created the new project.

@zooba
Copy link
Member

zooba commented Nov 7, 2022

_wmimodule.cpp includes this explanation near the top of the file:

#if _MSC_VER >= 1929
// We can use clinic directly when the C++ compiler supports C++20
#include "clinic/_wmimodule.cpp.h"
#else
// Cannot use clinic because of missing C++20 support, so create a simpler
// API instead. This won't impact releases, so fine to omit the docstring.
static PyObject *_wmi_exec_query_impl(PyObject *module, PyObject *query);
#define _WMI_EXEC_QUERY_METHODDEF {"exec_query", _wmi_exec_query_impl, METH_O, NULL},
#endif

Basically, Argument Clinic generates files that aren't valid C++ prior to C++20, because it uses designated initializers. Since I know I'm releasing with a compiler that supports them, I opt-in, but to allow other people to build and debug, it's easy enough to create a METH_O API directly around the _impl function.

I don't think we have any way to detect the compiler version in the build files, but if there is, we could make the option conditional on having an old compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build OS-windows
Projects
None yet
Development

No branches or pull requests

3 participants