Skip to content

[[lifetimebound]] assignment seems to interfere with tracking #100746

Open
@DenisYaroshevskiy

Description

@DenisYaroshevskiy

The following example is not caught

#include <string>
#include <string_view>
#include <iostream>

struct S {
  std::string s;

  std::string_view f() const [[clang::lifetimebound]] {
    return s;
  }
};

void test() {
  std::string_view thisIsAnIssue;
  thisIsAnIssue = S{}.f();
  std::cout << thisIsAnIssue << std::endl;
}

https://godbolt.org/z/onnPjPo95

While this one is

void test() {
  std::string_view thisIsAnIssue = S{}.f();
  std::cout << thisIsAnIssue << std::endl;
}

https://godbolt.org/z/q57nhWYaT

Could they both be caught?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:memory-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)false-negative

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions