Fix syntax error parsing unnamed template parameters with a default.
Closes #961
This commit is contained in:
parent
081d44d45e
commit
9b91b24d6b
3 changed files with 46 additions and 2 deletions
|
|
@ -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)
|
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
|
2022-11-25: olly
|
||||||
#2447 Fix undefined behaviour in swig's parser when handling
|
#2447 Fix undefined behaviour in swig's parser when handling
|
||||||
default parameter expressions containing method calls.
|
default parameter expressions containing method calls.
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,12 @@ template <typename A, typename B, std::enable_if_t<(std::is_integral_v<A> and st
|
||||||
|
|
||||||
void tester() {
|
void tester() {
|
||||||
enableif5<int, int>(10, 20);
|
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)
|
// 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 %{
|
%inline %{
|
||||||
|
|
@ -47,3 +48,42 @@ void destId(T el) {}
|
||||||
template <typename T, std::enable_if_t<sizeof(T) >= 3>>
|
template <typename T, std::enable_if_t<sizeof(T) >= 3>>
|
||||||
void destId(const T& el) {}
|
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
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
|
||||||
|
|
@ -4489,8 +4489,9 @@ templateparameters : templateparameter templateparameterstail {
|
||||||
| empty { $$ = 0; }
|
| empty { $$ = 0; }
|
||||||
;
|
;
|
||||||
|
|
||||||
templateparameter : templcpptype {
|
templateparameter : templcpptype def_args {
|
||||||
$$ = NewParmWithoutFileLineInfo(NewString($1), 0);
|
$$ = NewParmWithoutFileLineInfo(NewString($1), 0);
|
||||||
|
Setattr($$, "value", $2.rawval ? $2.rawval : $2.val);
|
||||||
}
|
}
|
||||||
| parm {
|
| parm {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue