-
Notifications
You must be signed in to change notification settings - Fork 121
Use _Static_assert to check macro lengths #1471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
7dbf999
to
2bb0dd7
Compare
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
2bb0dd7
to
2ae1afd
Compare
#define X(name, lenstr, str) \ | ||
_Static_assert(*lenstr == strlen(str), "Macro length mismatch for " # name); | ||
#include "platform_defaultatoms.def" | ||
#undef X |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe using assert.h
with static_assert()
would be a bit nicer.
@@ -23,10 +23,15 @@ | |||
#include <stdlib.h> | |||
#include <string.h> | |||
|
|||
// About X macro: https://en.wikipedia.org/wiki/X_macro | |||
#define X(name, lenstr, str) \ | |||
_Static_assert(*lenstr == strlen(str), "Macro length mismatch for " # name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was waiting this check for quite some time, let's enable it only with clang >= 17. That will be enough at least for blocking any PR that introduces some atom length bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make CI green with this.
I think we should just enable this on the right version of clang, and then merge it. |
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later