Skip to content

Diagnose dangling issues on member field access #120543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hokein opened this issue Dec 19, 2024 · 0 comments · Fixed by #122088
Closed

Diagnose dangling issues on member field access #120543

hokein opened this issue Dec 19, 2024 · 0 comments · Fixed by #122088
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer clang:memory-safety Issue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)

Comments

@hokein
Copy link
Collaborator

hokein commented Dec 19, 2024

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.
}
@hokein hokein added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer clang:memory-safety Issue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr) labels Dec 19, 2024
hokein added a commit that referenced this issue Jan 22, 2025
…inter (#122088)

We currently have ad-hoc filtering logic for temporary object member
access in `VisitGSLPointerArg`. This logic filters out more cases than
it should, leading to false negatives. Furthermore, this location lacks
sufficient context to implement a more accurate solution.

This patch refines the filtering logic by moving it to the central
filtering location, `analyzePathForGSLPointer`, consolidating the logic
and avoiding scattered filtering across multiple places. As a result,
the special handling for conditional operators (#120233) is no longer
necessary.

This change also resolves #120543.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer clang:memory-safety Issue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant