Commit ce1f87a
committed
MP_STATIC_ASSERT: Use _Static_assert.
.. or c++ static_assert where possible.
For the same reasons that C++ has trouble with "nonconstexpr"
static assertions, _Static_assert rejects such expression as well.
So, fall back to the old sizeof-array based implementation in that
case.
When _Static_assert can be used, the diagnostic quality is improved:
```
../py/objint.c: In function ‘mp_obj_int_make_new’:
../py/misc.h:67:32: error: static assertion failed: "37 == 42"
../py/objint.c:45:5: note: in expansion of macro ‘MP_STATIC_ASSERT’
```
As compared to a diagnostic about
```
../py/misc.h:71:50: error: size of unnamed array is negative
```
Testing on godbolt indicated that this actually works back to gcc
4.5, but it's easier to use GNUC >= 5 as the test; Hypothetical
users of 4.5, 4.6, or 4.7 will just get slightly worse diagnostics.
Related: micropython#18116
Signed-off-by: Jeff Epler <jepler@unpythonic.net>1 parent adf6319 commit ce1f87a
1 file changed
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
66 | 71 | | |
| 72 | + | |
| 73 | + | |
67 | 74 | | |
68 | 75 | | |
69 | 76 | | |
| |||
72 | 79 | | |
73 | 80 | | |
74 | 81 | | |
75 | | - | |
| 82 | + | |
76 | 83 | | |
77 | 84 | | |
78 | 85 | | |
| |||
0 commit comments