Skip to content

Diagnose dangling issues on member field access #120543

Closed
@hokein

Description

@hokein

We have some supports in member field access for references (#81589). It would be good to diagnose on the view types, see https://godbolt.org/z/zbx8hPera

#include <string_view>
#include <string>

struct S2 {
  std::string s2;
};
struct Q3 {
  const S2* get() const [[clang::lifetimebound]];
};
void test() {
  auto& t = Q3().get()->s2; //dangling, clang diagnoses it.
  std::string_view v = Q3().get()->s2; // dangling, clang doesn't diagnose it, bad.
}

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)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions