Fix syntax error when the template keyword is used in types

For example:
  std::template vector<int> v;
This commit is contained in:
William S Fulton 2015-07-02 07:40:29 +01:00
commit 05397cf6a2
5 changed files with 93 additions and 18 deletions

View file

@ -412,6 +412,7 @@ CPP_TEST_CASES += \
template_inherit \
template_inherit_abstract \
template_int_const \
template_keyword_in_type \
template_methods \
template_namespace_forward_declaration \
template_using_directive_and_declaration_forward \

View file

@ -5,6 +5,8 @@
%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) TypedefNamePtr;
%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) MyIntKeyClass;
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) PF;
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) BucketAllocator1;
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) BucketAllocator2;
// This warning should go away when type aliasing is supported
#pragma SWIG nowarn=SWIGWARN_PARSE_USING_UNDEF // Nothing known about 'p.SomeType< char *,T2,4 >'.
@ -39,3 +41,16 @@ TypedefName<int> alias1(TypedefName<int> a) { return a; }
TypedefNamePtr<int> alias1(TypedefNamePtr<int> a = nullptr) { return a; }
%}
%inline %{
typedef double Val;
template<typename T> struct ListBucket {
};
namespace Alloc {
template<typename T> struct rebind {
typedef int other;
};
}
using BucketAllocator1 = typename Alloc::template rebind<ListBucket<Val>>::other;
using BucketAllocator2 = typename Alloc::template rebind<::template ListBucket<double>>::other;
%}

View file

@ -0,0 +1,38 @@
%module template_keyword_in_type
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) YYY;
%inline %{
template<typename T> struct XXX;
template<typename T> struct XXX {
template<typename TT> struct YYY {
typedef TT type;
};
int xxx(int h) { return h; }
};
#if defined(SWIG) || defined(__clang__)
// gcc doesn't parse this (tested with gcc-4.8)
void testXXX1(::template XXX<int>::template YYY<int>::type xx) {}
#else
void testXXX1(:: XXX<int>::template YYY<int>::type xx) {}
#endif
void testXXX2(XXX<int>::YYY<int>::type xx) {}
typedef ::XXX<int>::template YYY<int>::type templatetyped;
%}
%inline %{
typedef double Val;
template<typename T> struct ListBucket {
};
namespace Alloc {
template<typename T> struct rebind {
typedef int other;
};
}
void other1(typename Alloc::template rebind<ListBucket<Val> >::other) {}
void other2(typename Alloc::template rebind< ::template ListBucket<Val> >::other) {}
void other3(Alloc::template rebind<int>) {}
%}