Re: [PATCH 16/19] Documentation: rust: add coding guidelines on lints
From: comex
Date: Sat Sep 07 2024 - 18:23:31 EST
> On Sep 5, 2024, at 2:45 AM, Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx> wrote:
>
> On Thu, Sep 5, 2024 at 10:16 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>>
>> Wow, does C really not have an easier way to do it?
>
> Yeah, it would be nice to get a similar system in C.
>
> There are targeted attributes that can annotate certain things, like
> `[[maybe_unused]]` in C23 (and vendor attributes too like our
> `__maybe_unused` macro), so `-Wunused-function` is not really the best
> example in that sense -- I will think of a better one (it was nice to
> use the same as in the other examples I wrote for `expect` later on,
> which is why I used it).
>
> But, as far as I am aware, there is no way to handle lints (and levels
> and so on) in a simple and consistent way like Rust does.
You can always hide the pragmas behind a macro:
https://gcc.godbolt.org/z/WTEaYWW8c
It’s not perfect, because warning names sometimes differ between GCC and Clang, among other reasons.