Fix parser error containing multiple #define statements inside an enum.

The second #define fails to parse:

  enum FooEnum {
    ENUM1 = 0,
    ENUM2 = 1,

  #define MACRO_DEF1 "Hello"
  #define MACRO_DEF2 "World!"

    ENUM3 = 2,
    ENUM4 = 3,
  };

Bug mentioned at https://sourceforge.net/p/swig/patches/333/
This commit is contained in:
William S Fulton 2019-02-16 08:09:56 +00:00
commit eb7b989c61
6 changed files with 92 additions and 17 deletions

View file

@ -83,7 +83,6 @@ Makefile: $(srcdir)/Makefile.in ../../../config.status
# Broken C++ test cases. (Can be run individually using: make testcase.cpptest)
CPP_TEST_BROKEN += \
constants \
cpp_broken \
director_nested_class \
exception_partial_info \
extend_variable \

View file

@ -1,12 +0,0 @@
%module cpp_broken
// bug #940318
%inline %{
typedef enum {
eZero = 0
#define ONE 1
} EFoo;
%}

View file

@ -97,3 +97,45 @@ enum Greeks13
#define GREEK13 -13
};
/* Multiple macros */
%inline %{
enum Greeks14
{
#define GREEK14a -14
#define GREEK14b -140
theta14,
};
enum Greeks15
{
alpha15 = 150,
beta15 = 151,
#define GREEK15a -150
#define GREEK15b -151
theta15 = 152,
delta15 = 153
};
enum Greeks16
{
alpha16 = 160,
beta16 = 161,
#define GREEK16a -160
#define GREEK16b -161
#define GREEK16c -162
theta16 = 162,
delta16 = 163
};
enum Greeks17
{
alpha17 = 170,
beta17 = 171,
theta17 = 172,
delta17 = 173
#define GREEK17a -170
#define GREEK17b -171
#define GREEK17c -172
};
%}

View file

@ -88,6 +88,30 @@ public class enum_macro_runme {
{
Greeks13 a = null;
}
{
Greeks15 a = Greeks15.alpha15;
a = Greeks15.beta15;
a = Greeks15.theta15;
a = Greeks15.delta15;
if (a.swigValue() != 153)
throw new RuntimeException("Greeks15");
}
{
Greeks16 a = Greeks16.alpha16;
a = Greeks16.beta16;
a = Greeks16.theta16;
a = Greeks16.delta16;
if (a.swigValue() != 163)
throw new RuntimeException("Greeks16");
}
{
Greeks17 a = Greeks17.alpha17;
a = Greeks17.beta17;
a = Greeks17.theta17;
a = Greeks17.delta17;
if (a.swigValue() != 173)
throw new RuntimeException("Greeks17");
}
}
}