Skip to content

Commit 780041a

Browse files
authored
[C] Add support for static_assert and its aliases (#4073)
This was first added in C11 but has since been revised by C23. It functions like sizeof in that it takes an argument as if it were a function so we implement it as an extension of sizeof.
1 parent ddfeab9 commit 780041a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

C++/C.sublime-syntax

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ variables:
4848
type_qualifier: 'const|volatile'
4949
compiler_directive: 'inline|restrict|__restrict__|__restrict'
5050
modifiers: '{{storage_classes}}|{{type_qualifier}}|{{compiler_directive}}'
51-
non_func_keywords: 'if|for|switch|while|decltype|typeof|typeof_unqual|sizeof|__declspec|__attribute__'
51+
non_func_keywords: 'if|for|switch|while|decltype|typeof|typeof_unqual|sizeof|static_assert|_Static_assert|__declspec|__attribute__'
5252

5353
contexts:
5454
main:
@@ -197,7 +197,7 @@ contexts:
197197
scope: keyword.control.flow.return.c
198198
- match: \b({{control_keywords}})\b
199199
scope: keyword.control.c
200-
- match: \bsizeof\b
200+
- match: \b(sizeof|static_assert|_Static_assert)\b
201201
scope: keyword.operator.word.c
202202

203203
modifiers:

C++/syntax_test_c.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ typeof_unqual(i) dt;
218218
/* ^ punctuation.section.group.begin */
219219
/* ^ punctuation.section.group.end */
220220

221+
static_assert(sizeof(int) == 4);
222+
/* <- keyword.operator.word */
223+
224+
_Static_assert(sizeof(int) == 4);
225+
/* <- keyword.operator.word */
226+
221227
void build_default_prototype(Function *ret) {
222228
static typeof(*ret->params) params[4];
223229
/* <- keyword.declaration.type */

0 commit comments

Comments
 (0)