https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106767
Bug ID: 106767 Summary: Failure to detect recursive macro calls due to _Pragma(pop_macro) Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: izbyshev at ispras dot ru CC: amonakov at gcc dot gnu.org Target Milestone: --- GCC preprocessor appears to behave as if each _Pragma(pop_macro("m")) creates a new definition of "m", so, for example, the following code results in infinite recursion: #define P(x) _Pragma(#x) #define f() P(push_macro("f")) P(pop_macro("f")) f() f() Naturally, this makes the preprocessor Turing-complete, e.g. it can add numbers: #define P(x) _Pragma(#x) #define PUSH(x) P(push_macro(#x)) #define POP(x) P(pop_macro(#x)) #define R(f) PUSH(f) POP(f) #define C(x, y) x ## y #define ADD0(...) __VA_ARGS__ #define ADD1(...) 1, R(ADD) ADD(__VA_ARGS__) #define ADD(x, ...) C(ADD, x)(__VA_ARGS__) // 1 + 2 (zero-terminated unary numbers) ADD(1, 0, 1, 1, 0) // Outputs 1, 1, 1, 0 with "gcc -E -P" The earliest GCC with this behavior on https://godbolt.org is 4.4.7. Clang detects recursion correctly.