Fix infinite loop handling non-type template parameters
Fixes infinite loop due to () brackets in a non-type template parameter containing an expression Fixes #2418 Non-trivial expressions are still not qualified properly though.
This commit is contained in:
parent
973590ff91
commit
52edda64c1
6 changed files with 69 additions and 3 deletions
|
|
@ -639,6 +639,7 @@ CPP11_TEST_BROKEN = \
|
|||
# C++14 test cases.
|
||||
CPP14_TEST_CASES += \
|
||||
cpp14_binary_integer_literals \
|
||||
cpp14_enable_if_t \
|
||||
|
||||
# Broken C++14 test cases.
|
||||
CPP14_TEST_BROKEN = \
|
||||
|
|
|
|||
34
Examples/test-suite/cpp14_enable_if_t.i
Normal file
34
Examples/test-suite/cpp14_enable_if_t.i
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
%module cpp14_enable_if_t
|
||||
|
||||
// test use of enable_if_t but without full %template instantiation, that is no enable_if_t definition is parsed
|
||||
|
||||
%inline %{
|
||||
#include <type_traits>
|
||||
typedef int node_t;
|
||||
typedef int position_t;
|
||||
|
||||
template <typename A, typename B, std::enable_if_t<std::is_integral_v<A>, bool> = true>
|
||||
void enableif1(const A a, const B b) {}
|
||||
|
||||
// tests non-type template parameters within () brackets - was causing an infinite loop, issue #2418
|
||||
template <typename A, typename B, std::enable_if_t<(std::is_integral_v<A>), bool> = true>
|
||||
void enableif2(const A a, const B b) {}
|
||||
|
||||
template <typename A, typename B, std::enable_if_t<(std::is_integral_v<A> || std::is_same_v<A, node_t>), bool> = true>
|
||||
void enableif3(const A a, const B b) {}
|
||||
|
||||
template <typename A, typename B, std::enable_if_t<(std::is_integral_v<A> or std::is_same_v<A, node_t>) and (std::is_integral_v<B> or std::is_same_v<B, position_t>), bool> = true>
|
||||
void enableif4(const A a, const B b) {}
|
||||
|
||||
template <typename A, typename B, std::enable_if_t<(std::is_integral_v<A> and std::is_integral_v<B>), bool> = true>
|
||||
int enableif5(const A a, const B b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
void tester() {
|
||||
enableif5<int, int>(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
|
||||
19
Examples/test-suite/java/cpp14_enable_if_t_runme.java
Normal file
19
Examples/test-suite/java/cpp14_enable_if_t_runme.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import cpp14_enable_if_t.*;
|
||||
|
||||
public class cpp14_enable_if_t_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("cpp14_enable_if_t");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
if (cpp14_enable_if_t.enableif5(10, 20) != 30)
|
||||
throw new RuntimeException("enableif5 not working");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue