aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-07-14 22:03:21 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-07-14 22:03:21 +0200
commit5db5a165533744781180ccea6d6150264e5b565c (patch)
treeaf7e6c1a5d8b30a0d2dd33786b998e41a19cb547
parenta1fdab3688708c5ac2b4ae68bf920961355dc2de (diff)
parentbbeebf636d496c9d5f7a270cb00465dabe87cae5 (diff)
downloadsparse-5db5a165533744781180ccea6d6150264e5b565c.tar.gz
Merge branch 'assert-opt-msg'
-rw-r--r--parse.c24
-rw-r--r--validation/static_assert.c5
2 files changed, 21 insertions, 8 deletions
diff --git a/parse.c b/parse.c
index a9222e7c..bd8989ca 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
}
diff --git a/validation/static_assert.c b/validation/static_assert.c
index dd5e0c08..0ab5844e 100644
--- a/validation/static_assert.c
+++ b/validation/static_assert.c
@@ -53,6 +53,10 @@ _Static_assert(1, );
_Static_assert(, "");
_Static_assert(,);
+// C2x's version: without message
+_Static_assert(1);
+_Static_assert(0);
+
/*
* check-name: static assertion
*
@@ -67,5 +71,6 @@ static_assert.c:52:19: error: string literal expected for _Static_assert()
static_assert.c:53:16: error: Expected constant expression
static_assert.c:54:16: error: Expected constant expression
static_assert.c:54:17: error: string literal expected for _Static_assert()
+static_assert.c:58:16: error: static assertion failed
* check-error-end
*/