Skip to content

Lifetime-bound annotations for methods returning pointers to internal buffers #45

@dpogue

Description

@dpogue

https://lemire.me/blog/2024/07/26/safer-code-in-c-with-lifetime-bounds/

Some newer versions of clang support annotating methods with an attribute that indicates they return data whose lifetime is bound to the containing object instance, and that holding pointers to such data is not safe if those pointers will outlive the object.

In string_theory, I believe that would be the case for the c_str() and data() methods on char buffers, and also c_str() on ST::string (and probably others but those were the obvious ones that came to mind).

It might be worth adding those annotations (conditionally when using a compiler that supports them).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions