diff --git a/CHANGES.current b/CHANGES.current index ba8bc36ef..e240ca3bc 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-25: wsfulton + #961 Fix syntax error parsing unnamed template parameters with a default value. + 2022-11-25: olly #2447 Fix undefined behaviour in swig's parser when handling default parameter expressions containing method calls. diff --git a/Examples/test-suite/cpp17_enable_if_t.i b/Examples/test-suite/cpp17_enable_if_t.i index 46515b9a3..a6695bca9 100644 --- a/Examples/test-suite/cpp17_enable_if_t.i +++ b/Examples/test-suite/cpp17_enable_if_t.i @@ -32,11 +32,12 @@ template and st void tester() { enableif5(10, 20); + enableif5(10, 20); } %} // 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 +%template(enableif5) enableif5; // workaround (overriding default) %inline %{ @@ -47,3 +48,42 @@ void destId(T el) {} template = 3>> void destId(const T& el) {} %} + +%inline %{ +// #961 no name for defaulted template parameter +template::value>> +void uuu() {} +template::value>> +void uuuE() {} + +template::value>::type> +void vvv() {} +template::value>::type> +void vvvE() {} + +// More variations of enable_if and enable_if_t +template::value>::type* = nullptr> +void www() {} + +template::value, int> = 0> +void xxx() {} + +enum TestEnum { Enum1 = 1, Enum2 }; +struct TestStruct {}; + +void tester2() { + uuu(); +// uuu(); // compilation error + uuuE(); +// uuuE(); // compilation error + vvv(); +// vvv(); // compilation error + vvvE(); +// vvvE(); // compilation error + + www(); +// www(); // compilation error + xxx(); +// xxx(); // compilation error +} +%} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index c92f82a18..04e6e9809 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -4489,8 +4489,9 @@ templateparameters : templateparameter templateparameterstail { | empty { $$ = 0; } ; -templateparameter : templcpptype { +templateparameter : templcpptype def_args { $$ = NewParmWithoutFileLineInfo(NewString($1), 0); + Setattr($$, "value", $2.rawval ? $2.rawval : $2.val); } | parm { $$ = $1;