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

fix C++ build for MSVC 2022 #21096

Merged
merged 17 commits into from May 24, 2023
Merged

fix C++ build for MSVC 2022 #21096

merged 17 commits into from May 24, 2023

Conversation

tonycoz
Copy link
Contributor

@tonycoz tonycoz commented May 15, 2023

Fixes #21073 for MSVC

Draft since it shouldn't be applied as is.

Includes Leont's designated array initialization revert.

@rwp0
Copy link
Contributor

rwp0 commented May 15, 2023

Can the GitHub CI runner be increased to windows-2022 then too?

https://github.com/Perl/perl5/blob/blead/.github/workflows/testsuite.yml#L460

I couldn't build Perl with Visual Studio 2022 under Windows 11.

Thanks.

@tonycoz
Copy link
Contributor Author

tonycoz commented May 15, 2023

I couldn't build Perl with Visual Studio 2021 under Windows 11.

Do you mean 2022? There is no 2021, see https://visualstudio.microsoft.com/vs/older-downloads/

Do you mean as C++ with this branch?

The -std:c++20 might need to be -std:c++latest with VS2019.

I could only see us increasing the required version for CI if we added a C++ build.

@tonycoz
Copy link
Contributor Author

tonycoz commented May 18, 2023

I tried building with both VS 2019 and 2017, both updated since their original installation.

Both successfully did a default build of this branch:

2019 accepted the -std:c++20 even though that isn't listed as an option in cl /?.

2017 warned about -std:c++20 when building perllib.obj:

cl : Command line warning D9002 : ignoring unknown option '-std:c++20'

but successfully built this branch.

For C++ builds:

2019 successfully built this branch with USE_CPLUSPLUS=define with -std:c++20.

2017 failed to build this branch with USE_CPLUSPLUS=define with either of -std:c++20 (which it ignores) and -std:c++latest failing on the use of designated initializers.

I'll re-work this to only add the -std:c++20 for USE_CPLUSPLUS builds.

tonycoz added 17 commits May 22, 2023 15:42
This produced errors with MSVC C++ builds like:

C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\wspiapi.h(53):
error C2894: templates cannot be declared to have 'C' linkage
This generated code like:

        char *	filename;

	if (items < 3)
	    filename = "DynaLoader";
	else {
	    filename = (char *)SvPV_nolen(ST(2))

which failed in C++ builds (and isn't valid in C either), when
assigning a "const char *" (well, "const char [11]") to "char *".
C++ has a similar feature, but it has a different syntax, both
as of C++20 do support designated struct initializers.
C++ builds threw an error on these.
21060 also has this fix
Unfortunately this means older versions of MSVC that don't have
C++20 support can no longer build perl as C++.
…finition

This caused the link stage to fail with a C++ build, as the type
annotated C++ name was used for the definition rather than the
extern "C" name.
and note that only 2019 or later can build as C++, since the
use of designated initialisers means we need at least C++20 and
only 2019 and 2022 support that.

"cl /?" for 2019 doesn't list "-std:c++20" as an option at least of
19.29.30148, but it does accept it.
clang-16 rejects this, MSVC warns about it.

Part of fixing Perl#21073
clang++ complains about this.

The replacement prevents the warning and should be back-compatible.
for the C++ compatibility changes.

I also need to bump some cpan/ but we don't own those, so I'll
do it separately.
since we don't own it, and mark it as customized
since we don't own it, and mark the customized files.
since we don't own it, and mark the modified files customized
since we don't own it, and mark the modified files as customized
since we don't own it, and mark the modified files as customized
@Leont
Copy link
Contributor

Leont commented May 23, 2023

Marked this as a release blocker AFAIK this fixes recent build regressions, but it that happened longer ago then arguably it should not block release.

@Leont Leont merged commit fbcc226 into Perl:blead May 24, 2023
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

C++ builds fail with modern C++ compilers
4 participants