ForNeVeR / ForNeVeR/Cesium

Infinite loop in macro expansion

Open
#990 1 comment 0 reactions 0 assignees View on GitHub
area:preprocessor kind:bug status:help-wanted
Dominant language
C#
Stars
451
Forks
49
Avg merge
13h 59m
Merged PRs (30d)
6

Description

```
#define EVAL0(...) __VA_ARGS__

#define MAP_END(...)
#define MAP_OUT

#define EMPTY()
#define DEFER(id) id EMPTY()

#define MAP_NEXT(test, next) next MAP_OUT

#define MAP0_UD_I(f, x, peek, ...) f(x) DEFER ( MAP_NEXT(peek, MAP1_UD_I) ) ( f, peek, __VA_ARGS__ )
#define MAP1_UD_I(f, x, peek, ...) f(x) DEFER ( MAP_NEXT(peek, MAP0_UD_I) ) ( f, peek, __VA_ARGS__ )

/**
* Applies the function macro `f` to each of the remaining parameters, passes userdata as the second parameter to each invocation,
* and the index of the invocation as the third parameter,
* e.g. MAP_UD_I(f, x, a, b, c) evaluates to f(a, x, 0) f(b, x, 1) f(c, x, 2)
*/
#define MAP_UD_I(f, ...) EVAL0(MAP1_UD_I(f, 0, __VA_ARGS__, ()()(), ()()(), ()()(), 0))

/* Pass user-defined data and an index to each invocation */
#define PRINT_STREAM_I(x) printf ("d: d\n");
MAP_UD_I(PRINT_STREAM_I, 1, 2, 3, 4, 5)
```

Fails with stack overflow. Should fail with preprocessor error

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.