================
@@ -11,6 +11,11 @@ struct S {
void h(const char*) __attribute__((nonnull(1))); // \
expected-error{{invalid for the implicit this argument}}
+
+ void i(this S* self, const char*) __attribute__((nonnull(1)));
+
+ void j(this S* self, const char*) __attribute__((nonnull(3))); // \
+ expected-error{{'nonnull' attribute parameter 1 is out of bounds}}
----------------
Sirraide wrote:
> Do you mean something like this:
>
> ```c++
> void k(this S* self, const char*) __attribute__((nonnull(2, 3))); // \
> expected-error{{'nonnull' attribute parameter 2 is out of bounds}}
> ```
No, I meant
```
void k(this S* self, const char*) __attribute__((nonnull(2))); // No diagnostic
```
> All indexes for `nonnull` are treated the same, so it works as param index 1.
That’s assuming we don’t have an off-by-one error in the index, which is what
the test is for ;Þ
> Also, what do you suggest the diagnostic message for this should be:
>
> ```c++
> void i(this S* self, const char*) __attribute__((nonnull(1)));
> ```
>
> It it had an implicit 'this', it would emit "'nonnull' attribute is invalid
> for the implicit this argument". Should I change it to something like
> "'nonnull' attribute is invalid for the 'this' argument".
I don’t think it makes sense to disallow `nonnull` for explicit object
parameters; to my understanding, something like this would be valid, if a bit
weird:
```
struct S {
void f(this auto int* x);
operator int*() { return nullptr; }
};
```
void f() {
S().f(); // Weird, but ok.
}
https://github.com/llvm/llvm-project/pull/165586
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits