Skip to content

[Visual C++] Provide alternative to array designators. #28170

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

Merged

Conversation

drodriguez
Copy link
Contributor

Even if they are supported in GCC and Clang, C99 array designators are
not part of the current C++ standard (they will be in C++20), so they
are not supported in Visual C++.

This commit provides an alternative for Visual C++ (which should work in
other compilers) which doesn't use array designators.

I think Clang 10 will start printing a warning about this incorrect
usage.

Introduced in #28052 and started breaking Windows CI in https://ci-external.swift.org/job/oss-swift-windows-x86_64/1899 (it was broken before, but this error starts in that one).

@drodriguez
Copy link
Contributor Author

@swift-ci please smoke test

@drodriguez
Copy link
Contributor Author

@swift-ci Please test Windows platform

Copy link
Contributor

@owenv owenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I thought this was part of the standard. LGTM to fix the build, but maybe we should just use the fallback everywhere to ensure we stay C++ 14 compliant. I can do that in a follow-up if need be

@drodriguez
Copy link
Contributor Author

I will let the Windows PR testing finish with this code. I want to check that my local results are valid in the CI machine. I can remove the non-standard implementation and re-submit later with a comment about why the strange construct.

Also, if some C++ wizard knows a cleaner way to initialize a constexpr array, I would not mind learning about it.

@drodriguez drodriguez force-pushed the msc-alternative-to-array-designators branch from cbe9c10 to 14821c4 Compare November 9, 2019 02:16
@drodriguez
Copy link
Contributor Author

The Windows CI went beyond the failure point just fine. Re-submitted with the non-standard implementation removed.

@swift-ci please smoke test

@owenv
Copy link
Contributor

owenv commented Nov 9, 2019

It seem like Clang doesn't like this line:

/Users/buildnode/jenkins/workspace/swift-PR-osx-smoke-test/branch-master/swift/lib/AST/DiagnosticEngine.cpp:140:37: error: array initializer must be an initializer list
18:19:13 static constexpr const char *const *educationalNotes[LocalDiagID::NumDiags] = EducationalNotes<LocalDiagID::NumDiags>().value;
18:19:13                                     ^
18:19:13 1 error generated.

Trying to work around that issue I'm also running into issues with "pointer to subject of temporary is not constexpr". I'm going to prepare a revert of my patch just in case.

@owenv
Copy link
Contributor

owenv commented Nov 9, 2019

clang accepts

static constexpr EducationalNotes<LocalDiagID::NumDiags> _EducationalNotes = EducationalNotes<LocalDiagID::NumDiags>();
static constexpr auto educationalNotes = _EducationalNotes.value;

I'm not sure if MSVC will like that use of auto though...

@drodriguez
Copy link
Contributor Author

Gonna send that in a moment. I don't have the Windows machine at hand anymore, so I will trust that the CI will tell us if it works.

@drodriguez drodriguez force-pushed the msc-alternative-to-array-designators branch from 14821c4 to 9cd1611 Compare November 9, 2019 08:24
@drodriguez
Copy link
Contributor Author

@swift-ci please smoke test

@drodriguez
Copy link
Contributor Author

(I will go to bed, so anyone, feel free to merge if everything is green)

@swift-ci please test Windows platform

@drodriguez
Copy link
Contributor Author

https://ci-external.swift.org/view/Pull%20Request/job/swift-PR-windows/163/ is the CI job, but it haven't been linked to this PR for some reason.

Even if they are supported in GCC and Clang, C99 array designators are
not part of the current C++ standard (they will be in C++20), so they
are not supported in Visual C++.

This commit provides an alternative for Visual C++ (which should work in
other compilers) which doesn't use array designators.

I think Clang 10 will start printing a warning about this incorrect
usage.
@drodriguez drodriguez force-pushed the msc-alternative-to-array-designators branch from 9cd1611 to eb7a26d Compare November 9, 2019 16:55
@drodriguez
Copy link
Contributor Author

I should have copy/pasted the solution provided, not try to type it from memory. Sigh.

@swift-ci please smoke test

@drodriguez
Copy link
Contributor Author

drodriguez commented Nov 9, 2019

@swift-ci please test Windows platform

(https://ci-external.swift.org/view/Pull%20Request/job/swift-PR-windows/164/ because it doesn't seem to be linked)

@drodriguez
Copy link
Contributor Author

Merging this one. Seems to work OK in the three platforms.

@drodriguez drodriguez merged commit 6792e0b into swiftlang:master Nov 9, 2019
@drodriguez drodriguez deleted the msc-alternative-to-array-designators branch November 9, 2019 20:17
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

Successfully merging this pull request may close these issues.

2 participants