-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Do not infer lifetimebound for functions with void return type #131997
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
Conversation
@llvm/pr-subscribers-clang Author: Utkarsh Saxena (usx95) ChangesFull diff: https://github.com/llvm/llvm-project/pull/131997.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index defdda17c32de..a6e827a421134 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -217,7 +217,7 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl *Record) {
}
void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
- if (FD->getNumParams() == 0)
+ if (FD->getNumParams() == 0 || FD->getReturnType()->isVoidType())
return;
if (unsigned BuiltinID = FD->getBuiltinID()) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have have a test for it. I think it should not be too hard to add one.
LGTM! I am not sure why lifetimebound needs to be an error while other attributes like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seem to be some errors missing the attribute tests now (see buildkite failures)
@usx95 I struggled to come up with a reproducer and couldn't understand why at first. https://gcc.godbolt.org/z/Wf3eqMabE // RUN: %clang_cc1 -std=c++20 -verify %s
namespace std {
template <class T>
constexpr const T& as_const(T&) noexcept;
// We need two declarations to see the error for some reason *shrug*
template <class T> void as_const(const T&&) noexcept = delete;
template <class T> void as_const(const T&&) noexcept;
}
namespace GH126231 {
void test() {
int a = 1;
std::as_const(a);
}
}
|
aeff21a
to
052bc3f
Compare
/cherry-pick 65ee281 |
/pull-request #133997 |
llvm#131997) Fixes: llvm#126231 Also found in : microsoft/STL#5271 (cherry picked from commit 65ee281)
Fixes: #126231
Also found in : microsoft/STL#5271