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 11:57 AM, Lance Richardson <lrichard@xxxxxxxxxx> wrote:
>
> Hi Chris and Luc,
>
> Thank you very much for your feedback and your patience with this series.
>
> I think if the standard allows mixing static assertions with code, sparse should
> also allow it (as both gcc and clang do).
>
> At least gcc does abide by the "static assertions are declarations" idea, e.g.:
>
>     $ gcc -c -Wdeclaration-after-statement moo.c
>     moo.c: In function ‘foo’:
>     moo.c:11:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
>       _Static_assert(1, "");
>       ^~~~~~~~~~~~~~

OK. Luc and you have a good point there. So that warning is too strong.

In your V5 patch.

@@ -2436,11 +2483,14 @@ static struct token * statement_list(struct
token *token, struct statement_list
  }
  stmt = alloc_statement(token->pos, STMT_DECLARATION);
  token = external_declaration(token, &stmt->declaration);
+ add_statement(list, stmt);
+ } else if (match_static_assert(token)) {
+ token = parse_static_assert(token, NULL);
  } else {
  seen_statement = Wdeclarationafterstatement;
  token = statement(token, &stmt);
+ add_statement(list, stmt);
  }
- add_statement(list, stmt);
  }
  return token;
 }

We don't need to relocate add_statment() into two places. We can add a
"continue"
after the static_assert() parsing.

> It doesn't appear to be possible to do a similar experiment with clang, in that
> case the "ISO C90 forbids mixed declarations and code" warning is only emitted
> with "-pedantic C90" or "-pedantic C89", and another warning is produced if
> _Static_assert() is used with those options:
>
>    warning: _Static_assert is a C11-specific feature [-Wc11-extensions]
>
> I would be happy to respin, taking the responses to the v5 patch as feedback.

That would be great. Looking forward to it. While you are there, can you make
it apply to master or sparse-next? I have update the master recently the V5
does not apply clean on master any more. It is trivial to fix though.

Chris
--
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