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

[SR-11292] A Character.init doesn't trap like it should iff using -O #53693

Open
jepers opened this issue Aug 10, 2019 · 1 comment
Open

[SR-11292] A Character.init doesn't trap like it should iff using -O #53693

jepers opened this issue Aug 10, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@jepers
Copy link

jepers commented Aug 10, 2019

Previous ID SR-11292
Radar None
Original Reporter @jepers
Type Bug
Environment

Xcode 10.3 (10G8)
macOS 10.14.6 (18G87)

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: d57ea084c81a5db011837f59b17e347a

Issue Description:

See this forum post:
https://forums.swift.org/t/is-this-a-character-bug/27622/8
and the attached Xcode project.

(EDIT: Never mind the attached project, the bug is easily demonstrated by the example in the forum post. I've now deleted the attachment to prevent unnecessary confusion.)

In short, if compiling with optimizations enabled, the following Character initializer will not trap (as it should) when the given string is invalid (ie the string does not hold exactly one extended grapheme cluster).

    /// Creates a character from a single-character string.
    ///
    /// The following example creates a new character from the uppercase version
    /// of a string that only holds one character.
    ///
    ///     let a = "a"
    ///     let capitalA = Character(a.uppercased())
    ///
    /// - Parameter s: The single-character string to convert to a `Character`
    ///   instance. `s` must contain exactly one extended grapheme cluster.
    @inlinable public init(_ s: String)

The result is that very strange Character instances can be created without any notice.

@belkadan
Copy link
Contributor

cc @milseman

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants