SWIG_NOEXCEPT is generated instead of throw() which is deprecated in
c++11. If c++11 or later is being used, then this macro expands to
noexcept instead of throw().
Affects director code only.
Also fix up some testcase to not use throw() when using c++11 or later.
Tested with clang and -Wdeprecated-dynamic-exception-spec as gcc
doesn't seem to warn for this deprecation.
Closes#3027
Fix compilation errors in generated code when instantiating a templated
static method within a template (non-static methods and constructors were
always okay). For example:
template <typename T> class X {
template <class InputIterator>
static void fn(InputIterator first, InputIterator last) { ... }
};
class SimpleIterator { ... };
%extend X<int> {
%template(fn) fn<SimpleIterator>;
}
The problem being fixed here is an extended method was generated when it
should not have been as for other %template instantiations within a
template - the template can be called directly.
Test includes variadic static method templates in a template, including
method overloading..
Old...
example.i:8: Error: 'Type' is multiply defined in the generated target language module.
:EOF: Error: Previous declaration of 'Type'
New...
example.i:8: Error: 'Type' is multiply defined in the generated target language module.
example.i:7: Error: Previous declaration of 'Type'
Fixes many cases, but the language symbols need more work in order for
deeper scopes to report the file/line numbering correctly.
Example from issue #1897
Const member variables such as the following are non-assignable by
by default:
const int x[2][2];
Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
Const member variables such as the following are non-assignable by
by default:
char * const x;
const int x;
const int x[1];
but not:
const char * x;
Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
Avoids confusion with newly created Allocate::is_assignable.
Language::is_immutable is just a wrapper around the
"feature:immutable" flag since previous commit.
is_mutable rename wip
A class that does not have an explicit assignment operator does not
have an implicit assignment operator if a member variable is not
assignable. Similarly should one of the base classes also not be
assignable. Detection of these scenarios has been fixed so that when
wrapping a variable that is not assignable, a variable setter is not
generated in order to avoid a compiler error.
Template instantiation via %template is required in order for this to
work for templates that are not assignable.
Closes#1416
Fix incorrect variable setters being generated when the type of the
variable is not assignable, due to variable type inheriting a private
assignment operator further up the inheritance chain (further up than
the immediate base).
Further removal of template parameters from the "name" attribute for
constructors and destructors.
Add test case for templated constructor instantiations - based on the
Python and Octave only li_std_pair_extra.i test which caused problems
making this change.
Support extended to directors.
Go protected constructors fix required for new testcase:
- Emit wrappers if director class is abstract
- If called, errors out with: accessing abstract class or protected constructor
- Now consistent with other target languages
This is one more step in the direction of supporting C++11 using
declarations for inheriting constructors that are implied/non-explicit
in a base class.
This step now adds the default constructor/destructors to the parse tree
in the earlier Allocate stage of processing the parse tree instead of
the language specific stage.
Doing this in the Allocate stage is much more sensible as this is the
stage that is primarily analysing the classes that require implied default
constructors and destructors.
Only minor complication is that the Language class controls most of the
director code generation and requires the previous commit to move director
enablement detection into Swig_directors_enabled() which is callable from
the Allocate class.
This is for consistency with other members.
Notable side effects:
- When $name is replaced in a constructor it no longer includes any
template parameters, so similar to member functions which also
don't include template parameters (li_boost_shared_ptr testcase)
This is for consistency with other members.
Fixes csymbol table name for the constructor.
Notable side effects:
- When $name is replaced in a constructor it no longer includes any
template parameters, so similar to member functions which also
don't include template parameters (li_boost_shared_ptr testcase)
- Fixes mangled C constructor name when using nested templates
(nested_in_template, template_nested testcases)
- Fixes some typedef look up when generating templates that have
default template parameters, to improve generated code so that
the default parameters are no longer explicitly generated when
the template type is used (template_default_class_parms_typedef
testcase)
- For Ruby, better error messages when calling constructors,
old:
runme.rb:5:in `initialize': Expected argument 0 of type int, but got String "hi" (TypeError)
in SWIG method 'Temply<(int)>'
new:
runme.rb:5:in `initialize': Expected argument 0 of type int, but got String "hi" (TypeError)
in SWIG method 'Temply'
- Feature matching of parameters that are template types is now
consistent for parameters in constructors and methods
(features testcase)
Potential incompatibility though:
old:
%exception Template<int>::Template(const Template&) "..."
new:
%exception Template<int>::Template(const Template<int>&) "..."
These features were all deprecated in 1.3.26 (October 9, 2005)
or before (many long before), so all more than 17 years and 3 new major
versions ago which seems more than enough time for users to have stopped
using them, especially as most emit a deprecation warning if used.
Previously we had a hard-coded list of allowed combinations in the
grammar, but this suffers from combinatorial explosion, and results
in a vague `Syntax error in input` error for invalid (and missing)
combinations.
This means we now support a number of cases which are valid C++
but weren't supported.
Fixes#302Fixes#2079 (friend constexpr)
Fixes#2474 (virtual explicit)
When a method with duplicate parameter names is wrapped such as:
void fn_3parms(int p_a, int p_a, double p_c);
Previously all duplicate parameter names were changed in order to
provide unique parameter names:
void fn_3parms(int arg0, int arg1, double p_c)
Now the parameter names changed are just the 2nd and subsequent duplicate
parameter names:
void fn_3parms(int p_a, int arg1, double p_c)
Further corrections to pass SwigType * to methods expecting types
instead of passing readable type strings.
Swig_string_mangle() takes a generic String *, but it was calling
functions that require SwigType *. Swig_string_mangle_type() is
now provided for SwigType *r. The special template handling
on types now occurs in this function.
Unfortunately the changes of 26bf86322 (Use SWIG-specific for
non-overloaded synthesized functions too, 2021-11-09) did break some
existing code bases using SWIG as they hardcoded the old wrapper
function names.
So turn this off by default and add a global variable allowing to enable
this, which can be done for a specific language only. This is ugly but,
unfortunately, there is no way to use the Language object from the C
function Swig_MethodToFunction(), so the only alternative would be to
add another parameter to it, but it already has 6 of them, so it
wouldn't really be that much better.
See #2366, #2368, #2370.
Language::unrollVirtualMethods was assuming that the using
declaration would only introduce one method. Fix this by adding
in all the overloaded methods from a base class.
Affects code generation in C# and Java, but I was not able
to construct a test that failed before this commit.
Move code in main loop into new function to handle one method at a time.
In preparation for next commit for using declaration fix.
Remove unused default_director variable.
This avoids conflicts between such functions, which are generated when
using %extend to add static methods to an existing class, and the actual
wrapper functions generated by the backend.
This shouldn't result in any user-visible changes.
No real changes, just move the test for "code" to the outer scope to
facilitate the upcoming changes.
This commit is best viewed ignoring whitespace-only changes.
These were officially deprecated in 2001, and attempts to use them have
resulted in a warning (including a pointer to what to update them to)
for most if not all of that time.
Fixes#1984
Generated SwigDirector_* classes were attempting to override
methods marked as final.
In addition, give a warning if the destructor of a director class is
final.
Closes#564.
Previously, only Python tried to preserve the original parameter name
(by prepending or appending an underscore to it, but otherwise keeping
the original name) if it conflicted with one of the language keywords,
while all the other languages replaced the parameter name with a
meaningless "argN" in this case.
Now do this for all languages as this results in more readable generated
code and there doesn't seem to be any reason to restrict this to Python
only.