diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-06 23:59:11 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-08 01:48:24 +0200 |
| commit | bbeebf636d496c9d5f7a270cb00465dabe87cae5 (patch) | |
| tree | 7281677cafbd9aee847c1d18cb318b4d270f7683 /parse.c | |
| parent | c9676a3b0349a1053c673243af52a2ef1b272bd7 (diff) | |
| download | sparse-dev-bbeebf636d496c9d5f7a270cb00465dabe87cae5.tar.gz | |
c2x: message in _Static_assert() is now optional
It seems that in the next version of the standard, the
second argument of _Static_assert() will be optional.
Nice. Let sparse already support this now.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'parse.c')
| -rw-r--r-- | parse.c | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -2223,17 +2223,25 @@ static struct token *parse_static_assert(struct token *token, struct symbol_list token = constant_expression(token, &cond); if (!cond) sparse_error(token->pos, "Expected constant expression"); - token = expect(token, ',', "after conditional expression in _Static_assert"); - token = string_expression(token, &message, "_Static_assert()"); - if (!message) - cond = NULL; + if (match_op(token, ',')) { + token = token->next; + token = string_expression(token, &message, "_Static_assert()"); + if (!message) + cond = NULL; + } token = expect(token, ')', "after diagnostic message in _Static_assert"); - token = expect(token, ';', "after _Static_assert()"); - if (cond && !const_expression_value(cond) && cond->type == EXPR_VALUE) - sparse_error(cond->pos, "static assertion failed: %s", - show_string(message->string)); + if (cond && !const_expression_value(cond) && cond->type == EXPR_VALUE) { + const char *sep = "", *msg = ""; + + if (message) { + sep = ": "; + msg = show_string(message->string); + } + sparse_error(cond->pos, "static assertion failed%s%s", sep, msg); + } + return token; } |
