linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Christopher Li <sparse@chrisli.org>
Cc: Lance Richardson <lrichard@redhat.com>,
	Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH v5] sparse: add support for _Static_assert
Date: Sun, 7 May 2017 05:51:26 +0200	[thread overview]
Message-ID: <CAMHZB6E3z2mzA_PM_fQZ9o=gBPFb8i17G=PpdfNAOvicE_c9_A@mail.gmail.com> (raw)
In-Reply-To: <CANeU7QnoXnsY-dMC+Rcm4YmgfzjP9F4OoKfJ7FGnbmSctmLR5w@mail.gmail.com>

On Sun, May 7, 2017 at 2:24 AM, Christopher Li <sparse@chrisli.org> wrote:
> On Sat, May 6, 2017 at 7:11 PM, Luc Van Oostenryck
> <luc.vanoostenryck@gmail.com> 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

  reply	other threads:[~2017-05-07 22:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-04 16:00 [PATCH v5] sparse: add support for _Static_assert Lance Richardson
2017-05-04 19:18 ` Luc Van Oostenryck
2017-05-06 20:22 ` Christopher Li
2017-05-06 23:11   ` Luc Van Oostenryck
2017-05-07  0:24     ` Christopher Li
2017-05-07  3:51       ` Luc Van Oostenryck [this message]
2017-05-07 15:57         ` Lance Richardson
2017-05-07 17:34           ` Christopher Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMHZB6E3z2mzA_PM_fQZ9o=gBPFb8i17G=PpdfNAOvicE_c9_A@mail.gmail.com' \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=lrichard@redhat.com \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).