Skip to content

langref: mark unsafe builtin functions #14543

@perillo

Description

@perillo

Some builtin functions can cause undefined behavior or subvert the Zig type system.
I think these builtin functions should be clearly marked.

Here is a list, probably incomplete:

  • @addrSpaceCast
    The documentation says that the operation may be illegal. What is the difference from undefined behavior?
    There is no documentation in the "Undefined Behavior" section.
  • @ptrCast
    The documentation says:
    "Casting an optional pointer which is null to a non-optional pointer invokes safety-checked Undefined Behavior".
    An additional warning is in the "volatile" section:
    "To convert one pointer type to another, use @ptrCast. This is an unsafe operation that Zig cannot protect you against."
    This is also documented in the "Undefined Behavior" section.
  • @alignCast
    Incorrect alignment is also documented in "Undefined Behavior" section.
  • @qualCast
    Warning about unsafe behavior is missing.
    Undefined behavior caused by @qualCast should probably be added to the "Undefined Behavior".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions