Skip to content

Commit

Permalink
sumtype: detect compilers with extensions off
Browse files Browse the repository at this point in the history
  • Loading branch information
mochaaP committed Jan 2, 2025
1 parent c8319f5 commit 3fec49b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion include/stc/sys/sumtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) \
Expand Down

0 comments on commit 3fec49b

Please sign in to comment.