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

False positive lifetime GSL warning for no-capture lambda? #126600

Open
smeenai opened this issue Feb 10, 2025 · 0 comments
Open

False positive lifetime GSL warning for no-capture lambda? #126600

smeenai opened this issue Feb 10, 2025 · 0 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer false-positive Warning fires when it should not

Comments

@smeenai
Copy link
Collaborator

smeenai commented Feb 10, 2025

For the code in https://godbolt.org/z/v919qqe6o:

struct [[gsl::Pointer]] function_ref {
  template <typename Callable>
  function_ref(Callable &&callable [[clang::lifetimebound]]) : ref(callable) {}
  void (*ref)();
};

void f();
void g(function_ref &r) {
  r = []() { f(); };
}

Clang trunk produces a warning:

warning: object backing the pointer r will be destroyed at the end of the full-expression [-Wdangling-assignment-gsl]
    9 |   r = []() { f(); };

Clang seems to consider the no-capture lambda as a temporary that will be destroyed at the end of the expression. I'm not a standards expert and I haven't found anything definitive through searching, but in practice no-capture lambdas will turn into ordinary functions, so there's no actual issue here. Should we actually be warning for this?

a3b4d91 is a commit that ran into this and changed the code slightly to avoid it (the code change made there would result in a stack-use-after-free were this an actual issue, but it avoids the warning). #126140 is a high-firing instance of this warning, and we'd appreciate some guidance.

@smeenai smeenai added the clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer label Feb 10, 2025
smeenai added a commit to smeenai/llvm-project that referenced this issue Feb 10, 2025
This warning is causing lots of build spam when I use a recent Clang as
my host compiler. It's a potential false positive, so silence it until
llvm#126600 is resolved.
@EugeneZelenko EugeneZelenko added the false-positive Warning fires when it should not label Feb 10, 2025
smeenai added a commit that referenced this issue Feb 11, 2025
This warning is causing lots of build spam when I use a recent Clang as
my host compiler. It's a potential false positive, so silence it until
#126600 is resolved.
Fix variable casing while I'm here.
github-actions bot pushed a commit to arm/arm-toolchain that referenced this issue Feb 11, 2025
…rt.h (#126140)

This warning is causing lots of build spam when I use a recent Clang as
my host compiler. It's a potential false positive, so silence it until
llvm/llvm-project#126600 is resolved.
Fix variable casing while I'm here.
Icohedron pushed a commit to Icohedron/llvm-project that referenced this issue Feb 11, 2025
…126140)

This warning is causing lots of build spam when I use a recent Clang as
my host compiler. It's a potential false positive, so silence it until
llvm#126600 is resolved.
Fix variable casing while I'm here.
alejandro-alvarez-sonarsource pushed a commit to alejandro-alvarez-sonarsource/llvm-project that referenced this issue Feb 12, 2025
…126140)

This warning is causing lots of build spam when I use a recent Clang as
my host compiler. It's a potential false positive, so silence it until
llvm#126600 is resolved.
Fix variable casing while I'm here.
flovent pushed a commit to flovent/llvm-project that referenced this issue Feb 13, 2025
…126140)

This warning is causing lots of build spam when I use a recent Clang as
my host compiler. It's a potential false positive, so silence it until
llvm#126600 is resolved.
Fix variable casing while I'm here.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this issue Feb 14, 2025
…126140)

This warning is causing lots of build spam when I use a recent Clang as
my host compiler. It's a potential false positive, so silence it until
llvm#126600 is resolved.
Fix variable casing while I'm here.
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 false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

2 participants