summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2022-11-25 08:29:01 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2022-11-26 11:09:08 +0000
commit7b19a6d6964d39ed8ad3eac80991fb32db303497 (patch)
tree4b59e6f3aa7a57813783b1c0cb38f2e8e2c2b141
parent04217d8c283b6567ba631389b06343ee5ee3c3ab (diff)
downloadswig-7b19a6d6964d39ed8ad3eac80991fb32db303497.tar.gz
Fix syntax error parsing unnamed template parameters with a default.
Closes #961 Conflicts: Examples/test-suite/cpp17_enable_if_t.i
-rw-r--r--CHANGES.current3
-rw-r--r--Examples/test-suite/cpp17_enable_if_t.i40
-rw-r--r--Source/CParse/parser.y3
3 files changed, 45 insertions, 1 deletions
diff --git a/CHANGES.current b/CHANGES.current
index d992157b8..eb56fd371 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.1.1 (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 b361775d0..f504d7200 100644
--- a/Examples/test-suite/cpp17_enable_if_t.i
+++ b/Examples/test-suite/cpp17_enable_if_t.i
@@ -32,8 +32,48 @@ 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
+
+%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 699ff2b5a..97b467b5c 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -4488,8 +4488,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;