diff options
author | Olly Betts <olly@survex.com> | 2023-04-19 16:00:03 +1200 |
---|---|---|
committer | Olly Betts <olly@survex.com> | 2023-04-19 16:00:03 +1200 |
commit | 26dfe3394810a72e85c4c52ee568ff44cfbcac76 (patch) | |
tree | 19f20506c2605a45b1a7bc6bff7f8be35161711d /Examples | |
parent | 7df0d05e875bd96d0e3a64e2fe3c968a5f160375 (diff) | |
parent | 8f946309cce18ab14506f2bacb3c7954ff415471 (diff) | |
download | swig-26dfe3394810a72e85c4c52ee568ff44cfbcac76.tar.gz |
Merge branch 'macro-partial-expansion'
Diffstat (limited to 'Examples')
-rw-r--r-- | Examples/test-suite/preproc_defined.i | 28 | ||||
-rw-r--r-- | Examples/test-suite/python/preproc_defined_runme.py | 9 |
2 files changed, 37 insertions, 0 deletions
diff --git a/Examples/test-suite/preproc_defined.i b/Examples/test-suite/preproc_defined.i index 5ebf0a099..401666806 100644 --- a/Examples/test-suite/preproc_defined.i +++ b/Examples/test-suite/preproc_defined.i @@ -123,3 +123,31 @@ void another_macro_checking(void) { #if 0 # wobble wobble #endif + +/* Regression test for https://sourceforge.net/p/swig/bugs/1163/ + * ONE(1)(2) should expand to `2` but SWIG was expanding it to `TWO(2)` + * which results in the generated C wrapper failing to compile. + */ +#define ONE(X) TWO +#define TWO(X) X +%constant int a = ONE(1)(2); +#define XXX TWO +%constant int b = XXX(42); +#undef ONE +#undef TWO + +/* + * The behaviour of Self-Referential Macros is defined + * https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Self-Referential-Macros.html + */ +%inline %{ +int y = 0; +%} + +#define x (4 + y) +#define y (2 * x) + +%constant int z = y; + +#undef y +#undef x diff --git a/Examples/test-suite/python/preproc_defined_runme.py b/Examples/test-suite/python/preproc_defined_runme.py index af46816be..37441db52 100644 --- a/Examples/test-suite/python/preproc_defined_runme.py +++ b/Examples/test-suite/python/preproc_defined_runme.py @@ -9,3 +9,12 @@ d.defined = 10 preproc_defined.thing(10) preproc_defined.stuff(10) preproc_defined.bumpf(10) + +if preproc_defined.a != 2: + raise RuntimeError + +if preproc_defined.b != 42: + raise RuntimeError + +if preproc_defined.z != 8: + raise RuntimeError |