Skip to content

[C++20] Remove u8 string literal prefixes. #67707

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
merged 1 commit into from
Aug 6, 2023

Conversation

allevato
Copy link
Member

@allevato allevato commented Aug 3, 2023

In C++20, u8 literals create values of type char8_t[] instead of char[], and these can't be implicitly converted.

Plan: Try just removing them first to see if any of our CI environments complain with un-prefixed Unicode strings. If they do, we can try introducing a macro that expands to u8 for C++<20 and to nothing for C++≥20. In some hypothetical future when everything is built in C++20 mode, we would want to address the usages then by explicitly using char8_t where needed.

@allevato
Copy link
Member Author

allevato commented Aug 3, 2023

@swift-ci please test

@allevato
Copy link
Member Author

allevato commented Aug 4, 2023

@swift-ci Please test Linux platform

@allevato
Copy link
Member Author

allevato commented Aug 4, 2023

@swift-ci Please test Windows platform

1 similar comment
@allevato
Copy link
Member Author

allevato commented Aug 4, 2023

@swift-ci Please test Windows platform

@allevato
Copy link
Member Author

allevato commented Aug 4, 2023

Looks like removing u8 entirely breaks Windows (note the mojibake where the tau should be in the SIL function signature):

C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Serialization\generic_extension.swift:12:11: error: CHECK: expected string not found in input
// CHECK: sil @$sSa19generic_extension_1E6wobble{{[_0-9a-zA-Z]*}}F : $@convention(method) <τ_0_0> (@guaranteed Array<τ_0_0>) -> @out Optional<τ_0_0>
<stdin>:1:1: note: scanning from here
sil_stage canonical
^
<stdin>:56:17: note: possible intended match here
 %36 = function_ref @$sSa19generic_extension_1E6wobblexSgyF : $@convention(method) <?_0_0> (@guaranteed Array<?_0_0>) -> @out Optional<?_0_0> // user: %37
                ^

In C++20, `u8` literals create values of type `char8_t` instead of
`char`, and these can't be implicitly converted. This macro
mitigates the difference and allows the same code to compile under
C++14/17 modes and C++20, preserving the `char` type while ensuring
that the text is interpreted as UTF-8.
@allevato
Copy link
Member Author

allevato commented Aug 4, 2023

The macro magic was needed after all. This introduces a SWIFT_UTF8("...") macro that should be used in lieu of direct u8"..." literals.

@allevato
Copy link
Member Author

allevato commented Aug 4, 2023

@swift-ci please test

@allevato allevato merged commit b2fd3eb into swiftlang:main Aug 6, 2023
@allevato allevato deleted the no-u8-prefixes branch August 7, 2023 12:23
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