Syntax error fixes parsing more elaborate parameter pack arguments

that are function pointers and member function pointers.

  template <typename... V> struct VariadicParms {
    void ParmsFuncPtrPtr(int (*)(V*...)) {}
    void ParmsFuncPtrPtrRef(int (*)(V*&...)) {}
    void ParmsFuncPtrPtrRValueRef(int (*)(V*&&...)) {}
    void ParmsFuncPtrRef(int (*)(V&...)) {}
    void ParmsFuncPtrRValueRef(int (*)(V&&...)) {}

    void ParmsMemFuncPtrPtr(int (KlassMemFuncs::*)(V*...)) {}
    void ParmsMemFuncPtrPtrRef(int (KlassMemFuncs::*)(V*&...)) {}
    void ParmsMemFuncPtrPtrRValueRef(int (KlassMemFuncs::*)(V*&&...)) {}
    void ParmsMemFuncPtrRef(int (KlassMemFuncs::*)(V&...)) {}
    void ParmsMemFuncPtrRValueRef(int (KlassMemFuncs::*)(V&&...)) {}
  };

  %template(VariadicParms0) VariadicParms<>;
  %template(VariadicParms1) VariadicParms<A>;

  Also in various other places such as within noexcept specifiers:

    template<typename T, typename... Args>
    void emplace(Args &&... args) noexcept(
        std::is_nothrow_constructible<T, Args &&...>::value);

Issue #1863
This commit is contained in:
William S Fulton 2022-12-29 21:04:48 +00:00
commit 004af63f3c
3 changed files with 71 additions and 13 deletions

View file

@ -7,6 +7,33 @@ 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-12-29: wsfulton
#1863 Syntax error fixes parsing more elaborate parameter pack arguments that are
used in function pointers, member function pointers:
template <typename... V> struct VariadicParms {
void ParmsFuncPtrPtr(int (*)(V*...)) {}
void ParmsFuncPtrPtrRef(int (*)(V*&...)) {}
void ParmsFuncPtrPtrRValueRef(int (*)(V*&&...)) {}
void ParmsFuncPtrRef(int (*)(V&...)) {}
void ParmsFuncPtrRValueRef(int (*)(V&&...)) {}
void ParmsMemFuncPtrPtr(int (KlassMemFuncs::*)(V*...)) {}
void ParmsMemFuncPtrPtrRef(int (KlassMemFuncs::*)(V*&...)) {}
void ParmsMemFuncPtrPtrRValueRef(int (KlassMemFuncs::*)(V*&&...)) {}
void ParmsMemFuncPtrRef(int (KlassMemFuncs::*)(V&...)) {}
void ParmsMemFuncPtrRValueRef(int (KlassMemFuncs::*)(V&&...)) {}
};
%template(VariadicParms0) VariadicParms<>;
%template(VariadicParms1) VariadicParms<A>;
Also in various other places such as within noexcept specifiers:
template<typename T, typename... Args>
void emplace(Args &&... args) noexcept(
std::is_nothrow_constructible<T, Args &&...>::value);
2022-12-27: wsfulton 2022-12-27: wsfulton
Fix instantiation of variadic class templates containing parameter pack arguments that Fix instantiation of variadic class templates containing parameter pack arguments that
are function pointers. are function pointers.

View file

@ -147,7 +147,6 @@ struct KlassMemFuncs {
int memfunc3() { return 3; } int memfunc3() { return 3; }
}; };
template <typename... V> struct VariadicParms { template <typename... V> struct VariadicParms {
public:
void ParmsVal(V... vparms_v) {} void ParmsVal(V... vparms_v) {}
void ParmsPtr(V*... vparms_p) {} void ParmsPtr(V*... vparms_p) {}
void ParmsPtrRef(V*&... vparms_pr) {} void ParmsPtrRef(V*&... vparms_pr) {}
@ -157,9 +156,20 @@ public:
void ParmsConstRef(const V&... vparms_cr) {} void ParmsConstRef(const V&... vparms_cr) {}
void ParmsFuncPtrVal(int (*)(V...)) {} void ParmsFuncPtrVal(int (*)(V...)) {}
void ParmsFuncPtrPtr(int (*)(V*...)) {}
void ParmsFuncPtrPtrRef(int (*)(V*&...)) {}
void ParmsFuncPtrPtrRValueRef(int (*)(V*&&...)) {}
void ParmsFuncPtrRef(int (*)(V&...)) {}
void ParmsFuncPtrRValueRef(int (*)(V&&...)) {}
void ParmsFuncPtrConstRef(int (*)(const V&...)) {}
void ParmsMemFuncPtrVal(int (KlassMemFuncs::*)(V...)) {} void ParmsMemFuncPtrVal(int (KlassMemFuncs::*)(V...)) {}
// TODO void ParmsMemFuncPtrPtr(int (KlassMemFuncs::*)(V*...)) {}
// void ParmsFuncPtrRef(int (*)(V&...)) {} void ParmsMemFuncPtrPtrRef(int (KlassMemFuncs::*)(V*&...)) {}
void ParmsMemFuncPtrPtrRValueRef(int (KlassMemFuncs::*)(V*&&...)) {}
void ParmsMemFuncPtrRef(int (KlassMemFuncs::*)(V&...)) {}
void ParmsMemFuncPtrRValueRef(int (KlassMemFuncs::*)(V&&...)) {}
void ParmsMemFuncPtrConstRef(int (KlassMemFuncs::*)(const V&...)) {}
}; };
%} %}
@ -209,3 +219,17 @@ template void Container::notifyMyTypes<>(void (tt)());
template void Container::notifyMyTypes<int>(void (tt)(int)); template void Container::notifyMyTypes<int>(void (tt)(int));
template void Container::notifyMyTypes<int, double>(void (tt)(int, double)); template void Container::notifyMyTypes<int, double>(void (tt)(int, double));
%} %}
// #1863
%inline %{
#include <type_traits>
class EmplaceContainer {
public:
template<typename T, typename... Args>
void emplace(Args &&... args) noexcept(
std::is_nothrow_constructible<T, Args &&...>::value) {}
};
%}
%template(emplace) EmplaceContainer::emplace<int,A>;
//%template(emplace) EmplaceContainer::emplace<int,A,B,C>;

View file

@ -1684,7 +1684,7 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
%type <type> templcpptype cpptype classkey classkeyopt; %type <type> templcpptype cpptype classkey classkeyopt;
%type <id> access_specifier; %type <id> access_specifier;
%type <node> base_specifier; %type <node> base_specifier;
%type <str> variadic; %type <str> variadic_opt;
%type <type> type rawtype type_right anon_bitfield_type decltype ; %type <type> type rawtype type_right anon_bitfield_type decltype ;
%type <bases> base_list inherit raw_inherit; %type <bases> base_list inherit raw_inherit;
%type <dtype> definetype def_args etype default_delete deleted_definition explicit_default; %type <dtype> definetype def_args etype default_delete deleted_definition explicit_default;
@ -5877,11 +5877,12 @@ direct_declarator : idcolon {
} }
; ;
abstract_declarator : pointer { abstract_declarator : pointer variadic_opt {
$$.type = $1; $$.type = $1;
$$.id = 0; $$.id = 0;
$$.parms = 0; $$.parms = 0;
$$.have_parms = 0; $$.have_parms = 0;
if ($2) SwigType_add_variadic($$.type);
} }
| pointer direct_abstract_declarator { | pointer direct_abstract_declarator {
$$ = $2; $$ = $2;
@ -5889,19 +5890,21 @@ abstract_declarator : pointer {
$$.type = $1; $$.type = $1;
Delete($2.type); Delete($2.type);
} }
| pointer AND { | pointer AND variadic_opt {
$$.type = $1; $$.type = $1;
SwigType_add_reference($$.type); SwigType_add_reference($$.type);
$$.id = 0; $$.id = 0;
$$.parms = 0; $$.parms = 0;
$$.have_parms = 0; $$.have_parms = 0;
if ($3) SwigType_add_variadic($$.type);
} }
| pointer LAND { | pointer LAND variadic_opt {
$$.type = $1; $$.type = $1;
SwigType_add_rvalue_reference($$.type); SwigType_add_rvalue_reference($$.type);
$$.id = 0; $$.id = 0;
$$.parms = 0; $$.parms = 0;
$$.have_parms = 0; $$.have_parms = 0;
if ($3) SwigType_add_variadic($$.type);
} }
| pointer AND direct_abstract_declarator { | pointer AND direct_abstract_declarator {
$$ = $3; $$ = $3;
@ -5942,19 +5945,21 @@ abstract_declarator : pointer {
Delete($2.type); Delete($2.type);
} }
} }
| AND { | AND variadic_opt {
$$.id = 0; $$.id = 0;
$$.parms = 0; $$.parms = 0;
$$.have_parms = 0; $$.have_parms = 0;
$$.type = NewStringEmpty(); $$.type = NewStringEmpty();
SwigType_add_reference($$.type); SwigType_add_reference($$.type);
if ($2) SwigType_add_variadic($$.type);
} }
| LAND { | LAND variadic_opt {
$$.id = 0; $$.id = 0;
$$.parms = 0; $$.parms = 0;
$$.have_parms = 0; $$.have_parms = 0;
$$.type = NewStringEmpty(); $$.type = NewStringEmpty();
SwigType_add_rvalue_reference($$.type); SwigType_add_rvalue_reference($$.type);
if ($2) SwigType_add_variadic($$.type);
} }
| idcolon DSTAR { | idcolon DSTAR {
$$.type = NewStringEmpty(); $$.type = NewStringEmpty();
@ -6155,7 +6160,9 @@ rawtype : type_qualifier type_right {
$$ = $2; $$ = $2;
SwigType_push($$,$1); SwigType_push($$,$1);
} }
| type_right { $$ = $1; } | type_right {
$$ = $1;
}
| type_right type_qualifier { | type_right type_qualifier {
$$ = $1; $$ = $1;
SwigType_push($$,$2); SwigType_push($$,$2);
@ -6876,7 +6883,7 @@ exprcompound : expr PLUS expr {
} }
; ;
variadic : ELLIPSIS { variadic_opt : ELLIPSIS {
$$ = NewString("..."); $$ = NewString("...");
} }
| empty { | empty {
@ -6921,7 +6928,7 @@ base_list : base_specifier {
base_specifier : opt_virtual { base_specifier : opt_virtual {
$<intvalue>$ = cparse_line; $<intvalue>$ = cparse_line;
} idcolon variadic { } idcolon variadic_opt {
$$ = NewHash(); $$ = NewHash();
Setfile($$,cparse_file); Setfile($$,cparse_file);
Setline($$,$<intvalue>2); Setline($$,$<intvalue>2);
@ -6940,7 +6947,7 @@ base_specifier : opt_virtual {
} }
| opt_virtual access_specifier { | opt_virtual access_specifier {
$<intvalue>$ = cparse_line; $<intvalue>$ = cparse_line;
} opt_virtual idcolon variadic { } opt_virtual idcolon variadic_opt {
$$ = NewHash(); $$ = NewHash();
Setfile($$,cparse_file); Setfile($$,cparse_file);
Setline($$,$<intvalue>3); Setline($$,$<intvalue>3);