diff --git a/CHANGES.current b/CHANGES.current index e184cc6d8..e3165b178 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.2.0 (in progress) =========================== +2022-11-22: wsfulton + #1037 Fix seg fault handling template parameter expressions containing '<='. + 2022-11-18: wsfulton Duplicate class template instantiations via %template now issue a warning and are ignored. diff --git a/Examples/test-suite/cpp17_enable_if_t.i b/Examples/test-suite/cpp17_enable_if_t.i index b361775d0..7c188dcfa 100644 --- a/Examples/test-suite/cpp17_enable_if_t.i +++ b/Examples/test-suite/cpp17_enable_if_t.i @@ -37,3 +37,16 @@ void tester() { // non-type template parameters working well in SWIG, below is a simple workaround as the 3rd parameter is defaulted for enable_if_t (which is just SFINAE to give a nice C++ compiler error) %template(enableif5) enableif5; // workaround + + +%inline %{ +// #1037 infinite loop +template > +void destId(T el) {} + +/* +not yet fixed +template = 3>> +void destId(const T& el) {} +*/ +%} diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 8cd2e28e9..569d2a406 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -1234,17 +1234,20 @@ String *SwigType_prefix(const SwigType *t) { while (d > c) { d--; - if (*d == '>') { + if (*d == '>' && (d > c) && *(d - 1) == ')') { + /* skip over template parameters */ int nest = 1; d--; + d--; while ((d > c) && (nest)) { - if (*d == '>') + if (*d == '>' && *(d - 1) == ')') nest++; - if (*d == '<') + if (*d == '<' && *(d + 1) == '(') nest--; d--; } } + if (*d == ')') { /* Skip over params */ int nparen = 1; @@ -1259,10 +1262,10 @@ String *SwigType_prefix(const SwigType *t) { } if (*d == '.') { - char t = *(d + 1); + char x = *(d + 1); *(d + 1) = 0; r = NewString(c); - *(d + 1) = t; + *(d + 1) = x; return r; } }