[Pdbg] [PATCH 2/8] ccan/cppmagic: Fix NONEMPTY macro
Alistair Popple
alistair at popple.id.au
Wed Jun 20 15:34:03 AEST 2018
The original implementation of non-empty will fail to compile if passed an
argument of the form 'CPPMAGIC_NONEMPTY((...))'. Add a check for parentheses and
return true if passed.
Signed-off-by: Alistair Popple <alistair at popple.id.au>
---
ccan/cppmagic/cppmagic.h | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/ccan/cppmagic/cppmagic.h b/ccan/cppmagic/cppmagic.h
index f1f6868..587fe4e 100644
--- a/ccan/cppmagic/cppmagic.h
+++ b/ccan/cppmagic/cppmagic.h
@@ -68,9 +68,15 @@
* CPPMAGIC_NONEMPTY(@a, ...)
* expand to '1'
*/
-#define _CPPMAGIC_EOA() 0
+#define CHECK_N(x, n, ...) n
+#define CHECK(...) CHECK_N(__VA_ARGS__, , )
+#define PROBE(x) x, 1,
+#define IS_PAREN(x, ...) CHECK(IS_PAREN_PROBE x)
+#define IS_PAREN_PROBE(...) PROBE(~)
+
+#define _CPPMAGIC_EOA(a_, ...) 0
#define CPPMAGIC_NONEMPTY(...) \
- CPPMAGIC_NONZERO(CPPMAGIC_1ST(_CPPMAGIC_EOA __VA_ARGS__)())
+ CPPMAGIC_NONZERO(CPPMAGIC_1ST(_CPPMAGIC_EOA IS_PAREN(__VA_ARGS__) __VA_ARGS__)())
/**
* CPPMAGIC_ISEMPTY - does the macro have no arguments?
--
2.11.0
More information about the Pdbg
mailing list