diff --git a/Examples/test-suite/cpp11_alternate_function_syntax.i b/Examples/test-suite/cpp11_alternate_function_syntax.i index 227a1c8c8..4454193db 100644 --- a/Examples/test-suite/cpp11_alternate_function_syntax.i +++ b/Examples/test-suite/cpp11_alternate_function_syntax.i @@ -6,13 +6,15 @@ struct SomeStruct { int addNormal(int x, int y); auto addAlternate(int x, int y) -> int; + auto addAlternateConst(int x, int y) const -> int; + auto addAlternateNoExcept(int x, int y) noexcept -> int; + auto addAlternateConstNoExcept(int x, int y) const noexcept -> int; }; -auto SomeStruct::addAlternate(int x, int y) -> int { - return x + y; -} +int SomeStruct::addNormal(int x, int y) { return x + y; } +auto SomeStruct::addAlternate(int x, int y) -> int { return x + y; } +auto SomeStruct::addAlternateConst(int x, int y) const -> int { return x + y; } +auto SomeStruct::addAlternateNoExcept(int x, int y) noexcept -> int { return x + y; } +auto SomeStruct::addAlternateConstNoExcept(int x, int y) const noexcept -> int { return x + y; } -int SomeStruct::addNormal(int x, int y) { - return x + y; -} %} diff --git a/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py b/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py index 363736a84..cc7b5cd91 100644 --- a/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py +++ b/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py @@ -4,11 +4,20 @@ a = cpp11_alternate_function_syntax.SomeStruct() res = a.addNormal(4, 5) if res != 9: - raise RuntimeError, ("SomeStruct::addNormal(4,5) returns ", - res, " should be 9.") - + raise RuntimeError, ("SomeStruct::addNormal(4,5) returns ", res, " should be 9.") res = a.addAlternate(4, 5) if res != 9: - raise RuntimeError, ("SomeStruct::addAlternate(4,5) returns ", - res, " should be 9.") + raise RuntimeError, ("SomeStruct::addAlternate(4,5) returns ", res, " should be 9.") + +res = a.addAlternateConst(4, 5) +if res != 9: + raise RuntimeError, ("SomeStruct::addAlternateConst(4,5) returns ", res, " should be 9.") + +res = a.addAlternateNoExcept(4, 5) +if res != 9: + raise RuntimeError, ("SomeStruct::addAlternateNoExcept(4,5) returns ", res, " should be 9.") + +res = a.addAlternateConstNoExcept(4, 5) +if res != 9: + raise RuntimeError, ("SomeStruct::addAlternateConstNoExcept(4,5) returns ", res, " should be 9.") diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 61dd559e1..2972ecfd8 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3067,36 +3067,36 @@ c_decl : storage_class type declarator initializer c_decl_tail { } /* Alternate function syntax introduced in C++11: auto funcName(int x, int y) -> int; */ - | storage_class AUTO declarator ARROW cpp_alternate_rettype initializer c_decl_tail { + | storage_class AUTO declarator cpp_const ARROW cpp_alternate_rettype initializer c_decl_tail { $$ = new_node("cdecl"); - if ($6.qualifier) SwigType_push($3.type,$6.qualifier); - Setattr($$,"type",$5); + if ($4.qualifier) SwigType_push($3.type, $4.qualifier); + Setattr($$,"type",$6); Setattr($$,"storage",$1); Setattr($$,"name",$3.id); Setattr($$,"decl",$3.type); Setattr($$,"parms",$3.parms); - Setattr($$,"value",$6.val); - Setattr($$,"throws",$6.throws); - Setattr($$,"throw",$6.throwf); - Setattr($$,"noexcept",$6.nexcept); - if (!$7) { + Setattr($$,"value",$4.val); + Setattr($$,"throws",$4.throws); + Setattr($$,"throw",$4.throwf); + Setattr($$,"noexcept",$4.nexcept); + if (!$8) { if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); Setattr($$,"code",code); Delete(code); } } else { - Node *n = $7; + Node *n = $8; while (n) { - String *type = Copy($5); + String *type = Copy($6); Setattr(n,"type",type); Setattr(n,"storage",$1); n = nextSibling(n); Delete(type); } } - if ($6.bitfield) { - Setattr($$,"bitfield", $6.bitfield); + if ($4.bitfield) { + Setattr($$,"bitfield", $4.bitfield); } if (Strstr($3.id,"::")) { @@ -3107,18 +3107,18 @@ c_decl : storage_class type declarator initializer c_decl_tail { String *lstr = Swig_scopename_last($3.id); Setattr($$,"name",lstr); Delete(lstr); - set_nextSibling($$,$7); + set_nextSibling($$, $8); } else { Delete($$); - $$ = $7; + $$ = $8; } Delete(p); } else { Delete($$); - $$ = $7; + $$ = $8; } } else { - set_nextSibling($$,$7); + set_nextSibling($$, $8); } } ;