[clang] [clang] Warn [[clang::lifetimebound]] misusages on types (PR #118281)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 2 05:52:07 PST 2024
================
@@ -9,11 +9,20 @@ namespace usage_invalid {
~A() [[clang::lifetimebound]]; // expected-error {{cannot be applied to a destructor}}
static int *static_class_member() [[clang::lifetimebound]]; // expected-error {{static member function has no implicit object parameter}}
int *explicit_object(this A&) [[clang::lifetimebound]]; // expected-error {{explicit object member function has no implicit object parameter}}
- int not_function [[clang::lifetimebound]]; // expected-error {{only applies to parameters and implicit object parameters}}
- int [[clang::lifetimebound]] also_not_function; // expected-error {{cannot be applied to types}}
+ int attr_on_var [[clang::lifetimebound]]; // expected-error {{only applies to parameters and implicit object parameters}}
+ int [[clang::lifetimebound]] attr_on_int; // expected-error {{cannot be applied to types}}
+ int * [[clang::lifetimebound]] attr_on_int_ptr; // expected-error {{cannot be applied to types}}
+ int * [[clang::lifetimebound]] * attr_on_int_ptr_ptr; // expected-error {{cannot be applied to types}}
+ int (* [[clang::lifetimebound]] attr_on_func_ptr)(); // expected-error {{cannot be applied to types}}
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)'}}
};
int *attr_with_param(int ¶m [[clang::lifetimebound(42)]]); // expected-error {{takes no arguments}}
----------------
ilya-biryukov wrote:
Could we add some tests for things that aren't working yet?
Now that we have a much wider coverage than before, it also makes more sense to list the cases we don't yet have covered. Some that come to mind are:
```cpp
// Uses in function types, but not on the functions declarations.
// We fail to diagnose those don't have "implicit object paramter".
int (*a)(int) [[clang::lifetimebound]];
int (*(*b)(int) [[clang::lifetimebound]])(int);
struct X{};
int (X::*c)(int) [[clang::lifetimebound]];
```
https://github.com/llvm/llvm-project/pull/118281
More information about the cfe-commits
mailing list