Skip to content

-Wconsumed is ignored on destructors #138890

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

Open
apache-hb opened this issue May 7, 2025 · 4 comments
Open

-Wconsumed is ignored on destructors #138890

apache-hb opened this issue May 7, 2025 · 4 comments
Labels
c++ clang:analysis clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@apache-hb
Copy link

In this example the destructor is marked [[clang::callable_when(consumed)]], and the constructor is marked with [[clang::return_typestate(unconsumed)]]. Despite this there is no warning issued when the destructor is reached on an unconsumed instance of IplTag

@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels May 7, 2025
@apache-hb
Copy link
Author

The warning is correctly produced when the destructor of IplTag is not trivial godbolt

@AaronBallman AaronBallman added c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party and removed clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer labels May 7, 2025
@llvmbot
Copy link
Member

llvmbot commented May 7, 2025

@llvm/issue-subscribers-c-1

Author: Elliot (apache-hb)

In [this example](https://godbolt.org/z/o54sjPjGs) the destructor is marked `[[clang::callable_when(consumed)]]`, and the constructor is marked with `[[clang::return_typestate(unconsumed)]]`. Despite this there is no warning issued when the destructor is reached on an unconsumed instance of `IplTag`

@llvmbot
Copy link
Member

llvmbot commented May 7, 2025

@llvm/issue-subscribers-clang-frontend

Author: Elliot (apache-hb)

In [this example](https://godbolt.org/z/o54sjPjGs) the destructor is marked `[[clang::callable_when(consumed)]]`, and the constructor is marked with `[[clang::return_typestate(unconsumed)]]`. Despite this there is no warning issued when the destructor is reached on an unconsumed instance of `IplTag`

@AaronBallman
Copy link
Collaborator

I looked into this briefly and I think the issue is that the CFG does not model a defaulted destructor correctly. I think CFGBuilder::hasTrivialDestructor() needs to be updated so that !CD->hasDefinition() || CD->hasTrivialDestructor() also looks to see if the destructor has attributes written on it, because some attributes may mean "yes this is trivial but it still has control flow effects". But I'm not 100% sure. CC @gribozavr @ymand @sgatev for additional opinions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ clang:analysis clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

4 participants