Skip to content

Suggest and infer lifetime annotations (workstream 4) #169375

@usx95

Description

@usx95

The idea is to use the lifetime analysis to conclude which parameters escape via return and can be annotated via [[clang::lifetimebound]].

std::string_view Select(bool cond, std::string_view a, std::string_view b) {
  if (cond)
    return a;
  else
    return b;
} 

We can implement this as a clang warning:

std::string_view Select(bool cond, std::string_view a, std::string_view b)
                                   ^^^^^^^^^^^^^ warning: param should be marked [[clang::lifetimebound]]
                                                       ^^^^^^^^^^^^^ warning: param should be marked [[clang::lifetimebound]]

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions