Merge branch 'interface-using-declaration'

* interface-using-declaration:
  Fix seg fault with %interface and using declarations
diff --git a/.travis.yml b/.travis.yml
index e2a47e6..a82b2bc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,9 +9,6 @@
     - compiler: gcc
       os: linux
       env: SWIGLANG=
-    - compiler: gcc
-      os: linux
-      env: SWIGLANG=
       sudo: required
       dist: trusty
     - os: linux
@@ -55,6 +52,8 @@
     - compiler: gcc
       os: linux
       env: SWIGLANG=javascript ENGINE=node
+      sudo: required
+      dist: trusty
     - compiler: gcc
       os: linux
       env: SWIGLANG=javascript ENGINE=jsc
diff --git a/CHANGES.current b/CHANGES.current
index 0629dfb..f76e5a5 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,6 +7,43 @@
 Version 4.0.0 (in progress)
 ===========================
 
+2017-09-18: wsfulton
+            Fix type promotion wrapping constant expressions of the form:
+              # define EXPR_MIXED1    (0x80 + 11.1) - 1
+            This was previously an integral type instead of a floating point type.
+
+2017-09-17: wsfulton
+            Fix generated code for constant expressions containing wchar_t L literals such as:
+              # define __WCHAR_MAX    (0x7fffffff + L'\0')
+              # define __WCHAR_MIN    (-__WCHAR_MAX - 1)
+
+2017-09-10: mlamarre
+            [Python] Patch #1083. Define_DEBUG to 1 to do exactly like Visual Studio
+            /LDd, /MDd or /MTd compiler options.
+
+2017-08-25: wsfulton
+            Issue #1059. Add support for C++11 ref-qualifiers on non-static member functions.
+            Members with lvalue ref-qualifiers such as:
+
+              struct RQ {
+                void m1(int x) &;
+                void m2(int x) const &;
+              };
+
+            are wrapped like any other member function. Member functions with rvalue ref-qualifiers
+            are ignored by default, such as:
+
+              struct RQ {
+                void m3(int x) &&;
+                void m4(int x) const &&;
+              };
+
+              example.i:7: Warning 405: Method with rvalue ref-qualifier m3(int) && ignored.
+              example.i:8: Warning 405: Method with rvalue ref-qualifier m4(int) const && ignored.
+
+            These can be unignored and exposed to the target language, see further documentation in
+            CPlusPlus11.html.
+
 2017-08-16: wsfulton
             Fix #1063. Add using declarations to templates into typedef table.
 
diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html
index e4dff65..f9281bd 100644
--- a/Doc/Manual/CPlusPlus11.html
+++ b/Doc/Manual/CPlusPlus11.html
@@ -42,6 +42,7 @@
 <li><a href="#CPlusPlus11_noexcept">Exception specifications and noexcept</a>
 <li><a href="#CPlusPlus11_alignment">Control and query object alignment</a>
 <li><a href="#CPlusPlus11_attributes">Attributes</a>
+<li><a href="#CPlusPlus11_ref_qualifiers">Methods with ref-qualifiers</a>
 </ul>
 <li><a href="#CPlusPlus11_standard_library_changes">Standard library changes</a>
 <ul>
@@ -971,6 +972,104 @@
 [[noreturn, nothrow]] void f [[noreturn]] ();
 </pre></div>
 
+
+<H3><a name="CPlusPlus11_ref_qualifiers">7.2.29 Methods with ref-qualifiers</a></H3>
+
+
+<p>
+C++11 non-static member functions can be declared with ref-qualifiers.
+Member functions declared with a <tt>&amp;</tt> lvalue ref-qualifiers are wrapped like any other function without ref-qualifiers.
+Member functions declared with a <tt>&amp;&amp;</tt> rvalue ref-qualifiers are ignored by default
+as they are unlikely to be required from non-C++ languages where the concept of <i>rvalue-ness</i>
+for the implied *this pointer does not apply.
+The warning is hidden by default, but can be displayed as described in the section on <a href="Warnings.html#Warnings_nn4">Enabling extra warnings</a>.
+</p>
+
+<p>
+Consider:
+</p>
+
+<div class="code"><pre>
+struct RQ {
+  void m1(int x) &amp;;
+  void m2(int x) &amp;&amp;;
+};
+</pre></div>
+
+<p>
+The only wrapped method will be the lvalue ref-qualified method <tt>m1</tt>
+and if SWIG is run with the <tt>-Wextra</tt> command-line option, the following warning will be issued indicating <tt>m2</tt> is not wrapped:
+</p>
+
+<div class="shell">
+<pre>
+example.i:7: Warning 405: Method with rvalue ref-qualifier m2(int) &amp;&amp; ignored.
+</pre>
+</div>
+
+<p>
+If you unignore the method as follows, wrappers for <tt>m2</tt> will be generated:
+</p>
+
+<div class="code"><pre>
+%feature("ignore", "0") RQ::m2(int x) &amp;&amp;;
+struct RQ {
+  void m1(int x) &amp;;
+  void m2(int x) &amp;&amp;;
+};
+</pre></div>
+
+<p>
+Inspection of the generated C++ code, will show that <tt>std::move</tt> is used on the instance
+of the <tt>RQ *</tt> class:
+</p>
+
+<div class="code"><pre>
+  RQ *arg1 = (RQ *) 0 ;
+  int arg2 ;
+
+  arg1 = ...marshalled from target language...
+  arg2 = ...marshalled from target language...
+
+  std::move(*arg1).m2(arg2);
+</pre></div>
+
+<p>
+This will compile but when run, the move effects may not be what you want.
+As stated earlier, rvalue ref-qualifiers aren't really applicable outside the world of C++.
+However, if you really know what you are doing, full control over the call to the method is
+possible via the low-level "action" feature.
+This feature completely replaces the call to the underlying function, that is, the last line in the snippet of code above.
+</p>
+
+<div class="code"><pre>
+%feature("ignore", "0") RQ::m2(int x) &amp;&amp;;
+%feature("action") RQ::m2(int x) &amp;&amp; %{
+  RQ().m2(arg2);
+%}
+struct RQ {
+  void m1(int x) &amp;;
+  void m2(int x) &amp;&amp;;
+};
+</pre></div>
+
+<p>
+resulting in:
+</p>
+
+<div class="code"><pre>
+  RQ *arg1 = (RQ *) 0 ;
+  int arg2 ;
+
+  arg1 = ...marshalled from target language...
+  arg2 = ...marshalled from target language...
+
+  RQ().m2(arg2);
+</pre></div>
+
+<p>
+<b>Compatibility note:</b> SWIG-4.0.0 was the first version to support ref-qualifiers.
+</p>
 <H2><a name="CPlusPlus11_standard_library_changes">7.3 Standard library changes</a></H2>
 
 
@@ -1177,5 +1276,6 @@
 You could just go with the more attractive option of just using <tt>double</tt> as the return type in the function declaration instead of <tt>result_of</tt>!
 </p>
 
+
 </body>
 </html>
diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html
index 3d9f6fd..f3beb22 100644
--- a/Doc/Manual/Contents.html
+++ b/Doc/Manual/Contents.html
@@ -228,7 +228,6 @@
 <li><a href="SWIGPlus.html#SWIGPlus_nn12">Static members</a>
 <li><a href="SWIGPlus.html#SWIGPlus_member_data">Member data</a>
 </ul>
-<li><a href="SWIGPlus.html#SWIGPlus_default_args">Default arguments</a>
 <li><a href="SWIGPlus.html#SWIGPlus_nn15">Protection</a>
 <li><a href="SWIGPlus.html#SWIGPlus_nn16">Enums and constants</a>
 <li><a href="SWIGPlus.html#SWIGPlus_nn17">Friends</a>
@@ -236,14 +235,15 @@
 <li><a href="SWIGPlus.html#SWIGPlus_nn19">Pass and return by value</a>
 <li><a href="SWIGPlus.html#SWIGPlus_nn20">Inheritance</a>
 <li><a href="SWIGPlus.html#SWIGPlus_nn21">A brief discussion of multiple inheritance, pointers,  and type checking</a>
-<li><a href="SWIGPlus.html#SWIGPlus_overloaded_methods">Wrapping Overloaded Functions and Methods</a>
+<li><a href="SWIGPlus.html#SWIGPlus_default_args">Default arguments</a>
+<li><a href="SWIGPlus.html#SWIGPlus_overloaded_methods">Overloaded functions and methods</a>
 <ul>
 <li><a href="SWIGPlus.html#SWIGPlus_nn24">Dispatch function generation</a>
-<li><a href="SWIGPlus.html#SWIGPlus_nn25">Ambiguity in Overloading</a>
-<li><a href="SWIGPlus.html#SWIGPlus_ambiguity_resolution_renaming">Ambiguity resolution and renaming</a>
+<li><a href="SWIGPlus.html#SWIGPlus_nn25">Ambiguity in overloading</a>
+<li><a href="SWIGPlus.html#SWIGPlus_ambiguity_resolution_renaming">Renaming and ambiguity resolution</a>
 <li><a href="SWIGPlus.html#SWIGPlus_nn27">Comments on overloading</a>
 </ul>
-<li><a href="SWIGPlus.html#SWIGPlus_nn28">Wrapping overloaded operators</a>
+<li><a href="SWIGPlus.html#SWIGPlus_nn28">Overloaded operators</a>
 <li><a href="SWIGPlus.html#SWIGPlus_class_extension">Class extension</a>
 <li><a href="SWIGPlus.html#SWIGPlus_nn30">Templates</a>
 <ul>
@@ -310,6 +310,7 @@
 <li><a href="CPlusPlus11.html#CPlusPlus11_noexcept">Exception specifications and noexcept</a>
 <li><a href="CPlusPlus11.html#CPlusPlus11_alignment">Control and query object alignment</a>
 <li><a href="CPlusPlus11.html#CPlusPlus11_attributes">Attributes</a>
+<li><a href="CPlusPlus11.html#CPlusPlus11_ref_qualifiers">Methods with ref-qualifiers</a>
 </ul>
 <li><a href="CPlusPlus11.html#CPlusPlus11_standard_library_changes">Standard library changes</a>
 <ul>
@@ -357,26 +358,32 @@
 <div class="sectiontoc">
 <ul>
 <li><a href="Library.html#Library_nn2">The %include directive and library search path</a>
-<li><a href="Library.html#Library_nn3">C Arrays and Pointers</a>
+<li><a href="Library.html#Library_nn3">C arrays and pointers</a>
 <ul>
 <li><a href="Library.html#Library_nn4">cpointer.i</a>
 <li><a href="Library.html#Library_carrays">carrays.i</a>
 <li><a href="Library.html#Library_nn6">cmalloc.i</a>
 <li><a href="Library.html#Library_nn7">cdata.i</a>
 </ul>
-<li><a href="Library.html#Library_nn8">C String Handling</a>
+<li><a href="Library.html#Library_nn8">C string handling</a>
 <ul>
 <li><a href="Library.html#Library_nn9">Default string handling</a>
 <li><a href="Library.html#Library_nn10">Passing binary data</a>
 <li><a href="Library.html#Library_nn11">Using %newobject to release memory</a>
 <li><a href="Library.html#Library_nn12">cstring.i</a>
 </ul>
-<li><a href="Library.html#Library_stl_cpp_library">STL/C++ Library</a>
+<li><a href="Library.html#Library_stl_cpp_library">STL/C++ library</a>
 <ul>
 <li><a href="Library.html#Library_std_string">std::string</a>
 <li><a href="Library.html#Library_std_vector">std::vector</a>
 <li><a href="Library.html#Library_stl_exceptions">STL exceptions</a>
 <li><a href="Library.html#Library_std_shared_ptr">shared_ptr smart pointer</a>
+<ul>
+<li><a href="Library.html#Library_shared_ptr_basics">shared_ptr basics</a>
+<li><a href="Library.html#Library_shared_ptr_inheritance">shared_ptr and inheritance</a>
+<li><a href="Library.html#Library_shared_ptr_templates">shared_ptr and templates</a>
+<li><a href="Library.html#Library_shared_ptr_directors">shared_ptr and directors</a>
+</ul>
 <li><a href="Library.html#Library_std_auto_ptr">auto_ptr smart pointer</a>
 </ul>
 <li><a href="Library.html#Library_nn16">Utility Libraries</a>
diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html
index e5040fc..269e659 100644
--- a/Doc/Manual/Customization.html
+++ b/Doc/Manual/Customization.html
@@ -356,7 +356,7 @@
 named "allocate".  This would include both global and member
 functions.  The names supplied to <tt>%exception</tt> follow the same
 rules as for <tt>%rename</tt> described in the section on 
-<a href="SWIGPlus.html#SWIGPlus_ambiguity_resolution_renaming">Ambiguity resolution and renaming</a>.
+<a href="SWIGPlus.html#SWIGPlus_ambiguity_resolution_renaming">Renaming and ambiguity resolution</a>.
 For example, if you wanted to define
 an exception handler for a specific class, you might write this:
 </p>
@@ -796,7 +796,7 @@
 </div>
 
 <p>
-The name matching rules outlined in the <a href="SWIGPlus.html#SWIGPlus_ambiguity_resolution_renaming">Ambiguity resolution and renaming</a>
+The name matching rules outlined in the <a href="SWIGPlus.html#SWIGPlus_ambiguity_resolution_renaming">Renaming and ambiguity resolution</a>
 section applies to all <tt>%feature</tt> directives.
 In fact the <tt>%rename</tt> directive is just a special form of <tt>%feature</tt>. 
 The matching rules mean that features are very flexible and can be applied with
diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html
index f41799b..8939c8d 100644
--- a/Doc/Manual/Library.html
+++ b/Doc/Manual/Library.html
@@ -12,26 +12,32 @@
 <div class="sectiontoc">
 <ul>
 <li><a href="#Library_nn2">The %include directive and library search path</a>
-<li><a href="#Library_nn3">C Arrays and Pointers</a>
+<li><a href="#Library_nn3">C arrays and pointers</a>
 <ul>
 <li><a href="#Library_nn4">cpointer.i</a>
 <li><a href="#Library_carrays">carrays.i</a>
 <li><a href="#Library_nn6">cmalloc.i</a>
 <li><a href="#Library_nn7">cdata.i</a>
 </ul>
-<li><a href="#Library_nn8">C String Handling</a>
+<li><a href="#Library_nn8">C string handling</a>
 <ul>
 <li><a href="#Library_nn9">Default string handling</a>
 <li><a href="#Library_nn10">Passing binary data</a>
 <li><a href="#Library_nn11">Using %newobject to release memory</a>
 <li><a href="#Library_nn12">cstring.i</a>
 </ul>
-<li><a href="#Library_stl_cpp_library">STL/C++ Library</a>
+<li><a href="#Library_stl_cpp_library">STL/C++ library</a>
 <ul>
 <li><a href="#Library_std_string">std::string</a>
 <li><a href="#Library_std_vector">std::vector</a>
 <li><a href="#Library_stl_exceptions">STL exceptions</a>
 <li><a href="#Library_std_shared_ptr">shared_ptr smart pointer</a>
+<ul>
+<li><a href="#Library_shared_ptr_basics">shared_ptr basics</a>
+<li><a href="#Library_shared_ptr_inheritance">shared_ptr and inheritance</a>
+<li><a href="#Library_shared_ptr_templates">shared_ptr and templates</a>
+<li><a href="#Library_shared_ptr_directors">shared_ptr and directors</a>
+</ul>
 <li><a href="#Library_std_auto_ptr">auto_ptr smart pointer</a>
 </ul>
 <li><a href="#Library_nn16">Utility Libraries</a>
@@ -92,7 +98,7 @@
 The directories that are searched are displayed when using <tt>-verbose</tt> commandline option.
 </p>
 
-<H2><a name="Library_nn3">9.2 C Arrays and Pointers</a></H2>
+<H2><a name="Library_nn3">9.2 C arrays and pointers</a></H2>
 
 
 <p>
@@ -761,7 +767,7 @@
 Clearly they are unsafe.
 </p>
 
-<H2><a name="Library_nn8">9.3 C String Handling</a></H2>
+<H2><a name="Library_nn8">9.3 C string handling</a></H2>
 
 
 <p>
@@ -1365,7 +1371,7 @@
 </li>
 </ul>
 
-<H2><a name="Library_stl_cpp_library">9.4 STL/C++ Library</a></H2>
+<H2><a name="Library_stl_cpp_library">9.4 STL/C++ library</a></H2>
 
 
 <p>
@@ -1728,6 +1734,9 @@
 <H3><a name="Library_std_shared_ptr">9.4.4 shared_ptr smart pointer</a></H3>
 
 
+<H4><a name="Library_shared_ptr_basics">9.4.4.1 shared_ptr basics</a></H4>
+
+
 <p>
 Some target languages have support for handling the shared_ptr reference counted smart pointer.
 This smart pointer is available in the standard C++11 library as <tt>std::shared_ptr</tt>.
@@ -1821,8 +1830,11 @@
 </pre>
 </div>
 
+<H4><a name="Library_shared_ptr_inheritance">9.4.4.2 shared_ptr and inheritance</a></H4>
+
+
 <p>
-This shared_ptr library works quite differently to SWIG's normal, but somewhat limited, 
+The shared_ptr library works quite differently to SWIG's normal, but somewhat limited, 
 <a href="SWIGPlus.html#SWIGPlus_smart_pointers">smart pointer handling</a>.
 The shared_ptr library does not generate extra wrappers, just for smart pointer handling, in addition to the proxy class.
 The normal proxy class including inheritance relationships is generated as usual.
@@ -1900,7 +1912,7 @@
 
 <div class="code">
 <pre>
-%include "boost_shared_ptr.i"
+%include &lt;boost_shared_ptr.i&gt;
 %shared_ptr(GrandParent);
 %shared_ptr(Parent);
 %shared_ptr(Child);
@@ -1909,8 +1921,52 @@
 </pre>
 </div>
 
+<H4><a name="Library_shared_ptr_templates">9.4.4.3 shared_ptr and templates</a></H4>
+
 <p>
-<b>Note:</b> There is somewhat limited support for <tt>%shared_ptr</tt> and the director feature
+The <tt>%shared_ptr</tt> macro should be used for all the required instantiations
+of the template before each of the <tt>%template</tt> instantiations.
+For example, consider <tt>number.h</tt> containing the following illustrative template:
+</p>
+
+<div class="code">
+<pre>
+#include &lt;memory&gt;
+
+template&lt;int N&gt; struct Number {
+  int num;
+  Number() : num(N) {}
+  static std::shared_ptr&lt;Number&lt;N&gt;&gt; make() { return std::make_shared&lt;Number&lt;N&gt;&gt;(); }
+};
+</pre>
+</div>
+
+<p>
+The SWIG code below shows the required ordering:
+</p>
+
+<div class="code">
+<pre>
+%include &lt;std_shared_ptr.i&gt;
+
+%shared_ptr(Number&lt;10&gt;);
+%shared_ptr(Number&lt;42&gt;);
+
+%{
+  #include "number.h"
+%}
+%include "number.h"
+
+%template(Number10) Number&lt;10&gt;;
+%template(Number42) Number&lt;42&gt;;
+</pre>
+</div>
+
+<H4><a name="Library_shared_ptr_directors">9.4.4.4 shared_ptr and directors</a></H4>
+
+
+<p>
+There is somewhat limited support for <tt>%shared_ptr</tt> and the director feature
 and the degrees of success varies among the different target languages.
 Please help to improve this support by providing patches with improvements.
 </p>
diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html
index 9a1178a..9fbfd75 100644
--- a/Doc/Manual/Php.html
+++ b/Doc/Manual/Php.html
@@ -390,8 +390,7 @@
 will generate dispatch functions which will use <tt>%typecheck</tt>
 typemaps to allow overloading.  This dispatch function's operation and
 precedence is described in <a
-href="SWIGPlus.html#SWIGPlus_overloaded_methods">Wrapping
-Overloaded Functions and Methods</a>.
+href="SWIGPlus.html#SWIGPlus_overloaded_methods">Overloaded functions and methods</a>.
 </p>
 
 <!-- This isn't correct for 1.3.30 and needs rewriting to reflect reality
diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html
index c05ed45..d677a22 100644
--- a/Doc/Manual/SWIG.html
+++ b/Doc/Manual/SWIG.html
@@ -1737,6 +1737,16 @@
 avoid these problems.</p>
 
 <p>
+When wrapping C code, simple use of identifiers/symbols with <tt>%rename</tt> usually suffices.
+When wrapping C++ code, simple use of simple identifiers/symbols with <tt>%rename</tt> might be too
+limiting when using C++ features such as function overloading, default arguments, namespaces, template specialization etc.
+If you are using the <tt>%rename</tt> directive and C++, make sure you read the
+<a href="SWIGPlus.html">SWIG and C++</a> chapter and in particular the section on
+<a href="SWIGPlus.html#SWIGPlus_ambiguity_resolution_renaming">Renaming and ambiguity resolution</a>
+for method overloading and default arguments.
+</p>
+
+<p>
 Closely related to <tt>%rename</tt> is the <tt>%ignore</tt> directive.  <tt>%ignore</tt> instructs SWIG
 to ignore declarations that match a given identifier.  For example:
 </p>
@@ -2078,7 +2088,7 @@
 <p>
 Finally, variants of <tt>%rename</tt> and <tt>%ignore</tt> directives can be used to help
 wrap C++ overloaded functions and methods or C++ methods which use default arguments. This is described in the
-<a href="SWIGPlus.html#SWIGPlus_ambiguity_resolution_renaming">Ambiguity resolution and renaming</a> section in the C++ chapter.
+<a href="SWIGPlus.html#SWIGPlus_ambiguity_resolution_renaming">Renaming and ambiguity resolution</a> section in the C++ chapter.
 </p>
 
 
@@ -3293,11 +3303,27 @@
   return (Vector *) malloc(sizeof(Vector));
 }
 %}
-
 </pre></div>
 
 <p>
-The <tt>%inline</tt> directive inserts all of the code that follows
+This is the same as writing:
+</p>
+
+<div class="code"><pre>
+%{
+/* Create a new vector */
+Vector *new_Vector() {
+  return (Vector *) malloc(sizeof(Vector));
+}
+%}
+
+/* Create a new vector */
+Vector *new_Vector() {
+  return (Vector *) malloc(sizeof(Vector));
+}
+</pre></div>
+<p>
+In other words, the <tt>%inline</tt> directive inserts all of the code that follows
 verbatim into the header portion of an interface file. The code is
 then parsed by both the SWIG preprocessor and parser.
 Thus, the above example creates a new command <tt>new_Vector</tt> using only one
@@ -3305,6 +3331,11 @@
 is given to both the C compiler and SWIG, it is illegal to include any
 SWIG directives inside a <tt>%{ ... %}</tt> block.</p>
 
+
+<p>
+<b>Note:</b> The usual SWIG C preprocessor rules apply to code in <tt>%apply</tt> blocks when SWIG parses this code. For example, as mentioned earlier, <a href="SWIG.html#SWIG_nn6">SWIG's C Preprocessor</a> does not follow <tt>#include</tt> directives by default.
+</p>
+
 <H3><a name="SWIG_nn44">5.6.4 Initialization blocks</a></H3>
 
 
diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html
index 57da73d..18059b4 100644
--- a/Doc/Manual/SWIGPlus.html
+++ b/Doc/Manual/SWIGPlus.html
@@ -31,7 +31,6 @@
 <li><a href="#SWIGPlus_nn12">Static members</a>
 <li><a href="#SWIGPlus_member_data">Member data</a>
 </ul>
-<li><a href="#SWIGPlus_default_args">Default arguments</a>
 <li><a href="#SWIGPlus_nn15">Protection</a>
 <li><a href="#SWIGPlus_nn16">Enums and constants</a>
 <li><a href="#SWIGPlus_nn17">Friends</a>
@@ -39,14 +38,15 @@
 <li><a href="#SWIGPlus_nn19">Pass and return by value</a>
 <li><a href="#SWIGPlus_nn20">Inheritance</a>
 <li><a href="#SWIGPlus_nn21">A brief discussion of multiple inheritance, pointers,  and type checking</a>
-<li><a href="#SWIGPlus_overloaded_methods">Wrapping Overloaded Functions and Methods</a>
+<li><a href="#SWIGPlus_default_args">Default arguments</a>
+<li><a href="#SWIGPlus_overloaded_methods">Overloaded functions and methods</a>
 <ul>
 <li><a href="#SWIGPlus_nn24">Dispatch function generation</a>
-<li><a href="#SWIGPlus_nn25">Ambiguity in Overloading</a>
-<li><a href="#SWIGPlus_ambiguity_resolution_renaming">Ambiguity resolution and renaming</a>
+<li><a href="#SWIGPlus_nn25">Ambiguity in overloading</a>
+<li><a href="#SWIGPlus_ambiguity_resolution_renaming">Renaming and ambiguity resolution</a>
 <li><a href="#SWIGPlus_nn27">Comments on overloading</a>
 </ul>
-<li><a href="#SWIGPlus_nn28">Wrapping overloaded operators</a>
+<li><a href="#SWIGPlus_nn28">Overloaded operators</a>
 <li><a href="#SWIGPlus_class_extension">Class extension</a>
 <li><a href="#SWIGPlus_nn30">Templates</a>
 <ul>
@@ -1104,113 +1104,7 @@
 customization features.
 </p>
 
-<H2><a name="SWIGPlus_default_args">6.7 Default arguments</a></H2>
-
-
-<p>
-SWIG will wrap all types of functions that have default arguments. For example member functions:
-</p>
-
-<div class="code">
-<pre>
-class Foo {
-public:
-  void bar(int x, int y = 3, int z = 4);
-};
-</pre>
-</div>
-
-<p>
-SWIG handles default arguments by generating an extra overloaded method for each defaulted argument.
-SWIG is effectively handling methods with default arguments as if it was wrapping the equivalent overloaded methods.
-Thus for the example above, it is as if we had instead given the following to SWIG:
-</p>
-
-<div class="code">
-<pre>
-class Foo {
-public:
-  void bar(int x, int y, int z);
-  void bar(int x, int y);
-  void bar(int x);
-};
-</pre>
-</div>
-
-<p>
-The wrappers produced are exactly the same as if the above code was instead fed into SWIG.
-Details of this are covered later in the <a href="#SWIGPlus_overloaded_methods">Wrapping Overloaded Functions and Methods</a> section.
-This approach allows SWIG to wrap all possible default arguments, but can be verbose.
-For example if a method has ten default arguments, then eleven wrapper methods are generated.
-</p>
-
-<p>
-Please see the <a href="Customization.html#Customization_features_default_args">Features and default arguments</a>
-section for more information on using <tt>%feature</tt> with functions with default arguments.
-The <a href="#SWIGPlus_ambiguity_resolution_renaming">Ambiguity resolution and renaming</a> section 
-also deals with using <tt>%rename</tt> and <tt>%ignore</tt> on methods with default arguments.
-If you are writing your own typemaps for types used in methods with default arguments, you may also need to write a <tt>typecheck</tt> typemap.
-See the <a href="Typemaps.html#Typemaps_overloading">Typemaps and overloading</a> section for details or otherwise
-use the <tt>compactdefaultargs</tt> feature flag as mentioned below.
-</p>
-
-<p>
-<b>Compatibility note:</b> Versions of SWIG prior to SWIG-1.3.23 wrapped default arguments slightly differently.
-Instead a single wrapper method was generated and the default values were copied into the C++ wrappers
-so that the method being wrapped was then called with all the arguments specified.
-If the size of the wrappers are a concern then this approach to wrapping methods with default arguments
-can be re-activated by using the <tt>compactdefaultargs</tt> 
-<a href="Customization.html#Customization_feature_flags">feature flag</a>.
-</p>
-
-<div class="code">
-<pre>
-%feature("compactdefaultargs") Foo::bar;
-class Foo {
-public:
-  void bar(int x, int y = 3, int z = 4);
-};
-</pre>
-</div>
-
-
-<p>
-This is great for reducing the size of the wrappers, but the caveat is it does not work for the statically typed languages,
-such as C# and Java,
-which don't have optional arguments in the language, 
-Another restriction of this feature is that it cannot handle default arguments that are not public.
-The following example illustrates this:
-</p>
-
-<div class="code">
-<pre>
-class Foo {
-private:
-  static const int spam;
-public:
-  void bar(int x, int y = spam);   // Won't work with %feature("compactdefaultargs") -
-                                   // private default value
-};
-</pre>
-</div>
-
-<p>
-This produces uncompilable wrapper code because default values in C++ are
-evaluated in the same scope as the member function whereas SWIG
-evaluates them in the scope of a wrapper function (meaning that the
-values have to be public). 
-</p>
-
-<p>
-The <tt>compactdefaultargs</tt> feature is automatically turned on when wrapping <a href="SWIG.html#SWIG_default_args">C code with default arguments</a>.
-Some target languages will also automatically turn on this feature
-if the keyword arguments feature (kwargs) is specified for either C or C++ functions, and the target language supports kwargs,
-the <tt>compactdefaultargs</tt> feature is also automatically turned on.
-Keyword arguments are a language feature of some scripting languages, for example Ruby and Python.
-SWIG is unable to support kwargs when wrapping overloaded methods, so the default approach cannot be used.
-</p>
-
-<H2><a name="SWIGPlus_nn15">6.8 Protection</a></H2>
+<H2><a name="SWIGPlus_nn15">6.7 Protection</a></H2>
 
 
 <p>
@@ -1230,7 +1124,7 @@
 the same convention used by C++).
 </p>
 
-<H2><a name="SWIGPlus_nn16">6.9 Enums and constants</a></H2>
+<H2><a name="SWIGPlus_nn16">6.8 Enums and constants</a></H2>
 
 
 <p>
@@ -1260,7 +1154,7 @@
 Members declared as <tt>const</tt> are wrapped as read-only members and do not create constants.
 </p>
 
-<H2><a name="SWIGPlus_nn17">6.10 Friends</a></H2>
+<H2><a name="SWIGPlus_nn17">6.9 Friends</a></H2>
 
 
 <p>
@@ -1321,7 +1215,7 @@
 and a wrapper for the method 'blah' will not be generated.
 </p>
 
-<H2><a name="SWIGPlus_nn18">6.11 References and pointers</a></H2>
+<H2><a name="SWIGPlus_nn18">6.10 References and pointers</a></H2>
 
 
 <p>
@@ -1421,7 +1315,7 @@
 </p>
 
 
-<H2><a name="SWIGPlus_nn19">6.12 Pass and return by value</a></H2>
+<H2><a name="SWIGPlus_nn19">6.11 Pass and return by value</a></H2>
 
 
 <p>
@@ -1525,7 +1419,7 @@
 It is not used for C++ pointers or references.
 </p>
 
-<H2><a name="SWIGPlus_nn20">6.13 Inheritance</a></H2>
+<H2><a name="SWIGPlus_nn20">6.12 Inheritance</a></H2>
 
 
 <p>
@@ -1711,7 +1605,7 @@
 class.
 </p>
 
-<H2><a name="SWIGPlus_nn21">6.14 A brief discussion of multiple inheritance, pointers,  and type checking</a></H2>
+<H2><a name="SWIGPlus_nn21">6.13 A brief discussion of multiple inheritance, pointers,  and type checking</a></H2>
 
 
 <p>
@@ -1843,7 +1737,113 @@
 In practice, the pointer is held as an integral number in the target language proxy class.
 </p>
 
-<H2><a name="SWIGPlus_overloaded_methods">6.15 Wrapping Overloaded Functions and Methods</a></H2>
+<H2><a name="SWIGPlus_default_args">6.14 Default arguments</a></H2>
+
+
+<p>
+SWIG will wrap all types of functions that have default arguments. For example member functions:
+</p>
+
+<div class="code">
+<pre>
+class Foo {
+public:
+  void bar(int x, int y = 3, int z = 4);
+};
+</pre>
+</div>
+
+<p>
+SWIG handles default arguments by generating an extra overloaded method for each defaulted argument.
+SWIG is effectively handling methods with default arguments as if it was wrapping the equivalent overloaded methods.
+Thus for the example above, it is as if we had instead given the following to SWIG:
+</p>
+
+<div class="code">
+<pre>
+class Foo {
+public:
+  void bar(int x, int y, int z);
+  void bar(int x, int y);
+  void bar(int x);
+};
+</pre>
+</div>
+
+<p>
+The wrappers produced are exactly the same as if the above code was instead fed into SWIG.
+Details of this are covered in the next section <a href="#SWIGPlus_overloaded_methods">Overloaded functions and methods</a>.
+This approach allows SWIG to wrap all possible default arguments, but can be verbose.
+For example if a method has ten default arguments, then eleven wrapper methods are generated.
+</p>
+
+<p>
+Please see the <a href="Customization.html#Customization_features_default_args">Features and default arguments</a>
+section for more information on using <tt>%feature</tt> with functions with default arguments.
+The <a href="#SWIGPlus_ambiguity_resolution_renaming">Renaming and ambiguity resolution</a> section 
+also deals with using <tt>%rename</tt> and <tt>%ignore</tt> on methods with default arguments.
+If you are writing your own typemaps for types used in methods with default arguments, you may also need to write a <tt>typecheck</tt> typemap.
+See the <a href="Typemaps.html#Typemaps_overloading">Typemaps and overloading</a> section for details or otherwise
+use the <tt>compactdefaultargs</tt> feature flag as mentioned below.
+</p>
+
+<p>
+<b>Compatibility note:</b> Versions of SWIG prior to SWIG-1.3.23 wrapped default arguments slightly differently.
+Instead a single wrapper method was generated and the default values were copied into the C++ wrappers
+so that the method being wrapped was then called with all the arguments specified.
+If the size of the wrappers are a concern then this approach to wrapping methods with default arguments
+can be re-activated by using the <tt>compactdefaultargs</tt> 
+<a href="Customization.html#Customization_feature_flags">feature flag</a>.
+</p>
+
+<div class="code">
+<pre>
+%feature("compactdefaultargs") Foo::bar;
+class Foo {
+public:
+  void bar(int x, int y = 3, int z = 4);
+};
+</pre>
+</div>
+
+
+<p>
+This is great for reducing the size of the wrappers, but the caveat is it does not work for the statically typed languages,
+such as C# and Java,
+which don't have optional arguments in the language, 
+Another restriction of this feature is that it cannot handle default arguments that are not public.
+The following example illustrates this:
+</p>
+
+<div class="code">
+<pre>
+class Foo {
+private:
+  static const int spam;
+public:
+  void bar(int x, int y = spam);   // Won't work with %feature("compactdefaultargs") -
+                                   // private default value
+};
+</pre>
+</div>
+
+<p>
+This produces uncompilable wrapper code because default values in C++ are
+evaluated in the same scope as the member function whereas SWIG
+evaluates them in the scope of a wrapper function (meaning that the
+values have to be public). 
+</p>
+
+<p>
+The <tt>compactdefaultargs</tt> feature is automatically turned on when wrapping <a href="SWIG.html#SWIG_default_args">C code with default arguments</a>.
+Some target languages will also automatically turn on this feature
+if the keyword arguments feature (kwargs) is specified for either C or C++ functions, and the target language supports kwargs,
+the <tt>compactdefaultargs</tt> feature is also automatically turned on.
+Keyword arguments are a language feature of some scripting languages, for example Ruby and Python.
+SWIG is unable to support kwargs when wrapping overloaded methods, so the default approach cannot be used.
+</p>
+
+<H2><a name="SWIGPlus_overloaded_methods">6.15 Overloaded functions and methods</a></H2>
 
 
 <p>
@@ -2031,7 +2031,7 @@
 If you're still confused, don't worry about it---SWIG is probably doing the right thing.
 </p>
 
-<H3><a name="SWIGPlus_nn25">6.15.2 Ambiguity in Overloading</a></H3>
+<H3><a name="SWIGPlus_nn25">6.15.2 Ambiguity in overloading</a></H3>
 
 
 <p>
@@ -2149,7 +2149,7 @@
 functions and methods.  The only way to fix the problem is to read the next section.
 </p>
 
-<H3><a name="SWIGPlus_ambiguity_resolution_renaming">6.15.3 Ambiguity resolution and renaming</a></H3>
+<H3><a name="SWIGPlus_ambiguity_resolution_renaming">6.15.3 Renaming and ambiguity resolution</a></H3>
 
 
 <p>
@@ -2409,8 +2409,8 @@
 is used.
 </li>
 
-<li><p>The name matching rules strictly follow member qualification rules.
-For example, if you have a class like this:</p>
+<li><p>The name matching rules strictly follow member qualifier rules.
+For example, if you have a class and member with a member that is const qualified like this:</p>
 
 <div class="code">
 <pre>
@@ -2434,7 +2434,7 @@
 </div>
 
 <p>
-will not apply as there is no unqualified member <tt>bar()</tt>. The following will apply as
+will not apply as there is no unqualified member <tt>bar()</tt>. The following will apply the rename as
 the qualifier matches correctly:
 </p>
 
@@ -2445,6 +2445,26 @@
 </div>
 
 <p>
+Similarly for combinations of cv-qualifiers and ref-qualifiers, all the qualifiers must be specified to match correctly:
+</p>
+
+<div class="code">
+<pre>
+%rename(name) Jam::bar();          // will not match
+%rename(name) Jam::bar() &amp;;        // will not match
+%rename(name) Jam::bar() const;    // will not match
+%rename(name) Jam::bar() const &amp;;  // ok, will match
+
+class Jam {
+public:
+  ...
+  void bar() const &amp;;
+  ...
+};
+</pre>
+</div>
+
+<p>
 An often overlooked C++ feature is that classes can define two different overloaded members
 that differ only in their qualifiers, like this:
 </p>
@@ -2476,7 +2496,7 @@
 <p>
 Similarly, if you
 merely wanted to ignore one of the declarations, use <tt>%ignore</tt>
-with the full qualification.  For example, the following directive
+with the full qualifier.  For example, the following directive
 would tell SWIG to ignore the <tt>const</tt> version of <tt>bar()</tt>
 above:
 </p>
@@ -2542,8 +2562,7 @@
 <p>
 The C++ method can then be called from the target language with the new name no matter how many arguments are specified, for example:
 <tt>newbar(2, 2.0)</tt>, <tt>newbar(2)</tt> or <tt>newbar()</tt>.
-However, if the <tt>%rename</tt> does not contain the default arguments, it will only apply to the single equivalent target language overloaded method.
-So if instead we have:
+However, if the <tt>%rename</tt> does not contain the default arguments:
 </p>
 
 <div class="code">
@@ -2553,8 +2572,23 @@
 </div>
 
 <p>
+then only one of the three equivalent overloaded methods will be renamed and wrapped as if SWIG parsed:
+</p>
+
+<div class="code">
+<pre>
+void Spam::newbar(int i, double d);
+void Spam::bar(int i);
+void Spam::bar();
+</pre>
+</div>
+
+<p>
 The C++ method must then be called from the target language with the new name <tt>newbar(2, 2.0)</tt> when both arguments are supplied
 or with the original name as <tt>bar(2)</tt> (one argument) or <tt>bar()</tt> (no arguments).
+</p>
+
+<p>
 In fact it is possible to use <tt>%rename</tt> on the equivalent overloaded methods, to rename all the equivalent overloaded methods:
 </p>
 
@@ -2596,7 +2630,7 @@
 than dynamically typed languages like Perl, Python, Ruby, and Tcl.
 </p>
 
-<H2><a name="SWIGPlus_nn28">6.16 Wrapping overloaded operators</a></H2>
+<H2><a name="SWIGPlus_nn28">6.16 Overloaded operators</a></H2>
 
 
 <p>
diff --git a/Doc/Manual/Scilab.html b/Doc/Manual/Scilab.html
index bfde99f..fafb0b5 100644
--- a/Doc/Manual/Scilab.html
+++ b/Doc/Manual/Scilab.html
@@ -1133,7 +1133,7 @@
 
 
 <p>
-As explained in <a href="SWIGPlus.html#SWIGPlus_overloaded_methods">6.15</a> SWIG provides support for overloaded functions and constructors.
+As explained in <a href="SWIGPlus.html#SWIGPlus_overloaded_methods">Overloaded functions and methods</a> SWIG provides support for overloaded functions and constructors.
 </p>
 
 <p>As SWIG knows pointer types, the overloading works also with pointer types, here is an example with a function <tt>magnify</tt> overloaded for the previous classes <tt>Shape</tt> and <tt>Circle</tt>:
diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html
index 7391707..c17f9e8 100644
--- a/Doc/Manual/Sections.html
+++ b/Doc/Manual/Sections.html
@@ -1,11 +1,11 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
-<title>SWIG-3.0 Documentation</title>
+<title>SWIG-4.0 Documentation</title>
 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 </head>
 <body bgcolor="#ffffff">
-<H1><a name="Sections">SWIG-3.0 Documentation</a></H1>
+<H1><a name="Sections">SWIG-4.0 Documentation</a></H1>
 
 <p>
 Last update : SWIG-4.0.0 (in progress)
diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html
index f274c92..eeabdd8 100644
--- a/Doc/Manual/Typemaps.html
+++ b/Doc/Manual/Typemaps.html
@@ -4021,7 +4021,7 @@
 Forced inclusion of fragments can be used as a replacement for <a href="SWIG.html#SWIG_nn42">code insertion block</a>, ensuring the
 code block is only generated once.
 Consider the contents of FileA.i below which first uses a code insertion block and then a forced fragment inclusion to generate code:
-<p>
+</p>
 <div class="code">
 <pre>
 // FileA.i
@@ -4058,7 +4058,7 @@
 <p>
 A note of caution must be mentioned when using <tt>%fragment</tt> forced inclusion or code insertion blocks with <tt>%import</tt>.
 If <tt>%import</tt> is used instead:
-<p>
+</p>
 
 <div class="code">
 <pre>
diff --git a/Doc/Manual/index.html b/Doc/Manual/index.html
index 26cc81e..e720e70 100644
--- a/Doc/Manual/index.html
+++ b/Doc/Manual/index.html
@@ -1,11 +1,11 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
-<title>SWIG-3.0 Documentation</title>
+<title>SWIG-4.0 Documentation</title>
 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 </head>
 <body bgcolor="#ffffff">
-<H1><a name="index">SWIG-3.0 Documentation</a></H1>
+<H1><a name="index">SWIG-4.0 Documentation</a></H1>
 
 The SWIG documentation is available in one of the following formats.
 <ul>
diff --git a/Examples/test-suite/class_scope_namespace.i b/Examples/test-suite/class_scope_namespace.i
index 372727f..730c076 100644
--- a/Examples/test-suite/class_scope_namespace.i
+++ b/Examples/test-suite/class_scope_namespace.i
@@ -20,9 +20,17 @@
   struct B;
 }
 using Space2::B;
+#ifdef __clang__
+namespace Space2 {
+  struct B {
+    void bb(Space2::B, B) {}
+  };
+}
+#else
 struct B {
   void bb(Space2::B, B) {}
 };
+#endif
 void bbb(Space2::B, B) {}
 
 namespace Space3 {
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index e3448dc..4bd657c 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -561,6 +561,9 @@
 	cpp11_noexcept \
 	cpp11_null_pointer_constant \
 	cpp11_raw_string_literals \
+	cpp11_ref_qualifiers \
+	cpp11_ref_qualifiers_rvalue_unignore \
+	cpp11_ref_qualifiers_typemaps \
 	cpp11_result_of \
 	cpp11_rvalue_reference \
 	cpp11_rvalue_reference2 \
diff --git a/Examples/test-suite/cpp11_ref_qualifiers.i b/Examples/test-suite/cpp11_ref_qualifiers.i
new file mode 100644
index 0000000..e371367
--- /dev/null
+++ b/Examples/test-suite/cpp11_ref_qualifiers.i
@@ -0,0 +1,226 @@
+%module cpp11_ref_qualifiers
+
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra2;
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra3;
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc2;
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc3;
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc5;
+
+%include <std_string.i>
+
+%ignore Host::h() const &;
+
+// Basic testing
+%inline %{
+using std::string;
+class Host {
+  string s;
+public:
+  string h1() & { return string(); }
+  string h2() const & { return string(); }
+  string h3() && { return std::move(string()); }
+  string h4() const && { return std::move(string()); }
+  string h5() const { return string(); }
+  string h6() volatile const & { return string(); }
+  string h7() const volatile & { return string(); }
+  string h8() volatile const && { return std::move(string()); }
+  string h9() const volatile && { return std::move(string()); }
+
+  string h() & { return string(); }
+  string h() const & { return string(); }
+  string h() && { return std::move(string()); }
+  string h() const && { return std::move(string()); }
+};
+%}
+
+// %feature testing
+%feature("except") F1() & %{ result = "F1"; %}
+%feature("except") F2 %{ result = "F2"; %}
+%feature("except") F3 %{ result = "F3"; %}
+%feature("except") F3() %{ _should_not_be_used_ %}
+
+%feature("except") C1(int i) const & %{ result = "C1"; %}
+%feature("except") C2 %{ result = "C2"; %}
+%feature("except") C3 %{ result = "C3"; %}
+%feature("except") C3(int i) %{ _should_not_be_used_ %}
+
+%inline %{
+struct Features {
+  string F1() & { return string(); }
+  string F2() & { return string(); }
+  string F3() & { return string(); }
+
+  string C1(int i) const & { return string(); }
+  string C2(int i) const & { return string(); }
+  string C3(int i) const & { return string(); }
+};
+%}
+
+// %rename testing
+%rename(RR1) R1;
+%rename(RR2) R2() &;
+%rename(RR3) R3;
+%rename(RR3Bad) R3();
+
+%rename(SS1) S1;
+%rename(SS2) S2(int i) const &;
+%rename(SS3) S3;
+%rename(SS3Bad) S3(int i);
+%rename(SS3BadConst) S3(int i) const;
+%rename(SS3BadLValue) S3(int i) &;
+
+%inline %{
+struct Renames {
+  string R1() & { return string(); }
+  string R2() & { return string(); }
+  string R3() & { return string(); }
+
+  string S1(int i) const & { return string(); }
+  string S2(int i) const & { return string(); }
+  string S3(int i) const & { return string(); }
+};
+%}
+
+// Conversion operators
+%rename(StringConvertCopy) operator string() &;
+%rename(StringConvertMove) operator string() &&;
+%feature("ignore", "0") operator string() &&; // unignore as it is ignored by default
+
+%inline %{
+struct ConversionOperators {
+  virtual operator string() & { return string(); }
+  virtual operator string() && { return std::move(string()); }
+  virtual ~ConversionOperators() {}
+};
+struct ConversionOperators2 {
+  virtual operator string() && { return std::move(string()); }
+  virtual ~ConversionOperators2() {}
+};
+%}
+
+%inline %{
+struct Funcs {
+  short FF(bool) { return 0; }
+  short CC(bool) const & { return 0; }
+};
+
+class MemberFuncPtrs
+{
+public:
+  // member ref-qualified function pointers, unnamed parameters
+  int aaa1(short (Funcs::*)(bool) &) const;
+  int aaa2(short (Funcs::* const *&)(bool) &) const;
+  int aaa3(short (Funcs::* *&)(bool) &) const;
+  int aaa4(short (Funcs::* *const&)(bool) &) const;
+  int aaa5(short (Funcs::* &)(bool) &) const;
+  int aaa6(short (Funcs::* const)(bool) &) const;
+  int aaa7(short (Funcs::* const&)(bool) &) const;
+
+  int aaa8(short (Funcs::* const&)(bool) &&) const;
+
+  // member cv-qualified and ref-qualified function pointers, unnamed parameters
+  int bbb1(short (Funcs::*)(bool) const &) const;
+  int bbb2(short (Funcs::* const *&)(bool) const &) const;
+  int bbb3(short (Funcs::* *&)(bool) const &) const;
+  int bbb4(short (Funcs::* *const&)(bool) const &) const;
+  int bbb5(short (Funcs::* &)(bool) const &) const;
+  int bbb6(short (Funcs::* const)(bool) const &) const;
+  int bbb7(short (Funcs::* const&)(bool) const &) const;
+
+  int bbb8(short (Funcs::*)(bool) const &&) const;
+
+  // member ref-qualified function pointers, named parameters
+  int qqq1(short (Funcs::* qq1)(bool) &) const;
+  int qqq2(short (Funcs::* const *& qq2)(bool) &) const;
+  int qqq3(short (Funcs::* *& qq3)(bool) &) const;
+  int qqq4(short (Funcs::* *const& qq4)(bool) &) const;
+  int qqq5(short (Funcs::* & qq5)(bool) &) const;
+  int qqq6(short (Funcs::* const qq6)(bool) &) const;
+  int qqq7(short (Funcs::* const& qq7)(bool) &) const;
+
+  int qqq8(short (Funcs::* const& qq8)(bool) &&) const;
+
+  // member cv-qualified and ref-qualified function pointers, named parameters
+  int rrr1(short (Funcs::* rr1)(bool) const &) const;
+  int rrr2(short (Funcs::* const *& rr2)(bool) const &) const;
+  int rrr3(short (Funcs::* *& rr3)(bool) const &) const;
+  int rrr4(short (Funcs::* *const& rr4)(bool) const &) const;
+  int rrr5(short (Funcs::* & rr5)(bool) const &) const;
+  int rrr6(short (Funcs::* const rr6)(bool) const &) const;
+  int rrr7(short (Funcs::* const& rr7)(bool) const &) const;
+
+  int rrr8(short (Funcs::* rr1)(bool) const &&) const;
+};
+
+// member ref-qualified function pointers, unnamed parameters
+int MemberFuncPtrs::aaa1(short (Funcs::*)(bool) &) const { return 0; }
+int MemberFuncPtrs::aaa2(short (Funcs::* const *&)(bool) &) const { return 0; }
+int MemberFuncPtrs::aaa3(short (Funcs::* *&)(bool) &) const { return 0; }
+int MemberFuncPtrs::aaa4(short (Funcs::* *const&)(bool) &) const { return 0; }
+int MemberFuncPtrs::aaa5(short (Funcs::* &)(bool) &) const { return 0; }
+int MemberFuncPtrs::aaa6(short (Funcs::* const)(bool) &) const { return 0; }
+int MemberFuncPtrs::aaa7(short (Funcs::* const&)(bool) &) const { return 0; }
+
+int MemberFuncPtrs::aaa8(short (Funcs::* const&)(bool) &&) const { return 0; }
+
+// member cv-qualified and ref-qualified function pointers, unnamed parameters
+int MemberFuncPtrs::bbb1(short (Funcs::*)(bool) const &) const { return 0; }
+int MemberFuncPtrs::bbb2(short (Funcs::* const *&)(bool) const &) const { return 0; }
+int MemberFuncPtrs::bbb3(short (Funcs::* *&)(bool) const &) const { return 0; }
+int MemberFuncPtrs::bbb4(short (Funcs::* *const&)(bool) const &) const { return 0; }
+int MemberFuncPtrs::bbb5(short (Funcs::* &)(bool) const &) const { return 0; }
+int MemberFuncPtrs::bbb6(short (Funcs::* const)(bool) const &) const { return 0; }
+int MemberFuncPtrs::bbb7(short (Funcs::* const&)(bool) const &) const { return 0; }
+
+int MemberFuncPtrs::bbb8(short (Funcs::*)(bool) const &&) const { return 0; }
+
+// member ref-qualified function pointers, named parameters
+int MemberFuncPtrs::qqq1(short (Funcs::* qq1)(bool) &) const { return 0; }
+int MemberFuncPtrs::qqq2(short (Funcs::* const *& qq2)(bool) &) const { return 0; }
+int MemberFuncPtrs::qqq3(short (Funcs::* *& qq3)(bool) &) const { return 0; }
+int MemberFuncPtrs::qqq4(short (Funcs::* *const& qq4)(bool) &) const { return 0; }
+int MemberFuncPtrs::qqq5(short (Funcs::* & qq5)(bool) &) const { return 0; }
+int MemberFuncPtrs::qqq6(short (Funcs::* const qq6)(bool) &) const { return 0; }
+int MemberFuncPtrs::qqq7(short (Funcs::* const& qq7)(bool) &) const { return 0; }
+
+int MemberFuncPtrs::qqq8(short (Funcs::* const& qq8)(bool) &&) const { return 0; }
+
+// member cv-qualified and ref-qualified function pointers, named parameters
+int MemberFuncPtrs::rrr1(short (Funcs::* rr1)(bool) const &) const { return 0; }
+int MemberFuncPtrs::rrr2(short (Funcs::* const *& rr2)(bool) const &) const { return 0; }
+int MemberFuncPtrs::rrr3(short (Funcs::* *& rr3)(bool) const &) const { return 0; }
+int MemberFuncPtrs::rrr4(short (Funcs::* *const& rr4)(bool) const &) const { return 0; }
+int MemberFuncPtrs::rrr5(short (Funcs::* & rr5)(bool) const &) const { return 0; }
+int MemberFuncPtrs::rrr6(short (Funcs::* const rr6)(bool) const &) const { return 0; }
+int MemberFuncPtrs::rrr7(short (Funcs::* const& rr7)(bool) const &) const { return 0; }
+
+int MemberFuncPtrs::rrr8(short (Funcs::* rr1)(bool) const &&) const { return 0; }
+
+// member cv-qualified and ref-qualified pointer variables
+short (Funcs::* cc1)(bool) const & = &Funcs::CC;
+
+short (Funcs::* const * ccextra2)(bool) const & = &cc1;
+short (Funcs::* * ccextra3)(bool) const & = &cc1;
+short (Funcs::* *const ccextra4)(bool) const & = &cc1;
+
+short (Funcs::* const *& cc2)(bool) const & = ccextra2;
+short (Funcs::* *& cc3)(bool) const & = ccextra3;
+short (Funcs::* *const& cc4)(bool) const & = ccextra4;
+short (Funcs::* & cc5)(bool) const & = cc1;
+short (Funcs::* const cc6)(bool) const & = &Funcs::CC;
+short (Funcs::* const& cc7)(bool) const & = cc1;
+%}
+
+%inline %{
+
+struct Funktions {
+  int addByValue(const int &a, int b) const & { return a+b; }
+  int * addByPointer(const int &a, int b) const & { static int val; val = a+b; return &val; }
+  int & addByReference(const int &a, int b) const & { static int val; val = a+b; return val; }
+};
+
+int call1(int (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return (f.*d)(a, b); }
+//int call2(int * (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return *(f.*d)(a, b); }
+//int call3(int & (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return (f.*d)(a, b); }
+%}
+%constant int (Funktions::*ADD_BY_VALUE)(const int &, int) const & = &Funktions::addByValue;
diff --git a/Examples/test-suite/cpp11_ref_qualifiers_rvalue_unignore.i b/Examples/test-suite/cpp11_ref_qualifiers_rvalue_unignore.i
new file mode 100644
index 0000000..2f5fadf
--- /dev/null
+++ b/Examples/test-suite/cpp11_ref_qualifiers_rvalue_unignore.i
@@ -0,0 +1,15 @@
+%module cpp11_ref_qualifiers_rvalue_unignore
+
+// This is a minimal test that does not include any C++ headers to make sure the required
+// <memory> header is generated from a fragment for the generated std::move call
+
+// m1 and m2 are ignored by default, unignore them
+%feature("ignore", "0") RefQualifier::m1() &&;
+%feature("ignore", "0") RefQualifier::m2() const &&;
+
+%inline %{
+struct RefQualifier {
+  void m1() && {}
+  void m2() const && {}
+};
+%}
diff --git a/Examples/test-suite/cpp11_ref_qualifiers_typemaps.i b/Examples/test-suite/cpp11_ref_qualifiers_typemaps.i
new file mode 100644
index 0000000..0e1c3fe
--- /dev/null
+++ b/Examples/test-suite/cpp11_ref_qualifiers_typemaps.i
@@ -0,0 +1,74 @@
+%module cpp11_ref_qualifiers_typemaps
+
+%typemap(in) SWIGTYPE (CLASS::*) %{
+  _this_will_fail_to_compile_if_used_
+%}
+
+// typemaps to completely ignore the input parm and override it
+%typemap(in) short (Funcs::*ff)(bool) const   %{ $1 = &Funcs::FFF2; %}
+%typemap(in) short (Funcs::*cc)(bool) &       %{ $1 = &Funcs::CCC5; %}
+%typemap(in) short (Funcs::*gg)(bool) const & %{ $1 = &Funcs::GGG8; %}
+%typemap(in) short (Funcs::*hh)(bool) &&      %{ $1 = &Funcs::HHH11; %}
+
+%typemap(in) short (Funcs::*)(bool) const   %{ $1 = &Funcs::FFF3; %}
+%typemap(in) short (Funcs::*)(bool) &       %{ $1 = &Funcs::CCC6; %}
+%typemap(in) short (Funcs::*)(bool) const & %{ $1 = &Funcs::GGG9; %}
+%typemap(in) short (Funcs::*)(bool) &&      %{ $1 = &Funcs::HHH12; %}
+
+%inline %{
+struct Funcs {
+  short FFF1(bool) const { return 1; }
+  short FFF2(bool) const { return 2; }
+  short FFF3(bool) const { return 3; }
+  short CCC4(bool) & { return 4; }
+  short CCC5(bool) & { return 5; }
+  short CCC6(bool) & { return 6; }
+  short GGG7(bool) const & { return 7; }
+  short GGG8(bool) const & { return 8; }
+  short GGG9(bool) const & { return 9; }
+  short HHH10(bool) && { return 10; }
+  short HHH11(bool) && { return 11; }
+  short HHH12(bool) && { return 12; }
+};
+struct TypemapsNamedParms
+{
+  short fff(short (Funcs::*ff)(bool) const) {
+    Funcs funcs;
+    return (funcs.*ff)(true);
+  }
+  short ccc(short (Funcs::*cc)(bool) &) {
+    Funcs funcs;
+    return (funcs.*cc)(true);
+  }
+  short ggg(short (Funcs::*gg)(bool) const &) {
+    Funcs funcs;
+    return (funcs.*gg)(true);
+  }
+  short hhh(short (Funcs::*hh)(bool) &&) {
+    return (Funcs().*hh)(true);
+  }
+};
+struct TypemapsUnnamedParms
+{
+  short fff(short (Funcs::*f)(bool) const) {
+    Funcs funcs;
+    return (funcs.*f)(true);
+  }
+  short ccc(short (Funcs::*c)(bool) &) {
+    Funcs funcs;
+    return (funcs.*c)(true);
+  }
+  short ggg(short (Funcs::*g)(bool) const &) {
+    Funcs funcs;
+    return (funcs.*g)(true);
+  }
+  short hhh(short (Funcs::*h)(bool) &&) {
+    return (Funcs().*h)(true);
+  }
+};
+%}
+
+%constant short (Funcs::*FF1_MFP)(bool) const = &Funcs::FFF1;
+%constant short (Funcs::*CC4_MFP)(bool) & = &Funcs::CCC4;
+%constant short (Funcs::*GG7_MFP)(bool) const & = &Funcs::GGG7;
+%constant short (Funcs::*HH10_MFP)(bool) && = &Funcs::HHH10;
diff --git a/Examples/test-suite/csharp/preproc_constants_c_runme.cs b/Examples/test-suite/csharp/preproc_constants_c_runme.cs
index 76c684d..5966d52 100644
--- a/Examples/test-suite/csharp/preproc_constants_c_runme.cs
+++ b/Examples/test-suite/csharp/preproc_constants_c_runme.cs
@@ -36,7 +36,7 @@
     assert( typeof(string) == preproc_constants_c.CONST_STRING2.GetType() );
 
     assert( typeof(int) == preproc_constants_c.INT_AND_BOOL.GetType() );
-//    assert( typeof(int) == preproc_constants_c.INT_AND_CHAR.GetType() );
+    assert( typeof(int) == preproc_constants_c.INT_AND_CHAR.GetType() );
     assert( typeof(int) == preproc_constants_c.INT_AND_INT.GetType() );
     assert( typeof(uint) == preproc_constants_c.INT_AND_UINT.GetType() );
     assert( typeof(int) == preproc_constants_c.INT_AND_LONG.GetType() );
@@ -61,7 +61,9 @@
     assert( typeof(int) == preproc_constants_c.EXPR_LAND.GetType() );
     assert( typeof(int) == preproc_constants_c.EXPR_LOR.GetType() );
     assert( typeof(double) == preproc_constants_c.EXPR_CONDITIONAL.GetType() );
-
+    assert( typeof(double) == preproc_constants_c.EXPR_MIXED1.GetType() );
+    assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MAX.GetType() );
+    assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MIN.GetType() );
   }
   static void assert(bool assertion) {
     if (!assertion)
diff --git a/Examples/test-suite/csharp/preproc_constants_runme.cs b/Examples/test-suite/csharp/preproc_constants_runme.cs
index 9fae591..6af8f20 100644
--- a/Examples/test-suite/csharp/preproc_constants_runme.cs
+++ b/Examples/test-suite/csharp/preproc_constants_runme.cs
@@ -35,7 +35,7 @@
     assert( typeof(string) == preproc_constants.CONST_STRING2.GetType() );
 
     assert( typeof(int) == preproc_constants.INT_AND_BOOL.GetType() );
-//    assert( typeof(int) == preproc_constants.INT_AND_CHAR.GetType() );
+    assert( typeof(int) == preproc_constants.INT_AND_CHAR.GetType() );
     assert( typeof(int) == preproc_constants.INT_AND_INT.GetType() );
     assert( typeof(uint) == preproc_constants.INT_AND_UINT.GetType() );
     assert( typeof(int) == preproc_constants.INT_AND_LONG.GetType() );
@@ -60,6 +60,9 @@
     assert( typeof(bool) == preproc_constants.EXPR_LAND.GetType() );
     assert( typeof(bool) == preproc_constants.EXPR_LOR.GetType() );
     assert( typeof(double) == preproc_constants.EXPR_CONDITIONAL.GetType() );
+    assert( typeof(double) == preproc_constants.EXPR_MIXED1.GetType() );
+    assert( typeof(int) == preproc_constants.EXPR_WCHAR_MAX.GetType() );
+    assert( typeof(int) == preproc_constants.EXPR_WCHAR_MIN.GetType() );
 
   }
   static void assert(bool assertion) {
diff --git a/Examples/test-suite/d/preproc_constants_c_runme.1.d b/Examples/test-suite/d/preproc_constants_c_runme.1.d
index d846c71..a6c2f3d 100644
--- a/Examples/test-suite/d/preproc_constants_c_runme.1.d
+++ b/Examples/test-suite/d/preproc_constants_c_runme.1.d
@@ -36,7 +36,7 @@
   static assert(is(char[] == typeof(CONST_STRING2())));
 
   static assert(is(int == typeof(INT_AND_BOOL())));
-//    static assert(is(int == typeof(INT_AND_CHAR())));
+  static assert(is(int == typeof(INT_AND_CHAR())));
   static assert(is(int == typeof(INT_AND_INT())));
   static assert(is(uint == typeof(INT_AND_UINT())));
   static assert(is(c_long == typeof(INT_AND_LONG())));
@@ -61,4 +61,7 @@
   static assert(is(int == typeof(EXPR_LAND())));
   static assert(is(int == typeof(EXPR_LOR())));
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
+  static assert(is(double == typeof(EXPR_MIXED1())));
+  static assert(is(int == typeof(EXPR_WCHAR_MAX())));
+  static assert(is(int == typeof(EXPR_WCHAR_MIN())));
 }
diff --git a/Examples/test-suite/d/preproc_constants_c_runme.2.d b/Examples/test-suite/d/preproc_constants_c_runme.2.d
index 9bdbb93..786cb48 100644
--- a/Examples/test-suite/d/preproc_constants_c_runme.2.d
+++ b/Examples/test-suite/d/preproc_constants_c_runme.2.d
@@ -36,7 +36,7 @@
   static assert(is(string == typeof(CONST_STRING2())));
 
   static assert(is(int == typeof(INT_AND_BOOL())));
-//    static assert(is(int == typeof(INT_AND_CHAR())));
+  static assert(is(int == typeof(INT_AND_CHAR())));
   static assert(is(int == typeof(INT_AND_INT())));
   static assert(is(uint == typeof(INT_AND_UINT())));
   static assert(is(c_long == typeof(INT_AND_LONG())));
@@ -61,4 +61,7 @@
   static assert(is(int == typeof(EXPR_LAND())));
   static assert(is(int == typeof(EXPR_LOR())));
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
+  static assert(is(double == typeof(EXPR_MIXED1())));
+  static assert(is(int == typeof(EXPR_WCHAR_MAX())));
+  static assert(is(int == typeof(EXPR_WCHAR_MIN())));
 }
diff --git a/Examples/test-suite/d/preproc_constants_runme.1.d b/Examples/test-suite/d/preproc_constants_runme.1.d
index 009405f..85fa918 100644
--- a/Examples/test-suite/d/preproc_constants_runme.1.d
+++ b/Examples/test-suite/d/preproc_constants_runme.1.d
@@ -35,7 +35,7 @@
   static assert(is(char[] == typeof(CONST_STRING2())));
 
   static assert(is(int == typeof(INT_AND_BOOL())));
-//    static assert(is(int == typeof(INT_AND_CHAR())));
+  static assert(is(int == typeof(INT_AND_CHAR())));
   static assert(is(int == typeof(INT_AND_INT())));
   static assert(is(uint == typeof(INT_AND_UINT())));
   static assert(is(c_long == typeof(INT_AND_LONG())));
@@ -60,4 +60,7 @@
   static assert(is(bool == typeof(EXPR_LAND())));
   static assert(is(bool == typeof(EXPR_LOR())));
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
+  static assert(is(double == typeof(EXPR_MIXED1())));
+  static assert(is(int == typeof(EXPR_WCHAR_MAX())));
+  static assert(is(int == typeof(EXPR_WCHAR_MIN())));
 }
diff --git a/Examples/test-suite/d/preproc_constants_runme.2.d b/Examples/test-suite/d/preproc_constants_runme.2.d
index 2d92ef0..c81e531 100644
--- a/Examples/test-suite/d/preproc_constants_runme.2.d
+++ b/Examples/test-suite/d/preproc_constants_runme.2.d
@@ -35,7 +35,7 @@
   static assert(is(string == typeof(CONST_STRING2())));
 
   static assert(is(int == typeof(INT_AND_BOOL())));
-//    static assert(is(int == typeof(INT_AND_CHAR())));
+  static assert(is(int == typeof(INT_AND_CHAR())));
   static assert(is(int == typeof(INT_AND_INT())));
   static assert(is(uint == typeof(INT_AND_UINT())));
   static assert(is(c_long == typeof(INT_AND_LONG())));
@@ -60,4 +60,7 @@
   static assert(is(bool == typeof(EXPR_LAND())));
   static assert(is(bool == typeof(EXPR_LOR())));
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
+  static assert(is(double == typeof(EXPR_MIXED1())));
+  static assert(is(int == typeof(EXPR_WCHAR_MAX())));
+  static assert(is(int == typeof(EXPR_WCHAR_MIN())));
 }
diff --git a/Examples/test-suite/errors/cpp_invalid_qualifiers.i b/Examples/test-suite/errors/cpp_invalid_qualifiers.i
new file mode 100644
index 0000000..fd3b363
--- /dev/null
+++ b/Examples/test-suite/errors/cpp_invalid_qualifiers.i
@@ -0,0 +1,43 @@
+%module cpp_invalid_qualifiers
+
+// Constructors, destructors and static methods cannot have qualifiers
+struct A {
+  ~A() const;
+};
+struct B {
+  virtual ~B() const;
+};
+struct C {
+  ~C() &;
+};
+struct D {
+  virtual ~D() &;
+};
+struct E {
+  ~E() &&;
+};
+struct F {
+  virtual ~F() &&;
+};
+
+struct J {
+  J() const;
+  J(int) const;
+};
+struct K {
+  K() &;
+  K(int) &;
+};
+struct L {
+  L() &&;
+  L(int) &&;
+};
+
+struct M {
+  static void m1() const;
+  static void m2() &;
+  thread_local static void m3() &&;
+  static auto m4() const -> int;
+  static auto m5() & -> int;
+  static auto m6() && -> int;
+};
diff --git a/Examples/test-suite/errors/cpp_invalid_qualifiers.stderr b/Examples/test-suite/errors/cpp_invalid_qualifiers.stderr
new file mode 100644
index 0000000..7b3e442
--- /dev/null
+++ b/Examples/test-suite/errors/cpp_invalid_qualifiers.stderr
@@ -0,0 +1,20 @@
+cpp_invalid_qualifiers.i:5: Error: Destructor ~A() const cannot have a qualifier.
+cpp_invalid_qualifiers.i:8: Error: Destructor ~B() const cannot have a qualifier.
+cpp_invalid_qualifiers.i:11: Error: Destructor ~C() & cannot have a qualifier.
+cpp_invalid_qualifiers.i:14: Error: Destructor ~D() & cannot have a qualifier.
+cpp_invalid_qualifiers.i:17: Error: Destructor ~E() && cannot have a qualifier.
+cpp_invalid_qualifiers.i:20: Error: Destructor ~F() && cannot have a qualifier.
+cpp_invalid_qualifiers.i:24: Error: Constructor cannot have a qualifier.
+cpp_invalid_qualifiers.i:25: Error: Constructor cannot have a qualifier.
+cpp_invalid_qualifiers.i:28: Error: Constructor cannot have a qualifier.
+cpp_invalid_qualifiers.i:29: Error: Constructor cannot have a qualifier.
+cpp_invalid_qualifiers.i:32: Error: Constructor cannot have a qualifier.
+cpp_invalid_qualifiers.i:33: Error: Constructor cannot have a qualifier.
+cpp_invalid_qualifiers.i:37: Error: Static function m1() const cannot have a qualifier.
+cpp_invalid_qualifiers.i:38: Error: Static function m2() & cannot have a qualifier.
+cpp_invalid_qualifiers.i:39: Error: Static function m3() && cannot have a qualifier.
+cpp_invalid_qualifiers.i:39: Warning 405: Method with rvalue ref-qualifier m3() && ignored.
+cpp_invalid_qualifiers.i:40: Error: Static function m4() const cannot have a qualifier.
+cpp_invalid_qualifiers.i:41: Error: Static function m5() & cannot have a qualifier.
+cpp_invalid_qualifiers.i:42: Error: Static function m6() && cannot have a qualifier.
+cpp_invalid_qualifiers.i:42: Warning 405: Method with rvalue ref-qualifier m6() && ignored.
diff --git a/Examples/test-suite/errors/cpp_refqualifier.i b/Examples/test-suite/errors/cpp_refqualifier.i
new file mode 100644
index 0000000..afd6632
--- /dev/null
+++ b/Examples/test-suite/errors/cpp_refqualifier.i
@@ -0,0 +1,28 @@
+%module cpp_refqualifier
+
+%ignore Host::h_ignored;
+%ignore Host::i_ignored() &&;
+%ignore Host::j_ignored() const &&;
+
+class Host {
+public:
+  void h1() &;
+  void h2() const &;
+  void h3() &&;
+  void h4() const &&;
+
+  void h() &;
+  void h() const &;
+  void h() &&;
+  void h() const &&;
+
+  void h_ignored() &&;
+  void i_ignored() &&;
+  void i_ignored() &&;
+};
+
+%feature("ignore", "0") Unignore::k_unignored() const &&;
+
+struct Unignore {
+  void k_unignored() const &&;
+};
diff --git a/Examples/test-suite/errors/cpp_refqualifier.stderr b/Examples/test-suite/errors/cpp_refqualifier.stderr
new file mode 100644
index 0000000..ea2cd22
--- /dev/null
+++ b/Examples/test-suite/errors/cpp_refqualifier.stderr
@@ -0,0 +1,6 @@
+cpp_refqualifier.i:11: Warning 405: Method with rvalue ref-qualifier h3() && ignored.
+cpp_refqualifier.i:12: Warning 405: Method with rvalue ref-qualifier h4() const && ignored.
+cpp_refqualifier.i:16: Warning 405: Method with rvalue ref-qualifier h() && ignored.
+cpp_refqualifier.i:17: Warning 405: Method with rvalue ref-qualifier h() const && ignored.
+cpp_refqualifier.i:15: Warning 512: Overloaded method Host::h() const & ignored,
+cpp_refqualifier.i:14: Warning 512: using non-const method Host::h() & instead.
diff --git a/Examples/test-suite/java/cpp11_ref_qualifiers_runme.java b/Examples/test-suite/java/cpp11_ref_qualifiers_runme.java
new file mode 100644
index 0000000..4755f8d
--- /dev/null
+++ b/Examples/test-suite/java/cpp11_ref_qualifiers_runme.java
@@ -0,0 +1,56 @@
+
+import cpp11_ref_qualifiers.*;
+
+public class cpp11_ref_qualifiers_runme {
+
+  static {
+    try {
+      System.loadLibrary("cpp11_ref_qualifiers");
+    } 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[]) {
+    Host h = new Host();
+
+    // Basic testing
+    h.h1();
+    h.h2();
+    h.h6();
+    h.h7();
+
+    h.h();
+
+    // %feature testing
+    Features f = new Features();
+    if (!f.F1().equals("F1")) throw new RuntimeException("Fail");
+    if (!f.F2().equals("F2")) throw new RuntimeException("Fail");
+    if (!f.F3().equals("F3")) throw new RuntimeException("Fail");
+
+    if (!f.C1(0).equals("C1")) throw new RuntimeException("Fail");
+    if (!f.C2(0).equals("C2")) throw new RuntimeException("Fail");
+    if (!f.C3(0).equals("C3")) throw new RuntimeException("Fail");
+
+    // %rename testing
+    Renames r = new Renames();
+    r.RR1();
+    r.RR2();
+    r.RR3();
+
+    r.SS1(0);
+    r.SS2(0);
+    r.SS3(0);
+
+    // Conversion operators
+    String s = null;
+    ConversionOperators co = new ConversionOperators();
+    s = co.StringConvertCopy();
+    s = co.StringConvertMove();
+
+    ConversionOperators2 co2 = new ConversionOperators2();
+    s = co2.StringConvertMove();
+  }
+}
+
diff --git a/Examples/test-suite/java/cpp11_ref_qualifiers_rvalue_unignore_runme.java b/Examples/test-suite/java/cpp11_ref_qualifiers_rvalue_unignore_runme.java
new file mode 100644
index 0000000..bbbe6f7
--- /dev/null
+++ b/Examples/test-suite/java/cpp11_ref_qualifiers_rvalue_unignore_runme.java
@@ -0,0 +1,20 @@
+
+import cpp11_ref_qualifiers_rvalue_unignore.*;
+
+public class cpp11_ref_qualifiers_rvalue_unignore_runme {
+
+  static {
+    try {
+      System.loadLibrary("cpp11_ref_qualifiers_rvalue_unignore");
+    } 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[]) {
+    new RefQualifier().m1();
+    new RefQualifier().m2();
+  }
+}
+
diff --git a/Examples/test-suite/java/cpp11_ref_qualifiers_typemaps_runme.java b/Examples/test-suite/java/cpp11_ref_qualifiers_typemaps_runme.java
new file mode 100644
index 0000000..8c6a21b
--- /dev/null
+++ b/Examples/test-suite/java/cpp11_ref_qualifiers_typemaps_runme.java
@@ -0,0 +1,39 @@
+import cpp11_ref_qualifiers_typemaps.*;
+
+public class cpp11_ref_qualifiers_typemaps_runme {
+  static {
+    try {
+      System.loadLibrary("cpp11_ref_qualifiers_typemaps");
+    } 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[]) 
+  {
+    {
+      TypemapsNamedParms tm = new TypemapsNamedParms();
+      if (tm.fff(cpp11_ref_qualifiers_typemaps.FF1_MFP) != 2)
+        throw new RuntimeException("failed");
+      if (tm.ccc(cpp11_ref_qualifiers_typemaps.CC4_MFP) != 5)
+        throw new RuntimeException("failed");
+      if (tm.ggg(cpp11_ref_qualifiers_typemaps.GG7_MFP) != 8)
+        throw new RuntimeException("failed");
+      if (tm.hhh(cpp11_ref_qualifiers_typemaps.HH10_MFP) != 11)
+        throw new RuntimeException("failed");
+    }
+    {
+      TypemapsUnnamedParms tm = new TypemapsUnnamedParms();
+      if (tm.fff(cpp11_ref_qualifiers_typemaps.FF1_MFP) != 3)
+        throw new RuntimeException("failed");
+      if (tm.ccc(cpp11_ref_qualifiers_typemaps.CC4_MFP) != 6)
+        throw new RuntimeException("failed");
+      if (tm.ggg(cpp11_ref_qualifiers_typemaps.GG7_MFP) != 9)
+        throw new RuntimeException("failed");
+      if (tm.hhh(cpp11_ref_qualifiers_typemaps.HH10_MFP) != 12)
+        throw new RuntimeException("failed");
+    }
+  }
+}
+
diff --git a/Examples/test-suite/member_funcptr_galore.i b/Examples/test-suite/member_funcptr_galore.i
index 27d7a38..27c2f02 100644
--- a/Examples/test-suite/member_funcptr_galore.i
+++ b/Examples/test-suite/member_funcptr_galore.i
@@ -6,6 +6,12 @@
 %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) pp3;
 %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) pp5;
 
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra2;
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra3;
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc2;
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc3;
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc5;
+
 %{
 #if defined(__SUNPRO_CC)
 #pragma error_messages (off, badargtype2w) /* Formal argument ... is being passed extern "C" ... */
@@ -155,7 +161,7 @@
     int qqq7(short (Funcs::* const& qq7)(bool)) const;
 };
 
-    // member const function pointers, unnamed parameters
+// member const function pointers, unnamed parameters
 int MemberFuncPtrs::aaa1(short (Funcs::* )(bool) const) const { return 0; }
 int MemberFuncPtrs::aaa2(short (Funcs::* const *&)(bool) const) const { return 0; }
 int MemberFuncPtrs::aaa3(short (Funcs::* *& )(bool) const) const { return 0; }
@@ -191,7 +197,7 @@
 int MemberFuncPtrs::qqq6(short (Funcs::* const qq6)(bool)) const { return 0; }
 int MemberFuncPtrs::qqq7(short (Funcs::* const& qq7)(bool)) const { return 0; }
 
-// member function pointer variables
+// member non-const function pointer variables
 short (Funcs::* pp1)(bool) = &Funcs::FF;
 
 short (Funcs::* const * extra2)(bool) = &pp1;
@@ -204,4 +210,18 @@
 short (Funcs::* & pp5)(bool) = pp1;
 short (Funcs::* const pp6)(bool) = &Funcs::FF;
 short (Funcs::* const& pp7)(bool) = pp1;
+
+// member const function pointer variables
+short (Funcs::* cc1)(bool) const = &Funcs::CC;
+
+short (Funcs::* const * ccextra2)(bool) const = &cc1;
+short (Funcs::* * ccextra3)(bool) const = &cc1;
+short (Funcs::* *const ccextra4)(bool) const = &cc1;
+
+short (Funcs::* const *& cc2)(bool) const = ccextra2;
+short (Funcs::* *& cc3)(bool) const = ccextra3;
+short (Funcs::* *const& cc4)(bool) const = ccextra4;
+short (Funcs::* & cc5)(bool) const = cc1;
+short (Funcs::* const cc6)(bool) const = &Funcs::CC;
+short (Funcs::* const& cc7)(bool) const = cc1;
 %}
diff --git a/Examples/test-suite/php/preproc_constants_c_runme.php b/Examples/test-suite/php/preproc_constants_c_runme.php
index af9b76e..20868dc 100644
--- a/Examples/test-suite/php/preproc_constants_c_runme.php
+++ b/Examples/test-suite/php/preproc_constants_c_runme.php
@@ -62,5 +62,8 @@
 check::equal(gettype(preproc_constants_c::EXPR_LAND), "integer", "preproc_constants.EXPR_LAND has unexpected type");
 check::equal(gettype(preproc_constants_c::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
 check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_MIXED1), "double", "preproc_constants.EXPR_MIXED1 has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
 
 ?>
diff --git a/Examples/test-suite/php/preproc_constants_runme.php b/Examples/test-suite/php/preproc_constants_runme.php
index 5c9119b..ef32867 100644
--- a/Examples/test-suite/php/preproc_constants_runme.php
+++ b/Examples/test-suite/php/preproc_constants_runme.php
@@ -61,5 +61,8 @@
 check::equal(gettype(preproc_constants::EXPR_LAND), "boolean", "preproc_constants.EXPR_LAND has unexpected type");
 check::equal(gettype(preproc_constants::EXPR_LOR), "boolean", "preproc_constants.EXPR_LOR has unexpected type");
 check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_MIXED1), "integer", "preproc_constants.EXPR_MIXED1 has unexpected type");
 
 ?>
diff --git a/Examples/test-suite/php5/preproc_constants_c_runme.php b/Examples/test-suite/php5/preproc_constants_c_runme.php
index 1ea0195..d55d423 100644
--- a/Examples/test-suite/php5/preproc_constants_c_runme.php
+++ b/Examples/test-suite/php5/preproc_constants_c_runme.php
@@ -62,5 +62,8 @@
 check::equal(gettype(preproc_constants_c::EXPR_LAND), "integer", "preproc_constants.EXPR_LAND has unexpected type");
 check::equal(gettype(preproc_constants_c::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
 check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_MIXED1), "double", "preproc_constants.EXPR_MIXED1 has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
 
 ?>
diff --git a/Examples/test-suite/php5/preproc_constants_runme.php b/Examples/test-suite/php5/preproc_constants_runme.php
index fb9ee4f..01137b0 100644
--- a/Examples/test-suite/php5/preproc_constants_runme.php
+++ b/Examples/test-suite/php5/preproc_constants_runme.php
@@ -70,5 +70,8 @@
 check::equal(gettype(preproc_constants::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
 
 check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_MIXED1), "double", "preproc_constants.EXPR_MIXED1 has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
 
 ?>
diff --git a/Examples/test-suite/preproc_constants.i b/Examples/test-suite/preproc_constants.i
index 3a999ad..628cae1 100644
--- a/Examples/test-suite/preproc_constants.i
+++ b/Examples/test-suite/preproc_constants.i
@@ -86,6 +86,10 @@
 #define EXPR_LAND        0xFF && 1
 #define EXPR_LOR         0xFF || 1
 #define EXPR_CONDITIONAL true ? 2 : 2.2
+#define EXPR_MIXED1      (0x80 + 11.1) - 1
+
+#define EXPR_WCHAR_MAX   (0x7fffffff + L'\0')
+#define EXPR_WCHAR_MIN   (-EXPR_WCHAR_MAX - 1)
 
 #define EXPR_CHAR_COMPOUND_ADD 'A' + 12
 #define EXPR_CHAR_COMPOUND_LSHIFT 'B' << 6
diff --git a/Examples/test-suite/python/cpp11_ref_qualifiers_runme.py b/Examples/test-suite/python/cpp11_ref_qualifiers_runme.py
new file mode 100644
index 0000000..d3aa98c
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_ref_qualifiers_runme.py
@@ -0,0 +1,45 @@
+import cpp11_ref_qualifiers
+
+h = cpp11_ref_qualifiers.Host()
+
+# Basic testing
+h.h1()
+h.h2()
+h.h6()
+h.h7()
+
+h.h()
+
+# %feature testing
+f = cpp11_ref_qualifiers.Features()
+if f.F1() != "F1":
+    raise RuntimeException("Fail")
+if f.F2() != "F2":
+    raise RuntimeException("Fail")
+if f.F3() != "F3":
+    raise RuntimeException("Fail")
+
+if f.C1(0) != "C1":
+    raise RuntimeException("Fail")
+if f.C2(0) != "C2":
+    raise RuntimeException("Fail")
+if f.C3(0) != "C3":
+    raise RuntimeException("Fail")
+
+# %rename testing
+r = cpp11_ref_qualifiers.Renames()
+r.RR1()
+r.RR2()
+r.RR3()
+
+r.SS1(0)
+r.SS2(0)
+r.SS3(0)
+
+# Conversion operators
+co = cpp11_ref_qualifiers.ConversionOperators()
+s = co.StringConvertCopy()
+s = co.StringConvertMove()
+
+co2 = cpp11_ref_qualifiers.ConversionOperators2()
+s = co2.StringConvertMove()
diff --git a/Examples/test-suite/python/cpp11_ref_qualifiers_rvalue_unignore_runme.py b/Examples/test-suite/python/cpp11_ref_qualifiers_rvalue_unignore_runme.py
new file mode 100644
index 0000000..6352c79
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_ref_qualifiers_rvalue_unignore_runme.py
@@ -0,0 +1,4 @@
+import cpp11_ref_qualifiers_rvalue_unignore
+
+cpp11_ref_qualifiers_rvalue_unignore.RefQualifier().m1()
+cpp11_ref_qualifiers_rvalue_unignore.RefQualifier().m2()
diff --git a/Examples/test-suite/template_empty_inherit.i b/Examples/test-suite/template_empty_inherit.i
index 308a01f..5677b8b 100644
--- a/Examples/test-suite/template_empty_inherit.i
+++ b/Examples/test-suite/template_empty_inherit.i
@@ -5,6 +5,7 @@
 %inline %{
 template<class Arg, typename Result> struct Functor {
   virtual Result operator()(Arg x) const = 0;
+  virtual ~Functor() {}
 };
 %}
 
diff --git a/Lib/java/std_array.i b/Lib/java/std_array.i
index f75857e..0944d93 100644
--- a/Lib/java/std_array.i
+++ b/Lib/java/std_array.i
@@ -8,13 +8,13 @@
 
   template<class T, size_t N> class array {
   public:
-    typedef T& reference;
-    typedef const T& const_reference;
     typedef size_t size_type;
     typedef ptrdiff_t difference_type;
     typedef T value_type;
-    typedef T* pointer;
-    typedef const T* const_pointer;
+    typedef T &reference;
+    typedef const T &const_reference;
+    typedef T *pointer;
+    typedef const T *const_pointer;
     array();
     array(const array& other);
     size_type size() const;
diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg
index 4fd1947..99903a9 100644
--- a/Lib/python/builtin.swg
+++ b/Lib/python/builtin.swg
@@ -393,10 +393,10 @@
 
 SWIGINTERN void
 SwigPyBuiltin_InitBases (PyTypeObject *type, PyTypeObject **bases) {
-  int base_count = 0;
+  Py_ssize_t base_count = 0;
   PyTypeObject **b;
   PyObject *tuple;
-  int i;
+  Py_ssize_t i;
 
   if (!bases[0]) {
     bases[0] = SwigPyObject_type();
diff --git a/Lib/python/pyruntime.swg b/Lib/python/pyruntime.swg
index fad97be..26d3081 100644
--- a/Lib/python/pyruntime.swg
+++ b/Lib/python/pyruntime.swg
@@ -3,7 +3,7 @@
 /* Use debug wrappers with the Python release dll */
 # undef _DEBUG
 # include <Python.h>
-# define _DEBUG
+# define _DEBUG 1
 #else
 # include <Python.h>
 #endif
diff --git a/Lib/swig.swg b/Lib/swig.swg
index 6f48f0d..6dc215d 100644
--- a/Lib/swig.swg
+++ b/Lib/swig.swg
@@ -309,11 +309,13 @@
 
 %define %$classname      %$ismember,"match$parentNode$name"  %enddef
 %define %$isnested       "match$nested"="1"  %enddef
+
 /* -----------------------------------------------------------------------------
- * Include all the warnings labels and macros 
+ * Common includes for warning labels, macros, fragments etc
  * ----------------------------------------------------------------------------- */
 
 %include <swigwarnings.swg>
+%include <swigfragments.swg>
 
 /* -----------------------------------------------------------------------------
  * Overloading support
diff --git a/Lib/swigfragments.swg b/Lib/swigfragments.swg
new file mode 100644
index 0000000..63bb6c8
--- /dev/null
+++ b/Lib/swigfragments.swg
@@ -0,0 +1,86 @@
+/* -----------------------------------------------------------------------------
+ * swigfragments.swg
+ *
+ * Common fragments
+ * ----------------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Fragments for C header files
+ * ----------------------------------------------------------------------------- */
+
+%fragment("<float.h>", "header") %{
+#include <float.h>
+%}
+
+/* Default compiler options for gcc allow long_long but not LLONG_MAX. 
+ * Define SWIG_NO_LLONG_MAX if this added limits support is not wanted. */
+%fragment("<limits.h>", "header") %{
+#include <limits.h>
+#if !defined(SWIG_NO_LLONG_MAX)
+# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__)
+#   define LLONG_MAX __LONG_LONG_MAX__
+#   define LLONG_MIN (-LLONG_MAX - 1LL)
+#   define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
+# endif
+#endif
+%}
+
+%fragment("<math.h>", "header") %{
+#include <math.h>
+%}
+
+%fragment("<stddef.h>", "header") %{
+#include <stddef.h>
+%}
+
+%fragment("<stdio.h>", "header") %{
+#include <stdio.h>
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
+# ifndef snprintf
+#  define snprintf _snprintf
+# endif
+#endif
+%}
+
+%fragment("<stdlib.h>", "header") %{
+#include <stdlib.h>
+#ifdef _MSC_VER
+# ifndef strtoull
+#  define strtoull _strtoui64
+# endif
+# ifndef strtoll
+#  define strtoll _strtoi64
+# endif
+#endif
+%}
+
+%fragment("<wchar.h>", "header") %{
+#include <wchar.h>
+#include <limits.h>
+#ifndef WCHAR_MIN
+#  define WCHAR_MIN 0
+#endif
+#ifndef WCHAR_MAX
+#  define WCHAR_MAX 65535
+#endif
+%}
+
+/* -----------------------------------------------------------------------------
+ * Fragments for C++ header files
+ * ----------------------------------------------------------------------------- */
+
+%fragment("<algorithm>", "header") %{
+#include <algorithm>
+%}
+
+%fragment("<stdexcept>", "header") %{
+#include <stdexcept>
+%}
+
+%fragment("<string>", "header") %{
+#include <string>
+%}
+
+%fragment("<memory>", "header") %{
+#include <memory>
+%}
diff --git a/Lib/typemaps/fragments.swg b/Lib/typemaps/fragments.swg
index 3f33ca9..aaf948c 100644
--- a/Lib/typemaps/fragments.swg
+++ b/Lib/typemaps/fragments.swg
@@ -96,75 +96,6 @@
  * common fragments 
  * ------------------------------------------------------------ */
 
-/* Default compiler options for gcc allow long_long but not LLONG_MAX. 
- * Define SWIG_NO_LLONG_MAX if this added limits support is not wanted. */
-%fragment("<limits.h>","header") %{
-#include <limits.h>
-#if !defined(SWIG_NO_LLONG_MAX)
-# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__)
-#   define LLONG_MAX __LONG_LONG_MAX__
-#   define LLONG_MIN (-LLONG_MAX - 1LL)
-#   define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
-# endif
-#endif
-%}
-
-%fragment("<math.h>","header") %{
-#include <math.h>
-%}
-
-%fragment("<wchar.h>","header") %{
-#include <wchar.h>
-#include <limits.h>
-#ifndef WCHAR_MIN
-#  define WCHAR_MIN 0
-#endif
-#ifndef WCHAR_MAX
-#  define WCHAR_MAX 65535
-#endif
-%}
-
-%fragment("<float.h>","header") %{
-#include <float.h>
-%}
-
-%fragment("<stdio.h>","header") %{
-#include <stdio.h>
-#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
-# ifndef snprintf
-#  define snprintf _snprintf
-# endif
-#endif
-%}
-
-%fragment("<stdlib.h>","header") %{
-#include <stdlib.h>
-#ifdef _MSC_VER
-# ifndef strtoull
-#  define strtoull _strtoui64
-# endif
-# ifndef strtoll
-#  define strtoll _strtoi64
-# endif
-#endif
-%}
-
-%fragment("<stddef.h>", "header") %{
-#include <stddef.h>
-%}
-
-%fragment("<string>", "header") %{
-#include <string>
-%}
-
-%fragment("<stdexcept>", "header") %{
-#include <stdexcept>
-%}
-
-%fragment("<algorithm>", "header") %{
-#include <algorithm>
-%}
-
 %fragment("SWIG_isfinite","header",fragment="<math.h>,<float.h>") %{
 /* Getting isfinite working pre C99 across multiple platforms is non-trivial. Users can provide SWIG_isfinite on older platforms. */
 #ifndef SWIG_isfinite
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index a4167b1..3df9896 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -194,7 +194,7 @@
  * ----------------------------------------------------------------------------- */
 
 static int promote_type(int t) {
-  if (t <= T_UCHAR || t == T_CHAR) return T_INT;
+  if (t <= T_UCHAR || t == T_CHAR || t == T_WCHAR) return T_INT;
   return t;
 }
 
@@ -485,8 +485,19 @@
         SetFlag(n,"deleted");
         SetFlag(n,"feature:ignore");
       }
+      if (SwigType_isrvalue_reference(Getattr(n, "refqualifier"))) {
+	/* Ignore rvalue ref-qualifiers by default
+	 * Use Getattr instead of GetFlag to handle explicit ignore and explicit not ignore */
+	if (!(Getattr(n, "feature:ignore") || Strncmp(symname, "$ignore", 7) == 0)) {
+	  SWIG_WARN_NODE_BEGIN(n);
+	  Swig_warning(WARN_TYPE_RVALUE_REF_QUALIFIER_IGNORED, Getfile(n), Getline(n),
+	      "Method with rvalue ref-qualifier %s ignored.\n", Swig_name_decl(n));
+	  SWIG_WARN_NODE_END(n);
+	  SetFlag(n, "feature:ignore");
+	}
+      }
     }
-    if (only_csymbol || GetFlag(n,"feature:ignore") || strncmp(Char(symname),"$ignore",7) == 0) {
+    if (only_csymbol || GetFlag(n, "feature:ignore") || Strncmp(symname, "$ignore", 7) == 0) {
       /* Only add to C symbol table and continue */
       Swig_symbol_add(0, n);
       if (!only_csymbol && !GetFlag(n, "feature:ignore")) {
@@ -1411,10 +1422,12 @@
 }
 
 /* -----------------------------------------------------------------------------
- * add_qualifier_to_declarator
+ * add_qualifier_to_declarator()
  *
+ * Normally the qualifier is pushed on to the front of the type.
  * Adding a qualifier to a pointer to member function is a special case.
  * For example       : typedef double (Cls::*pmf)(void) const;
+ * The qualifier is  : q(const).
  * The declarator is : m(Cls).f(void).
  * We need           : m(Cls).q(const).f(void).
  * ----------------------------------------------------------------------------- */
@@ -1422,22 +1435,39 @@
 static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier) {
   int is_pointer_to_member_function = 0;
   String *decl = Copy(type);
+  String *poppedtype = NewString("");
   assert(qualifier);
-  if (SwigType_ismemberpointer(decl)) {
-    String *memberptr = SwigType_pop(decl);
-    if (SwigType_isfunction(decl)) {
-      assert(!SwigType_isqualifier(decl));
-      SwigType_push(decl, qualifier);
-      SwigType_push(decl, memberptr);
-      is_pointer_to_member_function = 1;
+
+  while (decl) {
+    if (SwigType_ismemberpointer(decl)) {
+      String *memberptr = SwigType_pop(decl);
+      if (SwigType_isfunction(decl)) {
+	is_pointer_to_member_function = 1;
+	SwigType_push(decl, qualifier);
+	SwigType_push(decl, memberptr);
+	Insert(decl, 0, poppedtype);
+	Delete(memberptr);
+	break;
+      } else {
+	Append(poppedtype, memberptr);
+      }
+      Delete(memberptr);
     } else {
-      Delete(decl);
-      decl = Copy(type);
+      String *popped = SwigType_pop(decl);
+      if (!popped)
+	break;
+      Append(poppedtype, popped);
+      Delete(popped);
     }
-    Delete(memberptr);
   }
-  if (!is_pointer_to_member_function)
+
+  if (!is_pointer_to_member_function) {
+    Delete(decl);
+    decl = Copy(type);
     SwigType_push(decl, qualifier);
+  }
+
+  Delete(poppedtype);
   return decl;
 }
 
@@ -1451,6 +1481,7 @@
     String *rawval;
     int     type;
     String *qualifier;
+    String *refqualifier;
     String *bitfield;
     Parm   *throws;
     String *throwf;
@@ -1560,7 +1591,7 @@
 
 /* Misc */
 %type <id>       identifier;
-%type <dtype>    initializer cpp_const exception_specification;
+%type <dtype>    initializer cpp_const exception_specification cv_ref_qualifier qualifiers_exception_specification;
 %type <id>       storage_class extern_string;
 %type <pl>       parms  ptail rawparms varargs_parms ;
 %type <pl>       templateparameters templateparameterstail;
@@ -1576,7 +1607,8 @@
 %type <dtype>    expr exprnum exprcompound valexpr;
 %type <id>       ename ;
 %type <id>       less_valparms_greater;
-%type <str>      type_qualifier ;
+%type <str>      type_qualifier;
+%type <str>      ref_qualifier;
 %type <id>       type_qualifier_raw;
 %type <id>       idstring idstringopt;
 %type <id>       pragma_lang;
@@ -1597,7 +1629,7 @@
 %type <node>     lambda_introducer lambda_body;
 %type <pl>       lambda_tail;
 %type <node>     optional_constant_directive;
-%type <str>      virt_specifier_seq;
+%type <str>      virt_specifier_seq virt_specifier_seq_opt;
 
 %%
 
@@ -1863,12 +1895,12 @@
 		   $$ = 0;
 		 }
                }
-	       /* Member const function pointers . eg.
+	       /* Member function pointers with qualifiers. eg.
 	         %constant short (Funcs::*pmf)(bool) const = &Funcs::F; */
-	       | CONSTANT type direct_declarator LPAREN parms RPAREN CONST_QUAL def_args SEMI {
+	       | CONSTANT type direct_declarator LPAREN parms RPAREN cv_ref_qualifier def_args SEMI {
 		 if (($8.type != T_ERROR) && ($8.type != T_SYMBOL)) {
 		   SwigType_add_function($2, $5);
-		   SwigType_add_qualifier($2, "const");
+		   SwigType_push($2, $7.qualifier);
 		   SwigType_push($2, $3.type);
 		   /* Sneaky callback function trick */
 		   if (SwigType_isfunction($2)) {
@@ -3058,36 +3090,37 @@
    A C global declaration of some kind (may be variable, function, typedef, etc.)
    ------------------------------------------------------------ */
 
-c_decl  : storage_class type declarator initializer c_decl_tail {
+c_decl  : storage_class type declarator cpp_const initializer c_decl_tail {
 	      String *decl = $3.type;
               $$ = new_node("cdecl");
 	      if ($4.qualifier)
 	        decl = add_qualifier_to_declarator($3.type, $4.qualifier);
+	      Setattr($$,"refqualifier",$4.refqualifier);
 	      Setattr($$,"type",$2);
 	      Setattr($$,"storage",$1);
 	      Setattr($$,"name",$3.id);
 	      Setattr($$,"decl",decl);
 	      Setattr($$,"parms",$3.parms);
-	      Setattr($$,"value",$4.val);
+	      Setattr($$,"value",$5.val);
 	      Setattr($$,"throws",$4.throws);
 	      Setattr($$,"throw",$4.throwf);
 	      Setattr($$,"noexcept",$4.nexcept);
-	      if ($4.val && $4.type) {
+	      if ($5.val && $5.type) {
 		/* store initializer type as it might be different to the declared type */
-		SwigType *valuetype = NewSwigType($4.type);
+		SwigType *valuetype = NewSwigType($5.type);
 		if (Len(valuetype) > 0)
 		  Setattr($$,"valuetype",valuetype);
 		else
 		  Delete(valuetype);
 	      }
-	      if (!$5) {
+	      if (!$6) {
 		if (Len(scanner_ccode)) {
 		  String *code = Copy(scanner_ccode);
 		  Setattr($$,"code",code);
 		  Delete(code);
 		}
 	      } else {
-		Node *n = $5;
+		Node *n = $6;
 		/* Inherit attributes */
 		while (n) {
 		  String *type = Copy($2);
@@ -3097,8 +3130,8 @@
 		  Delete(type);
 		}
 	      }
-	      if ($4.bitfield) {
-		Setattr($$,"bitfield", $4.bitfield);
+	      if ($5.bitfield) {
+		Setattr($$,"bitfield", $5.bitfield);
 	      }
 
 	      if ($3.id) {
@@ -3113,29 +3146,33 @@
 		      String *lstr = Swig_scopename_last($3.id);
 		      Setattr($$, "name", lstr);
 		      Delete(lstr);
-		      set_nextSibling($$, $5);
+		      set_nextSibling($$, $6);
 		    } else {
 		      Delete($$);
-		      $$ = $5;
+		      $$ = $6;
 		    }
 		    Delete(p);
 		  } else {
 		    Delete($$);
-		    $$ = $5;
+		    $$ = $6;
 		  }
 		} else {
-		  set_nextSibling($$, $5);
+		  set_nextSibling($$, $6);
 		}
 	      } else {
 		Swig_error(cparse_file, cparse_line, "Missing symbol name for global declaration\n");
 		$$ = 0;
 	      }
+
+	      if ($4.qualifier && $1 && Strstr($1, "static"))
+		Swig_error(cparse_file, cparse_line, "Static function %s cannot have a qualifier.\n", Swig_name_decl($$));
            }
            /* Alternate function syntax introduced in C++11:
               auto funcName(int x, int y) -> int; */
-           | storage_class AUTO declarator cpp_const ARROW cpp_alternate_rettype initializer c_decl_tail {
+           | storage_class AUTO declarator cpp_const ARROW cpp_alternate_rettype virt_specifier_seq_opt initializer c_decl_tail {
               $$ = new_node("cdecl");
 	      if ($4.qualifier) SwigType_push($3.type, $4.qualifier);
+	      Setattr($$,"refqualifier",$4.refqualifier);
 	      Setattr($$,"type",$6);
 	      Setattr($$,"storage",$1);
 	      Setattr($$,"name",$3.id);
@@ -3145,14 +3182,14 @@
 	      Setattr($$,"throws",$4.throws);
 	      Setattr($$,"throw",$4.throwf);
 	      Setattr($$,"noexcept",$4.nexcept);
-	      if (!$8) {
+	      if (!$9) {
 		if (Len(scanner_ccode)) {
 		  String *code = Copy(scanner_ccode);
 		  Setattr($$,"code",code);
 		  Delete(code);
 		}
 	      } else {
-		Node *n = $8;
+		Node *n = $9;
 		while (n) {
 		  String *type = Copy($6);
 		  Setattr(n,"type",type);
@@ -3173,19 +3210,22 @@
 		    String *lstr = Swig_scopename_last($3.id);
 		    Setattr($$,"name",lstr);
 		    Delete(lstr);
-		    set_nextSibling($$, $8);
+		    set_nextSibling($$, $9);
 		  } else {
 		    Delete($$);
-		    $$ = $8;
+		    $$ = $9;
 		  }
 		  Delete(p);
 		} else {
 		  Delete($$);
-		  $$ = $8;
+		  $$ = $9;
 		}
 	      } else {
-		set_nextSibling($$, $8);
+		set_nextSibling($$, $9);
 	      }
+
+	      if ($4.qualifier && $1 && Strstr($1, "static"))
+		Swig_error(cparse_file, cparse_line, "Static function %s cannot have a qualifier.\n", Swig_name_decl($$));
            }
            ;
 
@@ -3195,27 +3235,28 @@
                    $$ = 0;
                    Clear(scanner_ccode); 
                }
-               | COMMA declarator initializer c_decl_tail {
+               | COMMA declarator cpp_const initializer c_decl_tail {
 		 $$ = new_node("cdecl");
 		 if ($3.qualifier) SwigType_push($2.type,$3.qualifier);
+		 Setattr($$,"refqualifier",$3.refqualifier);
 		 Setattr($$,"name",$2.id);
 		 Setattr($$,"decl",$2.type);
 		 Setattr($$,"parms",$2.parms);
-		 Setattr($$,"value",$3.val);
+		 Setattr($$,"value",$4.val);
 		 Setattr($$,"throws",$3.throws);
 		 Setattr($$,"throw",$3.throwf);
 		 Setattr($$,"noexcept",$3.nexcept);
-		 if ($3.bitfield) {
-		   Setattr($$,"bitfield", $3.bitfield);
+		 if ($4.bitfield) {
+		   Setattr($$,"bitfield", $4.bitfield);
 		 }
-		 if (!$4) {
+		 if (!$5) {
 		   if (Len(scanner_ccode)) {
 		     String *code = Copy(scanner_ccode);
 		     Setattr($$,"code",code);
 		     Delete(code);
 		   }
 		 } else {
-		   set_nextSibling($$,$4);
+		   set_nextSibling($$, $5);
 		 }
 	       }
                | LBRACE { 
@@ -3233,33 +3274,8 @@
                }
               ;
 
-initializer   : def_args { 
-                   $$ = $1; 
-                   $$.qualifier = 0;
-		   $$.throws = 0;
-		   $$.throwf = 0;
-		   $$.nexcept = 0;
-              }
-              | type_qualifier def_args { 
-                   $$ = $2; 
-		   $$.qualifier = $1;
-		   $$.throws = 0;
-		   $$.throwf = 0;
-		   $$.nexcept = 0;
-	      }
-              | exception_specification def_args { 
-		   $$ = $2; 
-                   $$.qualifier = 0;
-		   $$.throws = $1.throws;
-		   $$.throwf = $1.throwf;
-		   $$.nexcept = $1.nexcept;
-              }
-              | type_qualifier exception_specification def_args { 
-                   $$ = $3; 
-                   $$.qualifier = $1;
-		   $$.throws = $2.throws;
-		   $$.throwf = $2.throwf;
-		   $$.nexcept = $2.nexcept;
+initializer   : def_args {
+                   $$ = $1;
               }
               ;
 
@@ -3402,7 +3418,7 @@
 		    Namespaceprefix = Swig_symbol_qualifiedscopename(0);
 		  }
                }
-	       | storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBRACE declarator initializer c_decl_tail {
+	       | storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBRACE declarator cpp_const initializer c_decl_tail {
 		 Node *n;
 		 SwigType *ty = 0;
 		 String   *unnamed = 0;
@@ -3449,8 +3465,8 @@
 		   SetFlag(n,"unnamedinstance");
 		   Delete(cty);
                  }
-		 if ($10) {
-		   Node *p = $10;
+		 if ($11) {
+		   Node *p = $11;
 		   set_nextSibling(n,p);
 		   while (p) {
 		     SwigType *cty = Copy(ty);
@@ -3958,12 +3974,12 @@
              ;
 
 cpp_opt_declarators :  SEMI { $$ = 0; }
-                    |  declarator initializer c_decl_tail {
+                    |  declarator cpp_const initializer c_decl_tail {
                         $$ = new_node("cdecl");
                         Setattr($$,"name",$1.id);
                         Setattr($$,"decl",$1.type);
                         Setattr($$,"parms",$1.parms);
-			set_nextSibling($$,$3);
+			set_nextSibling($$, $4);
                     }
                     ;
 /* ------------------------------------------------------------
@@ -4600,6 +4616,8 @@
 	       Setattr($$,"noexcept",$6.nexcept);
 	       if ($6.val)
 	         Setattr($$,"value",$6.val);
+	       if ($6.qualifier)
+		 Swig_error(cparse_file, cparse_line, "Destructor %s %s cannot have a qualifier.\n", Swig_name_decl($$), SwigType_str($6.qualifier, 0));
 	       add_symbols($$);
 	      }
 
@@ -4629,7 +4647,8 @@
 		  Setattr($$,"decl",decl);
 		  Delete(decl);
 		}
-
+		if ($7.qualifier)
+		  Swig_error(cparse_file, cparse_line, "Destructor %s %s cannot have a qualifier.\n", Swig_name_decl($$), SwigType_str($7.qualifier, 0));
 		add_symbols($$);
 	      }
               ;
@@ -4646,6 +4665,7 @@
 		 if ($8.qualifier) {
 		   SwigType_push($4,$8.qualifier);
 		 }
+		 Setattr($$,"refqualifier",$8.refqualifier);
 		 Setattr($$,"decl",$4);
 		 Setattr($$,"parms",$6);
 		 Setattr($$,"conversion_operator","1");
@@ -4663,6 +4683,7 @@
 		 if ($8.qualifier) {
 		   SwigType_push(decl,$8.qualifier);
 		 }
+		 Setattr($$,"refqualifier",$8.refqualifier);
 		 Setattr($$,"decl",decl);
 		 Setattr($$,"parms",$6);
 		 Setattr($$,"conversion_operator","1");
@@ -4680,6 +4701,7 @@
 		 if ($8.qualifier) {
 		   SwigType_push(decl,$8.qualifier);
 		 }
+		 Setattr($$,"refqualifier",$8.refqualifier);
 		 Setattr($$,"decl",decl);
 		 Setattr($$,"parms",$6);
 		 Setattr($$,"conversion_operator","1");
@@ -4699,6 +4721,7 @@
 		 if ($9.qualifier) {
 		   SwigType_push(decl,$9.qualifier);
 		 }
+		 Setattr($$,"refqualifier",$9.refqualifier);
 		 Setattr($$,"decl",decl);
 		 Setattr($$,"parms",$7);
 		 Setattr($$,"conversion_operator","1");
@@ -4715,6 +4738,7 @@
 		if ($7.qualifier) {
 		  SwigType_push(t,$7.qualifier);
 		}
+		 Setattr($$,"refqualifier",$7.refqualifier);
 		Setattr($$,"decl",t);
 		Setattr($$,"parms",$5);
 		Setattr($$,"conversion_operator","1");
@@ -4785,6 +4809,9 @@
 cpp_end        : cpp_const SEMI {
 	            Clear(scanner_ccode);
 		    $$.val = 0;
+		    $$.qualifier = $1.qualifier;
+		    $$.refqualifier = $1.refqualifier;
+		    $$.bitfield = 0;
 		    $$.throws = $1.throws;
 		    $$.throwf = $1.throwf;
 		    $$.nexcept = $1.nexcept;
@@ -4792,6 +4819,9 @@
                | cpp_const EQUAL default_delete SEMI {
 	            Clear(scanner_ccode);
 		    $$.val = $3.val;
+		    $$.qualifier = $1.qualifier;
+		    $$.refqualifier = $1.refqualifier;
+		    $$.bitfield = 0;
 		    $$.throws = $1.throws;
 		    $$.throwf = $1.throwf;
 		    $$.nexcept = $1.nexcept;
@@ -4799,6 +4829,9 @@
                | cpp_const LBRACE { 
 		    skip_balanced('{','}'); 
 		    $$.val = 0;
+		    $$.qualifier = $1.qualifier;
+		    $$.refqualifier = $1.refqualifier;
+		    $$.bitfield = 0;
 		    $$.throws = $1.throws;
 		    $$.throwf = $1.throwf;
 		    $$.nexcept = $1.nexcept;
@@ -4809,6 +4842,7 @@
                      Clear(scanner_ccode);
                      $$.val = 0;
                      $$.qualifier = $1.qualifier;
+                     $$.refqualifier = $1.refqualifier;
                      $$.bitfield = 0;
                      $$.throws = $1.throws;
                      $$.throwf = $1.throwf;
@@ -4818,6 +4852,7 @@
                      Clear(scanner_ccode);
                      $$.val = $3.val;
                      $$.qualifier = $1.qualifier;
+                     $$.refqualifier = $1.refqualifier;
                      $$.bitfield = 0;
                      $$.throws = $1.throws; 
                      $$.throwf = $1.throwf; 
@@ -4827,6 +4862,7 @@
                      skip_balanced('{','}');
                      $$.val = 0;
                      $$.qualifier = $1.qualifier;
+                     $$.refqualifier = $1.refqualifier;
                      $$.bitfield = 0;
                      $$.throws = $1.throws; 
                      $$.throwf = $1.throwf; 
@@ -5080,14 +5116,15 @@
               $$.id = 0;
 	      $$.defarg = $1.rawval ? $1.rawval : $1.val;
             }
-	    /* Member const function pointer parameters. eg.
+	    /* Member function pointers with qualifiers. eg.
 	      int f(short (Funcs::*parm)(bool) const); */
-	    | direct_declarator LPAREN parms RPAREN CONST_QUAL {
+	    | direct_declarator LPAREN parms RPAREN cv_ref_qualifier {
 	      SwigType *t;
 	      $$ = $1;
 	      t = NewStringEmpty();
 	      SwigType_add_function(t,$3);
-	      SwigType_add_qualifier(t, "const");
+	      if ($5.qualifier)
+	        SwigType_push(t, $5.qualifier);
 	      if (!$$.have_parms) {
 		$$.parms = $3;
 		$$.have_parms = 1;
@@ -5137,6 +5174,27 @@
 		$$.parms = 0;
 	      }
             }
+	    /* Member function pointers with qualifiers. eg.
+	      int f(short (Funcs::*parm)(bool) const) */
+	    | direct_declarator LPAREN parms RPAREN cv_ref_qualifier {
+	      SwigType *t;
+	      $$ = $1;
+	      t = NewStringEmpty();
+	      SwigType_add_function(t, $3);
+	      if ($5.qualifier)
+	        SwigType_push(t, $5.qualifier);
+	      if (!$$.have_parms) {
+		$$.parms = $3;
+		$$.have_parms = 1;
+	      }
+	      if (!$$.type) {
+		$$.type = t;
+	      } else {
+		SwigType_push(t, $$.type);
+		Delete($$.type);
+		$$.type = t;
+	      }
+	    }
             | empty {
    	      $$.type = 0;
               $$.id = 0;
@@ -5776,12 +5834,12 @@
 		      $$.have_parms = 1;
 		    }
 		  }
-                  | direct_abstract_declarator LPAREN parms RPAREN type_qualifier {
+                  | direct_abstract_declarator LPAREN parms RPAREN cv_ref_qualifier {
 		    SwigType *t;
                     $$ = $1;
 		    t = NewStringEmpty();
                     SwigType_add_function(t,$3);
-		    SwigType_push(t, $5);
+		    SwigType_push(t, $5.qualifier);
 		    if (!$$.type) {
 		      $$.type = t;
 		    } else {
@@ -5828,6 +5886,33 @@
            }
            ;
 
+/* cv-qualifier plus C++11 ref-qualifier for non-static member functions */
+cv_ref_qualifier : type_qualifier {
+		  $$.qualifier = $1;
+		  $$.refqualifier = 0;
+	       }
+	       | type_qualifier ref_qualifier {
+		  $$.qualifier = $1;
+		  $$.refqualifier = $2;
+		  SwigType_push($$.qualifier, $2);
+	       }
+	       | ref_qualifier {
+		  $$.qualifier = NewStringEmpty();
+		  $$.refqualifier = $1;
+		  SwigType_push($$.qualifier, $1);
+	       }
+	       ;
+
+ref_qualifier : AND {
+	          $$ = NewStringEmpty();
+	          SwigType_add_reference($$);
+	       }
+	       | LAND {
+	          $$ = NewStringEmpty();
+	          SwigType_add_rvalue_reference($$);
+	       }
+	       ;
+
 type_qualifier : type_qualifier_raw {
 	          $$ = NewStringEmpty();
 	          if ($1) SwigType_add_qualifier($$,$1);
@@ -6049,6 +6134,7 @@
 		     $$.rawval = NewStringf("%s", $$.val);
 		   }
 		   $$.qualifier = 0;
+		   $$.refqualifier = 0;
 		   $$.bitfield = 0;
 		   $$.throws = 0;
 		   $$.throwf = 0;
@@ -6074,6 +6160,7 @@
 		  $$.rawval = 0;
 		  $$.type = T_STRING;
 		  $$.qualifier = 0;
+		  $$.refqualifier = 0;
 		  $$.bitfield = 0;
 		  $$.throws = 0;
 		  $$.throwf = 0;
@@ -6087,6 +6174,7 @@
 		  $$.rawval = 0;
 		  $$.type = T_STRING;
 		  $$.qualifier = 0;
+		  $$.refqualifier = 0;
 		  $$.bitfield = 0;
 		  $$.throws = 0;
 		  $$.throwf = 0;
@@ -6250,6 +6338,7 @@
 		       break;
 		   }
 		 }
+		 $$.type = promote($2.type, $4.type);
  	       }
                | LPAREN expr pointer RPAREN expr %prec CAST {
                  $$ = $5;
@@ -6584,6 +6673,14 @@
 	       }
                ;
 
+virt_specifier_seq_opt : virt_specifier_seq {
+                   $$ = 0;
+               }
+               | empty {
+                   $$ = 0;
+               }
+               ;
+
 exception_specification : THROW LPAREN parms RPAREN {
                     $$.throws = $3;
                     $$.throwf = NewString("1");
@@ -6616,25 +6713,34 @@
 	       }
 	       ;	
 
-cpp_const      : type_qualifier {
+qualifiers_exception_specification : cv_ref_qualifier {
                     $$.throws = 0;
                     $$.throwf = 0;
                     $$.nexcept = 0;
-                    $$.qualifier = $1;
+                    $$.qualifier = $1.qualifier;
+                    $$.refqualifier = $1.refqualifier;
                }
                | exception_specification {
 		    $$ = $1;
                     $$.qualifier = 0;
+                    $$.refqualifier = 0;
                }
-               | type_qualifier exception_specification {
+               | cv_ref_qualifier exception_specification {
 		    $$ = $2;
-                    $$.qualifier = $1;
+                    $$.qualifier = $1.qualifier;
+                    $$.refqualifier = $1.refqualifier;
+               }
+               ;
+
+cpp_const      : qualifiers_exception_specification {
+                    $$ = $1;
                }
                | empty { 
                     $$.throws = 0;
                     $$.throwf = 0;
                     $$.nexcept = 0;
-                    $$.qualifier = 0; 
+                    $$.qualifier = 0;
+                    $$.refqualifier = 0;
                }
                ;
 
@@ -6645,6 +6751,8 @@
 		    $$.throws = $1.throws;
 		    $$.throwf = $1.throwf;
 		    $$.nexcept = $1.nexcept;
+                    if ($1.qualifier)
+                      Swig_error(cparse_file, cparse_line, "Constructor cannot have a qualifier.\n");
                }
                | cpp_const ctor_initializer LBRACE { 
                     skip_balanced('{','}'); 
@@ -6653,6 +6761,8 @@
                     $$.throws = $1.throws;
                     $$.throwf = $1.throwf;
                     $$.nexcept = $1.nexcept;
+                    if ($1.qualifier)
+                      Swig_error(cparse_file, cparse_line, "Constructor cannot have a qualifier.\n");
                }
                | LPAREN parms RPAREN SEMI { 
                     Clear(scanner_ccode); 
@@ -6685,6 +6795,8 @@
                     $$.throws = $1.throws;
                     $$.throwf = $1.throwf;
                     $$.nexcept = $1.nexcept;
+                    if ($1.qualifier)
+                      Swig_error(cparse_file, cparse_line, "Constructor cannot have a qualifier.\n");
                }
                ;
 
diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h
index 0b4c7eeb..dd32aef 100644
--- a/Source/Include/swigwarn.h
+++ b/Source/Include/swigwarn.h
@@ -153,6 +153,7 @@
 #define WARN_TYPE_INCOMPLETE          402
 #define WARN_TYPE_ABSTRACT            403
 #define WARN_TYPE_REDEFINED           404
+#define WARN_TYPE_RVALUE_REF_QUALIFIER_IGNORED 405
 
 #define WARN_TYPEMAP_SOURCETARGET     450
 #define WARN_TYPEMAP_CHARLEAK         451
diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx
index 77f1319..f32d349 100644
--- a/Source/Modules/allegrocl.cxx
+++ b/Source/Modules/allegrocl.cxx
@@ -1685,285 +1685,6 @@
   return SWIG_OK;
 }
 
-/* very shamelessly 'borrowed' from overload.cxx, which
-   keeps the below Swig_overload_rank() code to itself.
-   We don't need a dispatch function in the C++ wrapper
-   code; we want it over on the lisp side. */
-
-#define Swig_overload_rank Allegrocl_swig_overload_rank
-
-#define MAX_OVERLOAD 256
-
-/* Overload "argc" and "argv" */
-// String *argv_template_string;
-// String *argc_template_string;
-
-struct Overloaded {
-  Node *n;			/* Node                               */
-  int argc;			/* Argument count                     */
-  ParmList *parms;		/* Parameters used for overload check */
-  int error;			/* Ambiguity error                    */
-};
-
-/* -----------------------------------------------------------------------------
- * Swig_overload_rank()
- *
- * This function takes an overloaded declaration and creates a list that ranks
- * all overloaded methods in an order that can be used to generate a dispatch 
- * function.
- * Slight difference in the way this function is used by scripting languages and
- * statically typed languages. The script languages call this method via 
- * Swig_overload_dispatch() - where wrappers for all overloaded methods are generated,
- * however sometimes the code can never be executed. The non-scripting languages
- * call this method via Swig_overload_check() for each overloaded method in order
- * to determine whether or not the method should be wrapped. Note the slight
- * difference when overloading methods that differ by const only. The
- * scripting languages will ignore the const method, whereas the non-scripting
- * languages ignore the first method parsed.
- * ----------------------------------------------------------------------------- */
-
-static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
-  Overloaded nodes[MAX_OVERLOAD];
-  int nnodes = 0;
-  Node *o = Getattr(n, "sym:overloaded");
-  Node *c;
-
-  if (!o)
-    return 0;
-
-  c = o;
-  while (c) {
-    if (Getattr(c, "error")) {
-      c = Getattr(c, "sym:nextSibling");
-      continue;
-    }
-    /*    if (SmartPointer && Getattr(c,"cplus:staticbase")) {
-       c = Getattr(c,"sym:nextSibling");
-       continue;
-       } */
-
-    /* Make a list of all the declarations (methods) that are overloaded with
-     * this one particular method name */
-    if (Getattr(c, "wrap:name")) {
-      nodes[nnodes].n = c;
-      nodes[nnodes].parms = Getattr(c, "wrap:parms");
-      nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms);
-      nodes[nnodes].error = 0;
-      nnodes++;
-    }
-    c = Getattr(c, "sym:nextSibling");
-  }
-
-  /* Sort the declarations by required argument count */
-  {
-    int i, j;
-    for (i = 0; i < nnodes; i++) {
-      for (j = i + 1; j < nnodes; j++) {
-	if (nodes[i].argc > nodes[j].argc) {
-	  Overloaded t = nodes[i];
-	  nodes[i] = nodes[j];
-	  nodes[j] = t;
-	}
-      }
-    }
-  }
-
-  /* Sort the declarations by argument types */
-  {
-    int i, j;
-    for (i = 0; i < nnodes - 1; i++) {
-      if (nodes[i].argc == nodes[i + 1].argc) {
-	for (j = i + 1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) {
-	  Parm *p1 = nodes[i].parms;
-	  Parm *p2 = nodes[j].parms;
-	  int differ = 0;
-	  int num_checked = 0;
-	  while (p1 && p2 && (num_checked < nodes[i].argc)) {
-	    //    Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type"));
-	    if (checkAttribute(p1, "tmap:in:numinputs", "0")) {
-	      p1 = Getattr(p1, "tmap:in:next");
-	      continue;
-	    }
-	    if (checkAttribute(p2, "tmap:in:numinputs", "0")) {
-	      p2 = Getattr(p2, "tmap:in:next");
-	      continue;
-	    }
-	    String *t1 = Getattr(p1, "tmap:typecheck:precedence");
-	    String *t2 = Getattr(p2, "tmap:typecheck:precedence");
-	    if ((!t1) && (!nodes[i].error)) {
-	      Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n),
-			   "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n",
-			   Swig_name_decl(nodes[i].n), SwigType_str(Getattr(p1, "type"), 0));
-	      nodes[i].error = 1;
-	    } else if ((!t2) && (!nodes[j].error)) {
-	      Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n),
-			   "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n",
-			   Swig_name_decl(nodes[j].n), SwigType_str(Getattr(p2, "type"), 0));
-	      nodes[j].error = 1;
-	    }
-	    if (t1 && t2) {
-	      int t1v, t2v;
-	      t1v = atoi(Char(t1));
-	      t2v = atoi(Char(t2));
-	      differ = t1v - t2v;
-	    } else if (!t1 && t2)
-	      differ = 1;
-	    else if (t1 && !t2)
-	      differ = -1;
-	    else if (!t1 && !t2)
-	      differ = -1;
-	    num_checked++;
-	    if (differ > 0) {
-	      Overloaded t = nodes[i];
-	      nodes[i] = nodes[j];
-	      nodes[j] = t;
-	      break;
-	    } else if ((differ == 0) && (Strcmp(t1, "0") == 0)) {
-	      t1 = Getattr(p1, "ltype");
-	      if (!t1) {
-		t1 = SwigType_ltype(Getattr(p1, "type"));
-		if (Getattr(p1, "tmap:typecheck:SWIGTYPE")) {
-		  SwigType_add_pointer(t1);
-		}
-		Setattr(p1, "ltype", t1);
-	      }
-	      t2 = Getattr(p2, "ltype");
-	      if (!t2) {
-		t2 = SwigType_ltype(Getattr(p2, "type"));
-		if (Getattr(p2, "tmap:typecheck:SWIGTYPE")) {
-		  SwigType_add_pointer(t2);
-		}
-		Setattr(p2, "ltype", t2);
-	      }
-
-	      /* Need subtype check here.  If t2 is a subtype of t1, then we need to change the
-	         order */
-
-	      if (SwigType_issubtype(t2, t1)) {
-		Overloaded t = nodes[i];
-		nodes[i] = nodes[j];
-		nodes[j] = t;
-	      }
-
-	      if (Strcmp(t1, t2) != 0) {
-		differ = 1;
-		break;
-	      }
-	    } else if (differ) {
-	      break;
-	    }
-	    if (Getattr(p1, "tmap:in:next")) {
-	      p1 = Getattr(p1, "tmap:in:next");
-	    } else {
-	      p1 = nextSibling(p1);
-	    }
-	    if (Getattr(p2, "tmap:in:next")) {
-	      p2 = Getattr(p2, "tmap:in:next");
-	    } else {
-	      p2 = nextSibling(p2);
-	    }
-	  }
-	  if (!differ) {
-	    /* See if declarations differ by const only */
-	    String *d1 = Getattr(nodes[i].n, "decl");
-	    String *d2 = Getattr(nodes[j].n, "decl");
-	    if (d1 && d2) {
-	      String *dq1 = Copy(d1);
-	      String *dq2 = Copy(d2);
-	      if (SwigType_isconst(d1)) {
-		Delete(SwigType_pop(dq1));
-	      }
-	      if (SwigType_isconst(d2)) {
-		Delete(SwigType_pop(dq2));
-	      }
-	      if (Strcmp(dq1, dq2) == 0) {
-
-		if (SwigType_isconst(d1) && !SwigType_isconst(d2)) {
-		  if (script_lang_wrapping) {
-		    // Swap nodes so that the const method gets ignored (shadowed by the non-const method)
-		    Overloaded t = nodes[i];
-		    nodes[i] = nodes[j];
-		    nodes[j] = t;
-		  }
-		  differ = 1;
-		  if (!nodes[j].error) {
-		    if (script_lang_wrapping) {
-		      Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
-				   "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
-		      Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n),
-				   "using non-const method %s instead.\n", Swig_name_decl(nodes[i].n));
-		    } else {
-		      if (!Getattr(nodes[j].n, "overload:ignore")) {
-			Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
-				     "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
-			Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
-				     "using %s instead.\n", Swig_name_decl(nodes[i].n));
-		      }
-		    }
-		  }
-		  nodes[j].error = 1;
-		} else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) {
-		  differ = 1;
-		  if (!nodes[j].error) {
-		    if (script_lang_wrapping) {
-		      Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
-				   "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
-		      Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n),
-				   "using non-const method %s instead.\n", Swig_name_decl(nodes[i].n));
-		    } else {
-		      if (!Getattr(nodes[j].n, "overload:ignore")) {
-			Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
-				     "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
-			Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
-				     "using %s instead.\n", Swig_name_decl(nodes[i].n));
-		      }
-		    }
-		  }
-		  nodes[j].error = 1;
-		}
-	      }
-	      Delete(dq1);
-	      Delete(dq2);
-	    }
-	  }
-	  if (!differ) {
-	    if (!nodes[j].error) {
-	      if (script_lang_wrapping) {
-		Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
-			     "Overloaded method %s effectively ignored,\n", Swig_name_decl(nodes[j].n));
-		Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[i].n), Getline(nodes[i].n),
-			     "as it is shadowed by %s.\n", Swig_name_decl(nodes[i].n));
-	      } else {
-		if (!Getattr(nodes[j].n, "overload:ignore")) {
-		  Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
-			       "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
-		  Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
-			       "using %s instead.\n", Swig_name_decl(nodes[i].n));
-		}
-	      }
-	      nodes[j].error = 1;
-	    }
-	  }
-	}
-      }
-    }
-  }
-  List *result = NewList();
-  {
-    int i;
-    for (i = 0; i < nnodes; i++) {
-      if (nodes[i].error)
-	Setattr(nodes[i].n, "overload:ignore", "1");
-      Append(result, nodes[i].n);
-      //      Printf(stdout,"[ %d ] %s\n", i, ParmList_errorstr(nodes[i].parms));
-      //      Swig_print_node(nodes[i].n);
-    }
-  }
-  return result;
-}
-
-/* end shameless borrowing */
-
 int any_varargs(ParmList *pl) {
   Parm *p;
 
diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx
index 7c2607f..813a309 100644
--- a/Source/Modules/emit.cxx
+++ b/Source/Modules/emit.cxx
@@ -454,7 +454,7 @@
   if (catchlist) {
     int unknown_catch = 0;
     int has_varargs = 0;
-    Printf(eaction, "}\n");
+    Printf(eaction, "} ");
     for (Parm *ep = catchlist; ep; ep = nextSibling(ep)) {
       String *em = Swig_typemap_lookup("throws", ep, "_e", 0);
       if (em) {
diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx
index 12b83b2..9822b6a 100644
--- a/Source/Modules/main.cxx
+++ b/Source/Modules/main.cxx
@@ -38,14 +38,15 @@
 int SwigRuntime = 0;		// 0 = no option, 1 = -runtime, 2 = -noruntime
 
 /* Suppress warning messages for private inheritance, preprocessor evaluation etc...
-   WARN_PP_EVALUATION            202
-   WARN_PARSE_PRIVATE_INHERIT    309
-   WARN_TYPE_ABSTRACT            403
-   WARN_LANG_OVERLOAD_CONST      512
-   WARN_PARSE_BUILTIN_NAME       321
-   WARN_PARSE_REDUNDANT          322
+   WARN_PP_EVALUATION                           202
+   WARN_PARSE_PRIVATE_INHERIT                   309
+   WARN_PARSE_BUILTIN_NAME                      321
+   WARN_PARSE_REDUNDANT                         322
+   WARN_TYPE_ABSTRACT                           403
+   WARN_TYPE_RVALUE_REF_QUALIFIER_IGNORED       405
+   WARN_LANG_OVERLOAD_CONST                     512
  */
-#define EXTRA_WARNINGS "202,309,403,512,321,322"
+#define EXTRA_WARNINGS "202,309,403,405,512,321,322"
 
 extern "C" {
   extern String *ModuleName;
diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx
index 330294e..81d1bb0 100644
--- a/Source/Modules/overload.cxx
+++ b/Source/Modules/overload.cxx
@@ -231,9 +231,21 @@
 	  }
 	  if (!differ) {
 	    /* See if declarations differ by const only */
-	    String *d1 = Getattr(nodes[i].n, "decl");
-	    String *d2 = Getattr(nodes[j].n, "decl");
-	    if (d1 && d2) {
+	    String *decl1 = Getattr(nodes[i].n, "decl");
+	    String *decl2 = Getattr(nodes[j].n, "decl");
+	    if (decl1 && decl2) {
+	      /* Remove ref-qualifiers. Note that rvalue ref-qualifiers are already ignored and 
+	       * it is illegal to overload a function with and without ref-qualifiers. So with
+	       * all the combinations of ref-qualifiers and cv-qualifiers, we just detect 
+	       * the cv-qualifier (const) overloading. */
+	      String *d1 = Copy(decl1);
+	      String *d2 = Copy(decl2);
+	      if (SwigType_isreference(d1) || SwigType_isrvalue_reference(d1)) {
+		Delete(SwigType_pop(d1));
+	      }
+	      if (SwigType_isreference(d2) || SwigType_isrvalue_reference(d2)) {
+		Delete(SwigType_pop(d2));
+	      }
 	      String *dq1 = Copy(d1);
 	      String *dq2 = Copy(d2);
 	      if (SwigType_isconst(d1)) {
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 64905bc..4e90533 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -177,7 +177,7 @@
 
 static void printSlot(File *f, String *slotval, const char *slotname, const char *functype = NULL) {
   String *slotval_override = 0;
-  if (functype)
+  if (functype && Strcmp(slotval, "0") == 0)
     slotval = slotval_override = NewStringf("(%s) %s", functype, slotval);
   int len = Len(slotval);
   int fieldwidth = len > 41 ? (len > 61 ? 0 : 61 - len) : 41 - len;
@@ -2501,7 +2501,8 @@
 
     String *tmp = NewString("");
     String *dispatch;
-    const char *dispatch_code = funpack ? "return %s(self, argc, argv);" : "return %s(self, args);";
+    const char *dispatch_code = funpack ? "return %s(self, argc, argv);" :
+      (builtin_ctor ? "return %s(self, args, NULL);" : "return %s(self, args);");
 
     if (castmode) {
       dispatch = Swig_overload_dispatch_cast(n, dispatch_code, &maxargs);
@@ -2515,7 +2516,8 @@
     String *symname = Getattr(n, "sym:name");
     String *wname = Swig_name_wrapper(symname);
 
-    Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL);
+    const char *builtin_kwargs = builtin_ctor ? ", PyObject *SWIGUNUSEDPARM(kwargs)" : "";
+    Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
 
     Wrapper_add_local(f, "argc", "Py_ssize_t argc");
     Printf(tmp, "PyObject *argv[%d] = {0}", maxargs + 1);
@@ -2729,9 +2731,10 @@
       Append(wname, overname);
     }
 
+    const char *builtin_kwargs = builtin_ctor ? ", PyObject *SWIGUNUSEDPARM(kwargs)" : "";
     if (!allow_kwargs || overname) {
       if (!varargs) {
-	Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
+	Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
       } else {
 	Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL);
       }
@@ -2927,17 +2930,13 @@
 	Clear(f->def);
 	if (overname) {
 	  if (noargs) {
-	    Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
+	    Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
 	  } else {
-	    Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL);
+	    Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
 	  }
 	  Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments);
 	} else {
-	  if (noargs) {
-	    Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
-	  } else {
-	    Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
-	  }
+	  Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
 	  if (onearg && !builtin_ctor) {
 	    Printf(parse_args, "if (!args) SWIG_fail;\n");
 	    Append(parse_args, "swig_obj[0] = args;\n");
@@ -3238,9 +3237,10 @@
       DelWrapper(f);
       f = NewWrapper();
       if (funpack) {
-	Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL);
+	// Note: funpack is currently always false for varargs
+	Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
       } else {
-	Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
+	Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
       }
       Wrapper_add_local(f, "resultobj", builtin_ctor ? "int resultobj" : "PyObject *resultobj");
       Wrapper_add_local(f, "varargs", "PyObject *varargs");
@@ -3350,7 +3350,7 @@
 	  closure_name = Copy(wrapper_name);
 	}
 	if (func_type) {
-	  String *s = NewStringf("(%s) %s", func_type, closure_name);
+	  String *s = NewStringf("%s", closure_name);
 	  Delete(closure_name);
 	  closure_name = s;
 	}
diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx
index 6a32620..db94ec9 100644
--- a/Source/Modules/r.cxx
+++ b/Source/Modules/r.cxx
@@ -290,8 +290,6 @@
   int membervariableHandler(Node *n);
 
   int typedefHandler(Node *n);
-  static List *Swig_overload_rank(Node *n,
-			   bool script_lang_wrapping);
 
   int memberfunctionHandler(Node *n) {
     if (debugMode)
@@ -1314,260 +1312,6 @@
     Printf(stdout, "Adding accessor: %s (%s) => %s\n", memberName, name, tmp);
 }
 
-#define MAX_OVERLOAD 256
-
-struct Overloaded {
-  Node      *n;          /* Node                               */
-  int        argc;       /* Argument count                     */
-  ParmList  *parms;      /* Parameters used for overload check */
-  int        error;      /* Ambiguity error                    */
-};
-
-
-List * R::Swig_overload_rank(Node *n, 
-				 bool script_lang_wrapping) {
-  Overloaded  nodes[MAX_OVERLOAD];
-  int         nnodes = 0;
-  Node *o = Getattr(n,"sym:overloaded");
-
-
-  if (!o) return 0;
-
-  Node *c = o;
-  while (c) {
-    if (Getattr(c,"error")) {
-      c = Getattr(c,"sym:nextSibling");
-      continue;
-    }
-    /*    if (SmartPointer && Getattr(c,"cplus:staticbase")) {
-	  c = Getattr(c,"sym:nextSibling");
-	  continue;
-	  } */
-
-    /* Make a list of all the declarations (methods) that are overloaded with
-     * this one particular method name */
-
-    if (Getattr(c,"wrap:name")) {
-      nodes[nnodes].n = c;
-      nodes[nnodes].parms = Getattr(c,"wrap:parms");
-      nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms);
-      nodes[nnodes].error = 0;
-      nnodes++;
-    }
-    c = Getattr(c,"sym:nextSibling");
-  }
-  
-  /* Sort the declarations by required argument count */
-  {
-    int i,j;
-    for (i = 0; i < nnodes; i++) {
-      for (j = i+1; j < nnodes; j++) {
-	if (nodes[i].argc > nodes[j].argc) {
-	  Overloaded t = nodes[i];
-	  nodes[i] = nodes[j];
-	  nodes[j] = t;
-	}
-      }
-    }
-  }
-
-  /* Sort the declarations by argument types */
-  {
-    int i,j;
-    for (i = 0; i < nnodes-1; i++) {
-      if (nodes[i].argc == nodes[i+1].argc) {
-	for (j = i+1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) {
-	  Parm *p1 = nodes[i].parms;
-	  Parm *p2 = nodes[j].parms;
-	  int   differ = 0;
-	  int   num_checked = 0;
-	  while (p1 && p2 && (num_checked < nodes[i].argc)) {
-	    if (debugMode) {
-	      Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type"));
-	    }
-	    if (checkAttribute(p1,"tmap:in:numinputs","0")) {
-	      p1 = Getattr(p1,"tmap:in:next");
-	      continue;
-	    }
-	    if (checkAttribute(p2,"tmap:in:numinputs","0")) {
-	      p2 = Getattr(p2,"tmap:in:next");
-	      continue;
-	    }
-	    String *t1 = Getattr(p1,"tmap:typecheck:precedence");
-	    String *t2 = Getattr(p2,"tmap:typecheck:precedence");
-	    if (debugMode) {
-	      Printf(stdout,"t1 = '%s', t2 = '%s'\n", t1, t2);
-	    }
-	    if ((!t1) && (!nodes[i].error)) {
-	      Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n),
-			   "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n",
-			   Swig_name_decl(nodes[i].n), SwigType_str(Getattr(p1, "type"), 0));
-	      nodes[i].error = 1;
-	    } else if ((!t2) && (!nodes[j].error)) {
-	      Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n),
-			   "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n",
-			   Swig_name_decl(nodes[j].n), SwigType_str(Getattr(p2, "type"), 0));
-	      nodes[j].error = 1;
-	    }
-	    if (t1 && t2) {
-	      int t1v, t2v;
-	      t1v = atoi(Char(t1));
-	      t2v = atoi(Char(t2));
-	      differ = t1v-t2v;
-	    }
-	    else if (!t1 && t2) differ = 1;
-	    else if (t1 && !t2) differ = -1;
-	    else if (!t1 && !t2) differ = -1;
-	    num_checked++;
-	    if (differ > 0) {
-	      Overloaded t = nodes[i];
-	      nodes[i] = nodes[j];
-	      nodes[j] = t;
-	      break;
-	    } else if ((differ == 0) && (Strcmp(t1,"0") == 0)) {
-	      t1 = Getattr(p1,"ltype");
-	      if (!t1) {
-		t1 = SwigType_ltype(Getattr(p1,"type"));
-		if (Getattr(p1,"tmap:typecheck:SWIGTYPE")) {
-		  SwigType_add_pointer(t1);
-		}
-		Setattr(p1,"ltype",t1);
-	      }
-	      t2 = Getattr(p2,"ltype");
-	      if (!t2) {
-		t2 = SwigType_ltype(Getattr(p2,"type"));
-		if (Getattr(p2,"tmap:typecheck:SWIGTYPE")) {
-		  SwigType_add_pointer(t2);
-		}
-		Setattr(p2,"ltype",t2);
-	      }
-
-	      /* Need subtype check here.  If t2 is a subtype of t1, then we need to change the
-                 order */
-
-	      if (SwigType_issubtype(t2,t1)) {
-		Overloaded t = nodes[i];
-		nodes[i] = nodes[j];
-		nodes[j] = t;
-	      }
-
-	      if (Strcmp(t1,t2) != 0) {
-		differ = 1;
-		break;
-	      }
-	    } else if (differ) {
-	      break;
-	    }
-	    if (Getattr(p1,"tmap:in:next")) {
-	      p1 = Getattr(p1,"tmap:in:next");
-	    } else {
-	      p1 = nextSibling(p1);
-	    }
-	    if (Getattr(p2,"tmap:in:next")) {
-	      p2 = Getattr(p2,"tmap:in:next");
-	    } else {
-	      p2 = nextSibling(p2);
-	    }
-	  }
-	  if (!differ) {
-	    /* See if declarations differ by const only */
-	    String *d1 = Getattr(nodes[i].n, "decl");
-	    String *d2 = Getattr(nodes[j].n, "decl");
-	    if (d1 && d2) {
-	      String *dq1 = Copy(d1);
-	      String *dq2 = Copy(d2);
-	      if (SwigType_isconst(d1)) {
-		Delete(SwigType_pop(dq1));
-	      }
-	      if (SwigType_isconst(d2)) {
-		Delete(SwigType_pop(dq2));
-	      }
-	      if (Strcmp(dq1, dq2) == 0) {
-
-		if (SwigType_isconst(d1) && !SwigType_isconst(d2)) {
-		  if (script_lang_wrapping) {
-		    // Swap nodes so that the const method gets ignored (shadowed by the non-const method)
-		    Overloaded t = nodes[i];
-		    nodes[i] = nodes[j];
-		    nodes[j] = t;
-		  }
-		  differ = 1;
-		  if (!nodes[j].error) {
-		    if (script_lang_wrapping) {
-		      Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
-				   "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
-		      Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n),
-				   "using non-const method %s instead.\n", Swig_name_decl(nodes[i].n));
-		    } else {
-		      if (!Getattr(nodes[j].n, "overload:ignore")) {
-			Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
-				     "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
-			Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
-				     "using %s instead.\n", Swig_name_decl(nodes[i].n));
-		      }
-		    }
-		  }
-		  nodes[j].error = 1;
-		} else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) {
-		  differ = 1;
-		  if (!nodes[j].error) {
-		    if (script_lang_wrapping) {
-		      Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
-				   "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
-		      Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n),
-				   "using non-const method %s instead.\n", Swig_name_decl(nodes[i].n));
-		    } else {
-		      if (!Getattr(nodes[j].n, "overload:ignore")) {
-			Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
-				     "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
-			Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
-				     "using %s instead.\n", Swig_name_decl(nodes[i].n));
-		      }
-		    }
-		  }
-		  nodes[j].error = 1;
-		}
-	      }
-	      Delete(dq1);
-	      Delete(dq2);
-	    }
-	  }
-	  if (!differ) {
-	    if (!nodes[j].error) {
-	      if (script_lang_wrapping) {
-		Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
-			     "Overloaded method %s effectively ignored,\n", Swig_name_decl(nodes[j].n));
-		Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[i].n), Getline(nodes[i].n),
-			     "as it is shadowed by %s.\n", Swig_name_decl(nodes[i].n));
-	      } else {
-		if (!Getattr(nodes[j].n, "overload:ignore")) {
-		  Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
-			       "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
-		  Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
-			       "using %s instead.\n", Swig_name_decl(nodes[i].n));
-		}
-	      }
-	      nodes[j].error = 1;
-	    }
-	  }
-	}
-      }
-    }
-  }
-  List *result = NewList();
-  {
-    int i;
-    for (i = 0; i < nnodes; i++) {
-      if (nodes[i].error)
-        Setattr(nodes[i].n, "overload:ignore", "1");
-      Append(result,nodes[i].n);
-      //      Printf(stdout,"[ %d ] %s\n", i, ParmList_errorstr(nodes[i].parms));
-      //      Swig_print_node(nodes[i].n);
-    }
-  }
-  return result;
-}
-
 void R::dispatchFunction(Node *n) {
   Wrapper *f = NewWrapper();
   String *symname = Getattr(n, "sym:name");
diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c
index 4c3135e..d6e5e0c 100644
--- a/Source/Swig/cwrap.c
+++ b/Source/Swig/cwrap.c
@@ -1024,6 +1024,15 @@
       }
     }
 
+    if (!self && SwigType_isrvalue_reference(Getattr(n, "refqualifier"))) {
+      String *memory_header = NewString("<memory>");
+      Setfile(memory_header, Getfile(n));
+      Setline(memory_header, Getline(n));
+      Swig_fragment_emit(memory_header);
+      self = NewString("std::move(*this).");
+      Delete(memory_header);
+    }
+
     call = Swig_cmethod_call(explicitcall_name ? explicitcall_name : name, p, self, explicit_qualifier, director_type);
     cres = Swig_cresult(Getattr(n, "type"), Swig_cresult_name(), call);
 
diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c
index ce1dbe8..d127701 100644
--- a/Source/Swig/naming.c
+++ b/Source/Swig/naming.c
@@ -1681,6 +1681,7 @@
  *   "MyNameSpace::MyTemplate<MyNameSpace::ABC >::~MyTemplate()"
  *   "MyNameSpace::ABC::ABC(int,double)"
  *   "MyNameSpace::ABC::constmethod(int) const"
+ *   "MyNameSpace::ABC::refqualifiermethod(int) const &"
  *   "MyNameSpace::ABC::variablename"
  * 
  * ----------------------------------------------------------------------------- */
@@ -1690,11 +1691,22 @@
   String *decl;
 
   qname = Swig_name_str(n);
+  decl = NewStringf("%s", qname);
 
-  if (checkAttribute(n, "kind", "variable"))
-    decl = NewStringf("%s", qname);
-  else
-    decl = NewStringf("%s(%s)%s", qname, ParmList_errorstr(Getattr(n, "parms")), SwigType_isconst(Getattr(n, "decl")) ? " const" : "");
+  if (!checkAttribute(n, "kind", "variable")) {
+    String *d = Getattr(n, "decl");
+    Printv(decl, "(", ParmList_errorstr(Getattr(n, "parms")), ")", NIL);
+    if (SwigType_isfunction(d)) {
+      SwigType *decl_temp = Copy(d);
+      SwigType *qualifiers = SwigType_pop_function_qualifiers(decl_temp);
+      if (qualifiers) {
+	String *qualifiers_string = SwigType_str(qualifiers, 0);
+	Printv(decl, " ", qualifiers_string, NIL);
+	Delete(qualifiers_string);
+      }
+      Delete(decl_temp);
+    }
+  }
 
   Delete(qname);
 
diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c
index 829005c..364329d 100644
--- a/Source/Swig/stype.c
+++ b/Source/Swig/stype.c
@@ -44,7 +44,7 @@
  *  'z.'                = Rvalue reference (&&)
  *  'a(n).'             = Array of size n  [n]
  *  'f(..,..).'         = Function with arguments  (args)
- *  'q(str).'           = Qualifier (such as const or volatile) (const, volatile)
+ *  'q(str).'           = Qualifier, such as const or volatile (cv-qualifier)
  *  'm(cls).'           = Pointer to member (cls::*)
  *
  * The encoding follows the order that you might describe a type in words.
@@ -64,11 +64,19 @@
  *
  * More examples:
  *
- *        String Encoding                 C++ Example
- *        ---------------                 -----------
- *        p.f(bool).q(const).long         const long (*)(bool)
- *        m(Funcs).q(const).f(bool).long  long (Funcs::*)(bool) const
- *        r.q(const).m(Funcs).f(int).long long (Funcs::*const &)(int)
+ *        String Encoding                     C++ Example
+ *        ---------------                     -----------
+ *        p.f(bool).r.q(const).long           const long & (*)(bool)
+ *        m(Funcs).q(const).f(bool).long      long (Funcs::*)(bool) const
+ *        r.q(const).m(Funcs).f(int).long     long (Funcs::*const &)(int)
+ *        m(Funcs).z.q(const).f(bool).long    long (Funcs::*)(bool) const &&
+ *
+ * Function decl examples:
+ *
+ *        f(bool).                            long a(bool);
+ *        r.f(bool).                          long b(bool) &;
+ *        z.f(bool).                          long c(bool) &&;
+ *        z.q(const).f(bool).                 long d(bool) const &&;
  *
  * For the most part, this module tries to minimize the use of special
  * characters (*, [, <, etc...) in its type encoding.  One reason for this
@@ -536,10 +544,9 @@
   String *element = 0;
   String *nextelement;
   String *forwardelement;
-  String *member_const_function_element = 0;
+  SwigType *member_function_qualifiers = 0;
   List *elements;
   int nelements, i;
-  int member_const_function = 0;
 
   if (id) {
     /* stringify the id expanding templates, for example when the id is a fully qualified templated class name */
@@ -570,14 +577,12 @@
       forwardelement = 0;
     }
     if (SwigType_isqualifier(element)) {
-      if (!member_const_function) {
+      if (!member_function_qualifiers) {
 	DOH *q = 0;
 	q = SwigType_parm(element);
 	Insert(result, 0, " ");
 	Insert(result, 0, q);
 	Delete(q);
-      } else {
-        member_const_function = 0;
       }
     } else if (SwigType_ispointer(element)) {
       Insert(result, 0, "*");
@@ -594,20 +599,28 @@
 	Insert(result, 0, "(");
 	Append(result, ")");
       }
-      if (SwigType_isqualifier(nextelement)) {
-	member_const_function_element = nextelement;
-	member_const_function = 1;
+      {
+	String *next3elements = NewStringEmpty();
+	int j;
+	for (j = i + 1; j < i + 4 && j < nelements; j++) {
+	  Append(next3elements, Getitem(elements, j));
+	}
+	if (SwigType_isfunction(next3elements))
+	  member_function_qualifiers = SwigType_pop_function_qualifiers(next3elements);
+	Delete(next3elements);
       }
       Delete(q);
     } else if (SwigType_isreference(element)) {
-      Insert(result, 0, "&");
+      if (!member_function_qualifiers)
+	Insert(result, 0, "&");
       if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
 	Insert(result, 0, "(");
 	Append(result, ")");
       }
     } else if (SwigType_isrvalue_reference(element)) {
-      Insert(result, 0, "&&");
-      if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
+      if (!member_function_qualifiers)
+	Insert(result, 0, "&&");
+      if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
 	Insert(result, 0, "(");
 	Append(result, ")");
       }
@@ -631,12 +644,13 @@
 	  Append(result, ",");
       }
       Append(result, ")");
-      if (member_const_function_element) {
-	String *p = SwigType_str(member_const_function_element, 0);
+      if (member_function_qualifiers) {
+	String *p = SwigType_str(member_function_qualifiers, 0);
 	Append(result, " ");
 	Append(result, p);
 	Delete(p);
-	member_const_function_element = 0;
+	Delete(member_function_qualifiers);
+	member_function_qualifiers = 0;
       }
       Delete(parms);
     } else {
@@ -670,6 +684,7 @@
   int nelements, i;
   int firstarray = 1;
   int notypeconv = 0;
+  int ignore_member_function_qualifiers = 0;
 
   result = NewStringEmpty();
   tc = Copy(s);
@@ -696,6 +711,7 @@
       tc = td;
     }
   }
+
   elements = SwigType_split(tc);
   nelements = Len(elements);
 
@@ -705,14 +721,33 @@
     /* when we see a function, we need to preserve the following types */
     if (SwigType_isfunction(element)) {
       notypeconv = 1;
+      ignore_member_function_qualifiers = 0;
     }
-    if (SwigType_isqualifier(element)) {
-      /* Do nothing. Ignore */
+    if (ignore_member_function_qualifiers) {
+      /* cv-qualifiers and ref-qualifiers up until the f() element have already been added */
+    } else if (SwigType_isqualifier(element)) {
+      /* swallow cv-qualifiers */
     } else if (SwigType_ispointer(element)) {
       Append(result, element);
       firstarray = 0;
     } else if (SwigType_ismemberpointer(element)) {
       Append(result, element);
+      {
+	String *next3elements = NewStringEmpty();
+	int j;
+	for (j = i + 1; j < i + 4 && j < nelements; j++) {
+	  Append(next3elements, Getitem(elements, j));
+	}
+	if (SwigType_isfunction(next3elements)) {
+	  SwigType *member_function_qualifiers = SwigType_pop_function_qualifiers(next3elements);
+	  /* compilers won't let us cast from a member function without qualifiers to one with qualifiers, so the qualifiers are kept in the ltype */
+	  if (member_function_qualifiers)
+	    Append(result, member_function_qualifiers);
+	  Delete(member_function_qualifiers);
+	  ignore_member_function_qualifiers = 1;
+	}
+	Delete(next3elements);
+      }
       firstarray = 0;
     } else if (SwigType_isreference(element)) {
       if (notypeconv) {
@@ -752,13 +787,14 @@
 }
 
 /* -----------------------------------------------------------------------------
- * SwigType_lstr(DOH *s, DOH *id)
+ * SwigType_lstr()
  *
  * Produces a type-string that is suitable as a lvalue in an expression.
  * That is, a type that can be freely assigned a value without violating
  * any C assignment rules.
  *
  *      -   Qualifiers such as 'const' and 'volatile' are stripped.
+ *          Except for member function cv-qualifiers and ref-qualifiers.
  *      -   Arrays are converted into a *single* pointer (i.e.,
  *          double [][] becomes double *).
  *      -   References are converted into a pointer.
@@ -788,7 +824,7 @@
   String *element = 0;
   String *nextelement;
   String *forwardelement;
-  String *member_const_function_element = 0;
+  String *member_function_qualifiers = 0;
   SwigType *td, *tc = 0;
   const SwigType *rs;
   List *elements;
@@ -797,7 +833,6 @@
   int firstarray = 1;
   int isreference = 0;
   int isfunction = 0;
-  int member_const_function = 0;
 
   result = NewStringEmpty();
 
@@ -846,15 +881,13 @@
       forwardelement = 0;
     }
     if (SwigType_isqualifier(element)) {
-      if (!member_const_function) {
+      if (!member_function_qualifiers) {
 	DOH *q = 0;
 	q = SwigType_parm(element);
 	Insert(result, 0, " ");
 	Insert(result, 0, q);
 	Delete(q);
 	clear = 0;
-      } else {
-        member_const_function = 0;
       }
     } else if (SwigType_ispointer(element)) {
       Insert(result, 0, "*");
@@ -868,32 +901,42 @@
       Insert(result, 0, "::*");
       q = SwigType_parm(element);
       Insert(result, 0, q);
-      Delete(q);
       if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
 	Insert(result, 0, "(");
 	Append(result, ")");
       }
-      if (SwigType_isqualifier(nextelement)) {
-	member_const_function_element = nextelement;
-	member_const_function = 1;
+      {
+	String *next3elements = NewStringEmpty();
+	int j;
+	for (j = i + 1; j < i + 4 && j < nelements; j++) {
+	  Append(next3elements, Getitem(elements, j));
+	}
+	if (SwigType_isfunction(next3elements))
+	  member_function_qualifiers = SwigType_pop_function_qualifiers(next3elements);
+	Delete(next3elements);
       }
       firstarray = 0;
+      Delete(q);
     } else if (SwigType_isreference(element)) {
-      Insert(result, 0, "&");
+      if (!member_function_qualifiers) {
+	Insert(result, 0, "&");
+	if (!isfunction)
+	  isreference = 1;
+      }
       if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
 	Insert(result, 0, "(");
 	Append(result, ")");
       }
-      if (!isfunction)
-	isreference = 1;
     } else if (SwigType_isrvalue_reference(element)) {
-      Insert(result, 0, "&&");
+      if (!member_function_qualifiers) {
+	Insert(result, 0, "&&");
+	if (!isfunction)
+	  isreference = 1;
+      }
       if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
 	Insert(result, 0, "(");
 	Append(result, ")");
       }
-      if (!isfunction)
-	isreference = 1;
       clear = 0;
     } else if (SwigType_isarray(element)) {
       DOH *size;
@@ -923,12 +966,13 @@
       }
       Append(result, ")");
       Delete(parms);
-      if (member_const_function_element) {
-	String *p = SwigType_str(member_const_function_element, 0);
+      if (member_function_qualifiers) {
+	String *p = SwigType_str(member_function_qualifiers, 0);
 	Append(result, " ");
 	Append(result, p);
 	Delete(p);
-	member_const_function_element = 0;
+	Delete(member_function_qualifiers);
+	member_function_qualifiers = 0;
 	clear = 0;
       }
       isfunction = 1;
diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h
index 0bcd53a..7452c37 100644
--- a/Source/Swig/swig.h
+++ b/Source/Swig/swig.h
@@ -136,6 +136,7 @@
   extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms);
   extern SwigType *SwigType_add_template(SwigType *t, ParmList *parms);
   extern SwigType *SwigType_pop_function(SwigType *t);
+  extern SwigType *SwigType_pop_function_qualifiers(SwigType *t);
   extern ParmList *SwigType_function_parms(const SwigType *t, Node *file_line_node);
   extern List *SwigType_split(const SwigType *t);
   extern String *SwigType_pop(SwigType *t);
diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c
index b2832b6..7a0626c 100644
--- a/Source/Swig/typeobj.c
+++ b/Source/Swig/typeobj.c
@@ -43,12 +43,12 @@
  * All type constructors are denoted by a trailing '.':
  * 
  *  'p.'                = Pointer (*)
- *  'r.'                = Reference (&)
- *  'z.'                = Rvalue reference (&&)
+ *  'r.'                = Reference or ref-qualifier (&)
+ *  'z.'                = Rvalue reference or ref-qualifier (&&)
  *  'a(n).'             = Array of size n  [n]
  *  'f(..,..).'         = Function with arguments  (args)
- *  'q(str).'           = Qualifier (such as const or volatile) (const, volatile)
- *  'm(qual).'          = Pointer to member (qual::*)
+ *  'q(str).'           = Qualifier, such as const or volatile (cv-qualifier)
+ *  'm(cls).'           = Pointer to member (cls::*)
  *
  *  The complete type representation for varargs is:
  *  'v(...)'
@@ -183,9 +183,10 @@
  * SwigType_pop()
  * 
  * Pop one type element off the type.
- * Example: t in:  q(const).p.Integer
- *          t out: p.Integer
- *	   result: q(const).
+ * For example:
+ *   t in:   q(const).p.Integer
+ *   t out:  p.Integer
+ *   result: q(const).
  * ----------------------------------------------------------------------------- */
 
 SwigType *SwigType_pop(SwigType *t) {
@@ -771,7 +772,6 @@
  *                                    Functions
  *
  * SwigType_add_function()
- * SwigType_del_function()
  * SwigType_isfunction()
  * SwigType_pop_function()
  *
@@ -795,14 +795,36 @@
   return t;
 }
 
+/* -----------------------------------------------------------------------------
+ * SwigType_pop_function()
+ *
+ * Pop and return the function from the input type leaving the function's return
+ * type, if any.
+ * For example:
+ *   t in:   q(const).f().p.
+ *   t out:  p.
+ *   result: q(const).f().
+ * ----------------------------------------------------------------------------- */
+
 SwigType *SwigType_pop_function(SwigType *t) {
   SwigType *f = 0;
   SwigType *g = 0;
   char *c = Char(t);
-  if (strncmp(c, "q(", 2) == 0) {
+  if (strncmp(c, "r.", 2) == 0 || strncmp(c, "z.", 2) == 0) {
+    /* Remove ref-qualifier */
     f = SwigType_pop(t);
     c = Char(t);
   }
+  if (strncmp(c, "q(", 2) == 0) {
+    /* Remove cv-qualifier */
+    String *qual = SwigType_pop(t);
+    if (f) {
+      SwigType_push(qual, f);
+      Delete(f);
+    }
+    f = qual;
+    c = Char(t);
+  }
   if (strncmp(c, "f(", 2)) {
     printf("Fatal error. SwigType_pop_function applied to non-function.\n");
     abort();
@@ -814,14 +836,55 @@
   return g;
 }
 
+/* -----------------------------------------------------------------------------
+ * SwigType_pop_function_qualifiers()
+ *
+ * Pop and return the function qualifiers from the input type leaving the rest of
+ * function declaration. Returns NULL if no qualifiers.
+ * For example:
+ *   t in:   r.q(const).f().p.
+ *   t out:  f().p.
+ *   result: r.q(const)
+ * ----------------------------------------------------------------------------- */
+
+SwigType *SwigType_pop_function_qualifiers(SwigType *t) {
+  SwigType *qualifiers = 0;
+  char *c = Char(t);
+  if (strncmp(c, "r.", 2) == 0 || strncmp(c, "z.", 2) == 0) {
+    /* Remove ref-qualifier */
+    String *qual = SwigType_pop(t);
+    qualifiers = qual;
+    c = Char(t);
+  }
+  if (strncmp(c, "q(", 2) == 0) {
+    /* Remove cv-qualifier */
+    String *qual = SwigType_pop(t);
+    if (qualifiers) {
+      SwigType_push(qual, qualifiers);
+      Delete(qualifiers);
+    }
+    qualifiers = qual;
+    c = Char(t);
+  }
+  assert(strncmp(c, "f(", 2) == 0);
+
+  return qualifiers;
+}
+
 int SwigType_isfunction(const SwigType *t) {
   char *c;
   if (!t) {
     return 0;
   }
   c = Char(t);
+  if (strncmp(c, "r.", 2) == 0 || strncmp(c, "z.", 2) == 0) {
+    /* Might be a function with a ref-qualifier, skip over */
+    c += 2;
+    if (!*c)
+      return 0;
+  }
   if (strncmp(c, "q(", 2) == 0) {
-    /* Might be a 'const' function.  Try to skip over the 'const' */
+    /* Might be a function with a cv-qualifier, skip over */
     c = strchr(c, '.');
     if (c)
       c++;
diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh
index 43bdb77..4a958df 100755
--- a/Tools/travis-linux-install.sh
+++ b/Tools/travis-linux-install.sh
@@ -33,10 +33,7 @@
 	"javascript")
 		case "$ENGINE" in
 			"node")
-				travis_retry sudo add-apt-repository -y ppa:chris-lea/node.js
-				travis_retry sudo apt-get -qq update
-				travis_retry sudo apt-get install -qq nodejs rlwrap
-				travis_retry sudo npm install -g node-gyp
+				travis_retry sudo apt-get install -qq nodejs node-gyp
 				;;
 			"jsc")
 				travis_retry sudo apt-get install -qq libwebkitgtk-dev
@@ -88,7 +85,7 @@
 		travis_retry sudo apt-get -qq install php$VER-cli php$VER-dev
 		;;
 	"python")
-		pip install pep8
+		pip install --user pep8
 		if [[ "$PY3" ]]; then
 			travis_retry sudo apt-get install -qq python3-dev
 		fi