Skip to content

Commit 4a10adf

Browse files
committed
[Clang] Do not allow [[clang::lifetime_bound]] on explicit object member functions
1 parent f991ebb commit 4a10adf

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9999,8 +9999,9 @@ def warn_null_ret : Warning<
99999999
InGroup<NonNull>;
1000010000

1000110001
def err_lifetimebound_no_object_param : Error<
10002-
"'lifetimebound' attribute cannot be applied; %select{static |non-}0member "
10003-
"function has no implicit object parameter">;
10002+
"'lifetimebound' attribute cannot be applied; "
10003+
"%select{non-|static |explicit object }0"
10004+
"member function has no implicit object parameter">;
1000410005
def err_lifetimebound_ctor_dtor : Error<
1000510006
"'lifetimebound' attribute cannot be applied to a "
1000610007
"%select{constructor|destructor}0">;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7072,9 +7072,16 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
70727072
// by applying it to the function type.
70737073
if (const auto *A = ATL.getAttrAs<LifetimeBoundAttr>()) {
70747074
const auto *MD = dyn_cast<CXXMethodDecl>(FD);
7075-
if (!MD || MD->isStatic()) {
7075+
int NoImplicitObjectError = -1;
7076+
if (!MD)
7077+
NoImplicitObjectError = 0;
7078+
else if (MD->isStatic())
7079+
NoImplicitObjectError = 1;
7080+
else if (MD->isExplicitObjectMemberFunction())
7081+
NoImplicitObjectError = 2;
7082+
if (NoImplicitObjectError != -1) {
70767083
S.Diag(A->getLocation(), diag::err_lifetimebound_no_object_param)
7077-
<< !MD << A->getRange();
7084+
<< NoImplicitObjectError << A->getRange();
70787085
} else if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)) {
70797086
S.Diag(A->getLocation(), diag::err_lifetimebound_ctor_dtor)
70807087
<< isa<CXXDestructorDecl>(MD) << A->getRange();

0 commit comments

Comments
 (0)