Skip to content
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

No dangling assignment involving lifetimebound argument #112234

Open
usx95 opened this issue Oct 14, 2024 · 5 comments
Open

No dangling assignment involving lifetimebound argument #112234

usx95 opened this issue Oct 14, 2024 · 5 comments
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

@usx95
Copy link
Contributor

usx95 commented Oct 14, 2024

https://godbolt.org/z/oedcc359z

struct S { int *x; };

S foo(const int &x [[clang::lifetimebound]]);

void usage() {
    S y = foo(1);  // Warning. Good.
    y = foo(1);    // No warning. Bad.
}
@usx95 usx95 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 Oct 14, 2024
@higher-performance
Copy link
Contributor

I think I'm confused. Neither of those warn for me, but should they? They do warn if the return type is a reference or a pointer, but not if it's an integer.

@usx95
Copy link
Contributor Author

usx95 commented Oct 14, 2024

Modified the example for a better example. Basically we should warn in all cases because "lifetimebound" means we return an entity which refers to the arg. It does not have to be that we return the same reference as we accept.

@higher-performance
Copy link
Contributor

Yeah makes sense, I agree, thanks!

@higher-performance
Copy link
Contributor

I think #112614 should fix this.

@usx95
Copy link
Contributor Author

usx95 commented Oct 16, 2024

Copying relevant text from comment on PR:

We already do a good job when GSL pointers and lifetimebound interact as in the bug: https://godbolt.org/z/9M9PsEGs7

I feel we need to fix the analysis for assignment operator here which would fix cases beyond std::string_view.
cc: @Xazax-hun @hokein

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.

2 participants