Skip to content

Commit 356df2d

Browse files
committed
Revert "[clang] Warn [[clang::lifetimebound]] misusages on types (#118281)"
Temporarily revert the patch to give downstream teams some time to clean up their codebases. This reverts commit 4849d59.
1 parent f4ce7e0 commit 356df2d

File tree

3 files changed

+3
-36
lines changed

3 files changed

+3
-36
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ C++ Specific Potentially Breaking Changes
139139
// Fixed version:
140140
unsigned operator""_udl_name(unsigned long long);
141141

142-
- Clang will now produce an error diagnostic when ``[[clang::lifetimebound]]`` is
142+
- Clang will now produce an error diagnostic when [[clang::lifetimebound]] is
143143
applied on a parameter or an implicit object parameter of a function that
144144
returns void. This was previously ignored and had no effect. (#GH107556)
145145

@@ -148,21 +148,6 @@ C++ Specific Potentially Breaking Changes
148148
// Now diagnoses with an error.
149149
void f(int& i [[clang::lifetimebound]]);
150150

151-
- Clang will now produce an error diagnostic when ``[[clang::lifetimebound]]``
152-
is applied on a type (instead of a function parameter or an implicit object
153-
parameter); this includes the case when the attribute is specified for an
154-
unnamed function parameter. These were previously ignored and had no effect.
155-
(#GH118281)
156-
157-
.. code-block:: c++
158-
159-
// Now diagnoses with an error.
160-
int* [[clang::lifetimebound]] x;
161-
// Now diagnoses with an error.
162-
void f(int* [[clang::lifetimebound]] i);
163-
// Now diagnoses with an error.
164-
void g(int* [[clang::lifetimebound]]);
165-
166151
- Clang now rejects all field accesses on null pointers in constant expressions. The following code
167152
used to work but will now be rejected:
168153

clang/lib/Sema/SemaType.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8612,11 +8612,7 @@ static void HandleLifetimeBoundAttr(TypeProcessingState &State,
86128612
CurType = State.getAttributedType(
86138613
createSimpleAttr<LifetimeBoundAttr>(State.getSema().Context, Attr),
86148614
CurType, CurType);
8615-
return;
86168615
}
8617-
State.getSema().Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type_str)
8618-
<< Attr << Attr.isRegularKeywordAttribute()
8619-
<< "parameters and implicit object parameters";
86208616
}
86218617

86228618
static void HandleLifetimeCaptureByAttr(TypeProcessingState &State,

clang/test/SemaCXX/attr-lifetimebound.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,11 @@ namespace usage_invalid {
99
~A() [[clang::lifetimebound]]; // expected-error {{cannot be applied to a destructor}}
1010
static int *static_class_member() [[clang::lifetimebound]]; // expected-error {{static member function has no implicit object parameter}}
1111
int *explicit_object(this A&) [[clang::lifetimebound]]; // expected-error {{explicit object member function has no implicit object parameter}}
12-
int attr_on_var [[clang::lifetimebound]]; // expected-error {{only applies to parameters and implicit object parameters}}
13-
int [[clang::lifetimebound]] attr_on_int; // expected-error {{cannot be applied to types}}
14-
int * [[clang::lifetimebound]] attr_on_int_ptr; // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}}
15-
int * [[clang::lifetimebound]] * attr_on_int_ptr_ptr; // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}}
16-
int (* [[clang::lifetimebound]] attr_on_func_ptr)(); // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}}
12+
int not_function [[clang::lifetimebound]]; // expected-error {{only applies to parameters and implicit object parameters}}
13+
int [[clang::lifetimebound]] also_not_function; // expected-error {{cannot be applied to types}}
1714
void void_return_member() [[clang::lifetimebound]]; // expected-error {{'lifetimebound' attribute cannot be applied to an implicit object parameter of a function that returns void; did you mean 'lifetime_capture_by(X)'}}
1815
};
1916
int *attr_with_param(int &param [[clang::lifetimebound(42)]]); // expected-error {{takes no arguments}}
20-
21-
void attr_on_ptr_arg(int * [[clang::lifetimebound]] ptr); // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}}
22-
static_assert((int [[clang::lifetimebound]]) 12); // expected-error {{cannot be applied to types}}
23-
int* attr_on_unnamed_arg(const int& [[clang::lifetimebound]]); // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}}
24-
template <typename T>
25-
int* attr_on_template_ptr_arg(T * [[clang::lifetimebound]] ptr); // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}}
26-
27-
int (*func_ptr)(int) [[clang::lifetimebound]]; // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}}
28-
int (*(*func_ptr_ptr)(int) [[clang::lifetimebound]])(int); // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}}
29-
struct X {};
30-
int (X::*member_func_ptr)(int) [[clang::lifetimebound]]; // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}}
3117
}
3218

3319
namespace usage_ok {

0 commit comments

Comments
 (0)