diff options
-rw-r--r-- | CHANGES.current | 3 | ||||
-rw-r--r-- | Examples/test-suite/cpp17_enable_if_t.i | 42 | ||||
-rw-r--r-- | Source/CParse/parser.y | 3 |
3 files changed, 46 insertions, 2 deletions
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 <typename A, typename B, std::enable_if_t<(std::is_integral_v<A> and st void tester() { enableif5<int, int>(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<int, int, true>; // workaround +%template(enableif5) enableif5<int, int, true>; // workaround (overriding default) %inline %{ @@ -47,3 +48,42 @@ void destId(T el) {} template <typename T, std::enable_if_t<sizeof(T) >= 3>> void destId(const T& el) {} %} + +%inline %{ +// #961 no name for defaulted template parameter +template<typename T, typename = std::enable_if_t<std::is_enum<T>::value>> +void uuu() {} +template<typename T, typename E = std::enable_if_t<std::is_enum<T>::value>> +void uuuE() {} + +template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type> +void vvv() {} +template<typename T, typename E = typename std::enable_if<std::is_floating_point<T>::value>::type> +void vvvE() {} + +// More variations of enable_if and enable_if_t +template<typename T, typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr> +void www() {} + +template<typename T, typename std::enable_if_t<std::is_enum<T>::value, int> = 0> +void xxx() {} + +enum TestEnum { Enum1 = 1, Enum2 }; +struct TestStruct {}; + +void tester2() { + uuu<TestEnum>(); +// uuu<TestStruct>(); // compilation error + uuuE<TestEnum>(); +// uuuE<TestStruct>(); // compilation error + vvv<double>(); +// vvv<TestStruct>(); // compilation error + vvvE<double>(); +// vvvE<TestStruct>(); // compilation error + + www<double>(); +// www<TestStruct>(); // compilation error + xxx<TestEnum>(); +// xxx<TestStruct>(); // 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; |