From 3fec49b2c93f0b0582f8f69c871e3fd26556fe09 Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Thu, 2 Jan 2025 09:36:29 +0800 Subject: [PATCH] sumtype: detect compilers with extensions off --- include/stc/sys/sumtype.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/stc/sys/sumtype.h b/include/stc/sys/sumtype.h index ff5cef58..4999cfb7 100644 --- a/include/stc/sys/sumtype.h +++ b/include/stc/sys/sumtype.h @@ -106,7 +106,17 @@ int main(void) { c_EVAL(c_LOOP(_c_vartuple_var, T, __VA_ARGS__, (0),)) \ } -#if defined __GNUC__ || defined __clang__ || defined __TINYC__ || _MSC_VER >= 1939 +#ifdef __clang__ +#if !__is_identifier(__typeof__) +#define __STC_HAS_TYPEOF +#endif +#elif (defined(__GNUC__) && __has_builtin(__typeof__)) \ + || defined(__TINYC__) \ + || _MSC_FULL_VER >= 193933428 +#define __STC__STC_HAS_TYPEOF +#endif + +#ifdef __STC_HAS_TYPEOF #define c_when(var) \ for (__typeof__(var) _match = (var); _match; _match = NULL) \ switch (_match->_any_.tag) @@ -119,6 +129,7 @@ int main(void) { for (__typeof__(v) _var = (v); _var; _var = NULL) \ if (c_holds(_var, Tag)) \ for (__typeof__(_var->Tag.var) *x = &_var->Tag.var; x; x = NULL) + #undef __STC_HAS_TYPEOF #else typedef union { struct { uint8_t tag; } _any_; } _c_any_variant; #define c_when(var) \