diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2022-11-25 08:29:01 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2022-11-25 08:37:39 +0000 |
commit | 9b91b24d6be0c5296b08b527b70e6abd5507b3c2 (patch) | |
tree | ea0dcf037b6f17ea11f560c14105738df1258bd2 /Examples | |
parent | 081d44d45ea4ef4247580a9baa1f8bb64bd16b77 (diff) | |
download | swig-9b91b24d6be0c5296b08b527b70e6abd5507b3c2.tar.gz |
Fix syntax error parsing unnamed template parameters with a default.
Closes #961
Diffstat (limited to 'Examples')
-rw-r--r-- | Examples/test-suite/cpp17_enable_if_t.i | 42 |
1 files changed, 41 insertions, 1 deletions
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 +} +%} |