Re: [PATCH v5] sparse: add support for _Static_assert

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, May 7, 2017 at 2:24 AM, Christopher Li <sparse@xxxxxxxxxxx> wrote:
> On Sat, May 6, 2017 at 7:11 PM, Luc Van Oostenryck
> <luc.vanoostenryck@xxxxxxxxx> wrote:
>>
>>> @@ -2093,6 +2107,40 @@ static struct token *parse_asm_declarator(struct token *token, struct decl_state
>>> +
>>> +static struct token *parse_static_assert(struct token *token, struct symbol_list **unused)
>>> +{
>>> +     struct expression *cond = NULL, *fail_string = NULL;
>>> +     int val;
>>> +
>>> +     token = expect(token->next, '(', "after _Static_assert");
>>> +     token = constant_expression(token, &cond);
>>> +     if (!cond)
>>> +             sparse_error(token->pos, "expect expression before '%s' token", show_token(token));
>>
>> I would prefer to put this validation after the parsing
>> rather than in the middle but it's a detail.
>
> It can be done but there will be more bookkeeping of the token->pos.
> We need to remember which token is the one the error happening.

Ah yes, indeed.
Better to left it there then.

>>     - you will have a warning 'Expected ; at the end of type declaration'
>>       for something that nobody will consider to be a declaration
>>       (well ok, nobody but the ones that read such details in the
>>       C grammar).
> If it is only the "type" declaration you are complain about.
> We should be able to make it emit "static assert" declaration.
> I will see if I can make it better.

No, it's not with "type" that I have a problem but with "declaration".
As I tried to say above: "how many developers will consider the
static assertions as a declaration?"

> I think static assert *should not* consider as statements.
> It is wrong in may levels.
>
> It is clear that the stander consider static assert as declaration:
>     declaration:
>         <declaration-specifiers> <init-declarator-list>[opt] ;
>         <static_assert-declaration>

I don't think this is relevant here.
Yes, in the grammar of the C11 standard static assert is a kind of
declaration. And then?

> I think it is bad mixing the static assert inside statements.
> <statement>
> _Static_assert();
> <statement>
>
> It give the impression the static assert look like a function call.
How is that relevant?
Will this make it look less like a function call:
    int a;
    static_assert(..., ...);
    some_function_call();

> I see nothing wrong complain about this because stander clearly
> state static assert as declaration, for a reason.

The standard has its reasons that don't always match ours.
It's sparse's "raison d'être" to make different choices than the standard.

And for the standard, the whole point is moot anyway since
it allows to freely mix declarations and statements.

Thus the only points that matter are:
- will people want to use static assertions in the middle of statements
  and still would receive a warning when true declarations are mixed
  with statements?
- does code already exists where static assertions are in the middle
  of statements while true declarations are not welcomed there?
- how hard i sit really to add an option to allow one or the other behaviour?

-- Luc
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux