[clang] [Clang] Do not allow `[[clang::lifetimebound]]` on explicit object member functions (PR #96113)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 19 13:36:55 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Mital Ashok (MitalAshok)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/96113.diff
2 Files Affected:
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3-2)
- (modified) clang/lib/Sema/SemaDecl.cpp (+9-2)
``````````diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 14736784cff5f..4ea1d730e3a16 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9999,8 +9999,9 @@ def warn_null_ret : Warning<
InGroup<NonNull>;
def err_lifetimebound_no_object_param : Error<
- "'lifetimebound' attribute cannot be applied; %select{static |non-}0member "
- "function has no implicit object parameter">;
+ "'lifetimebound' attribute cannot be applied; "
+ "%select{non-|static |explicit object }0"
+ "member function has no implicit object parameter">;
def err_lifetimebound_ctor_dtor : Error<
"'lifetimebound' attribute cannot be applied to a "
"%select{constructor|destructor}0">;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e28e5c56c11a7..58de57657c35a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7072,9 +7072,16 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
// by applying it to the function type.
if (const auto *A = ATL.getAttrAs<LifetimeBoundAttr>()) {
const auto *MD = dyn_cast<CXXMethodDecl>(FD);
- if (!MD || MD->isStatic()) {
+ int NoImplicitObjectError = -1;
+ if (!MD)
+ NoImplicitObjectError = 0;
+ else if (MD->isStatic())
+ NoImplicitObjectError = 1;
+ else if (MD->isExplicitObjectMemberFunction())
+ NoImplicitObjectError = 2;
+ if (NoImplicitObjectError != -1) {
S.Diag(A->getLocation(), diag::err_lifetimebound_no_object_param)
- << !MD << A->getRange();
+ << NoImplicitObjectError << A->getRange();
} else if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)) {
S.Diag(A->getLocation(), diag::err_lifetimebound_ctor_dtor)
<< isa<CXXDestructorDecl>(MD) << A->getRange();
``````````
</details>
https://github.com/llvm/llvm-project/pull/96113
More information about the cfe-commits
mailing list