Commit graph

4,312 commits

Author SHA1 Message Date
William S Fulton
1cf599bccb Improve ref-qualifier implementation
Internally, handle function ref-qualifiers in the function decl type string.
Needed for a whole host of things to work like %feature and %rename.
Add %feature %rename and %ignore testing for ref-qualifiers.
2017-08-30 18:17:04 +01:00
William S Fulton
eeab152901 Fix support for member const function pointer variables
Was not generating code that compiled when the variable was not
a simple member pointer, for example,
a const reference member pointer:
  short (Funcs::* const& cc7)(bool) const = cc1;
2017-08-30 18:16:59 +01:00
William S Fulton
685ee6cdc4 Use normal SWIG encodings for ref-qualifiers 2017-08-19 09:38:19 +01:00
William S Fulton
9e19fe7868 C++11 ref-qualifier support added
Fixes #1059

Methods with rvalue ref-qualifiers are ignored by default as it is not
possible to have an rvalue temporary from the target language (which is
needed to call the rvalue ref-qualified method).
A warning 405 is shown mentioning the ignored rvalue ref-qualifier method
which can be seen with the -Wextra option.

  cpp_refqualifier.i:15: Warning 405: Method with rvalue ref-qualifier ignored h() const &&.

Usually rvalue and lvalue ref-qualifier overloaded methods are written - the
lvalue method will then be wrapped.
2017-08-19 01:02:34 +01:00
William S Fulton
32a454cfef Merge branch 'templates-scope-enforcement'
* templates-scope-enforcement:
  Test a few %template errors
  Add using declarations to templates into typedef table.
  Fix type lookup in the presence of using directives and using declarations
  More docs on %template
  Testcase fix for nameclash in php
  %template scope enforcement and class definition fixes
  Template documentation tweaks
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  Documentation corrections to use targetlang formatting
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  Namespace documentation minor corrections
  Improve description of template_parameters_resolve
  Minor code optimisation in template_parameters_resolve
  Fix scope lookup for template parameters containing unary scope operators
  Typemap change for templates
2017-08-16 21:44:51 +01:00
William S Fulton
96e99416d7 Add using declarations to templates into typedef table.
Fixes #1051. Using declarations to templates were missing in SWIG's internal typedef tables.
This led to a few problems, such as, templates that did not instantiate and generated
C++ code that did not compile as SWIG did not know what scope the template was
in. This happened mostly when a using declaration was used on a template type in a
completely unrelated namespace.
2017-08-16 00:24:25 +01:00
William S Fulton
bf98c5304f Fix type lookup in the presence of using directives and using declarations
Fix some cases of type lookup failure via a combination of both using directives and
using declarations resulting in C++ code that did not compile as the generated type was
not fully qualified for use in the global namespace. Example below:

    namespace Space5 {
      namespace SubSpace5 {
        namespace SubSubSpace5 {
          struct F {};
        }
      }
      using namespace SubSpace5;
      using SubSubSpace5::F;
      void func(SubSubSpace5::F f);
    }
2017-08-16 00:24:25 +01:00
William S Fulton
959e627208 %template scope enforcement and class definition fixes
The scoping rules around %template have been specified and enforced.
The %template directive for a class template is the equivalent to an
explicit instantiation of a C++ class template. The scope for a valid
%template instantiation is now the same as the scope required for a
valid explicit instantiation of a C++ template. A definition of the
template for the explicit instantiation must be in scope where the
instantiation is declared and must not be enclosed within a different
namespace.

For example, a few %template and explicit instantiations of std::vector
are shown below:

  // valid
  namespace std {
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // valid
  using namespace std;
  %template(vin) vector<int>;
  template class vector<int>;

  // valid
  using std::vector;
  %template(vin) vector<int>;
  template class vector<int>;

  // ill-formed
  namespace unrelated {
    using std::vector;
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // ill-formed
  namespace unrelated {
    using namespace std;
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // ill-formed
  namespace unrelated {
    namespace std {
      %template(vin) vector<int>;
      template class vector<int>;
    }
  }

  // ill-formed
  namespace unrelated {
    %template(vin) std::vector<int>;
    template class std::vector<int>;
  }

When the scope is incorrect, an error now occurs such as:

cpp_template_scope.i:34: Error: 'vector' resolves to 'std::vector' and
was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.

Previously SWIG accepted the ill-formed examples above but this led to
numerous subtle template scope problems especially in the presence of
using declarations and using directives as well as with %feature and %typemap.

Actually, a valid instantiation is one which conforms to the C++03
standard as C++11 made a change to disallow using declarations and
using directives to find a template.

  // valid C++03, ill-formed C++11
  using std::vector;
  template class vector<int>;

Similar fixes for defining classes using forward class references have
also been put in place. For example:

namespace Space1 {
  struct A;
}
namespace Space2 {
  struct Space1::A {
    void x();
  }
}

will now error out with:

cpp_class_definition.i:5: Error: 'Space1::A' resolves to 'Space1::A' and
was incorrectly instantiated in scope 'Space2' instead of within scope 'Space1'.
2017-08-16 00:24:25 +01:00
William S Fulton
2681bbad36 Improve description of template_parameters_resolve 2017-08-16 00:24:24 +01:00
William S Fulton
8bf3a342c2 Minor code optimisation in template_parameters_resolve 2017-08-16 00:24:24 +01:00
William S Fulton
26e14c4f18 Fix scope lookup for template parameters containing unary scope operators
Fixes cases like:

namespace Alloc {
  template<typename T> struct Rebind {
    typedef int Integer;
  };
}
%template(RebindBucket) Alloc::Rebind< Bucket >;
OR
%template(RebindBucket) Alloc::Rebind< ::Bucket >;

Alloc::Rebind< Bucket >::Integer Bucket1() { return 1; }
Alloc::Rebind< ::Bucket >::Integer Bucket2() { return 2; }
Alloc::Rebind<::template TemplateBucket<double>>::Integer Bucket3() { return 3; };
2017-08-16 00:24:24 +01:00
William S Fulton
aa2932f409 Typemap change for templates
For templates only, the template parameters are fully resolved when
handling typemaps. Without this, it is too hard to have decent rules
to apply typemaps when parameter types are typedef'd and template
parameters have default values.

Fixes %clear for typedefs in templates, eg:

  %typemap("in") XXX<int>::Long "..."
  template typename<T> struct XXX {
    typedef long Long;
  };
  %clear XXX<int>::Long;

as the typemap was previously incorrectly stored as a typemap for long
instead of XXX<int>::Long.
2017-08-16 00:24:06 +01:00
William S Fulton
2165f27f5d Fix incorrectly shown warning for empty template instantiation used as a base class. 2017-08-13 21:32:44 +01:00
Olly Betts
90f9117e10 Fix various comment and documentation typos 2017-08-13 18:04:33 +12:00
Olly Betts
a92137a708 [C++11] Allow static_assert at the top level
And disallow it right after template<T>).

Fixes https://github.com/swig/swig/issues/1031 reported by Artem V L.
2017-08-04 14:09:30 +12:00
William S Fulton
7be6c10d4a Fix display of documented template types when using the autodoc feature for Python. 2017-07-07 19:35:44 +01:00
Nihal
251d25346d Fix OUTPUT Typemap not having return statement bug in PHP wrapper. 2017-06-28 09:47:33 +12:00
William S Fulton
a2267a8152 Memory leak fixes in Python default argument handling 2017-06-23 14:19:12 +01:00
Olly Betts
2425c8d6d8 Don't handle cases like -1U as Python constants 2017-06-23 14:54:50 +12:00
Michael Thon
80ffb169c1 [Python] fix and improve default argument handling
1. Fix negative octals. Currently not handled correctly by `-py3`
   (unusual case, but incorrect).
2. Fix arguments of type "octal + something" (e.g. `0640 | 04`).
   Currently drops everything after the first octal. Nasty!
3. Fix bool arguments "0 + something" (e.g. `0 | 1`) are always
   "False" (unusual case, but incorrect).
4. Remove special handling of "TRUE" and "FALSE" from
   `convertValue` since there's no reason these have to match
   "true" and "false".
5. Remove the Python 2 vs. Python 3 distinction based on the
   `-py3` flag. Now the same python code is produced for default
   arguments for Python 2 and Python 3. For this, octal default
   arguments, e.g. 0644, are now wrapped as `int('644', 8)`. This
   is required, as Python 2 and Python 3 have incompatible syntax
   for octal literals.

Fixes #707
2017-06-23 13:38:49 +12:00
William S Fulton
687cf9c9c1 Add missing %python:maybecall to operator overloads.
This ensures NotImplemented is returned on error so that the Python
interpreter will handle the operators correctly instead of throwing an
exception. NotImplemented was not being returned for non-builtin wrappers
when the operator overload did not have a function overload.

See PEP 207 and https://docs.python.org/3/library/constants.html#NotImplemented

Mentioned in SF patch #303 and SF bug #1208.
2017-06-19 19:25:27 +01:00
William S Fulton
11aa71b939 Make sure warning and error messages are not split up
They could be split up by other processes writing to stdout
at the same time.
2017-06-16 19:24:48 +01:00
William S Fulton
6a7cd97fe9 Fix R function pointer wrappers containing lvalue and rvalue reference parameters 2017-06-16 07:41:05 +01:00
William S Fulton
9d5d991f83 Merge branch 'master' of git+ssh://github.com/swig/swig
* 'master' of git+ssh://github.com/swig/swig:
  update changes referencing issue
  fix Scilab 6.0.0 linking issue

Conflicts:
	CHANGES.current
2017-06-05 20:58:12 +01:00
William S Fulton
57a89f987d Fix %import and %fragment forced inclusion to not generate code. 2017-06-03 18:37:05 +01:00
William S Fulton
9f55985a6c Remove unused code 2017-06-03 18:37:05 +01:00
Clément DAVID
9278593dc4 fix Scilab 6.0.0 linking issue 2017-05-30 14:42:44 +02:00
William S Fulton
a2d65ca3bb Merge branch 'asibross-master' into director-smartptr-ownership
* asibross-master:
  Missing smart pointer handling in Java director extra methods implementation.

Conflicts:
	Source/Modules/java.cxx
2017-05-25 08:00:35 +01:00
William S Fulton
05badeb1a4 Remove undocumented features used in directors
The jsdowncast and csdowncast features are not documented and I think
these are a relic of something that was never finished.
2017-05-21 17:43:06 +01:00
William S Fulton
b90a8d7444 Remove unnecessary dynamic_cast in C#/D/Java directors
Also revert the removal of dynamic_cast in the csdowncast feature.
2017-05-21 17:42:27 +01:00
William S Fulton
7f2849cb0a Merge branch 'Sghirate-master'
* Sghirate-master:
  [C#] static_cast for native directors
2017-05-21 00:22:17 +01:00
William S Fulton
81ba06e59e Fix Python negative unsigned default values
Closes #993
2017-05-21 00:02:08 +01:00
Julien Schueller
ed54cc904c Fix E731: do not assign a lambda expression
https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-05-19 22:49:23 +02:00
Olly Betts
9a0180c56c Merge pull request #970 from nihal95/master
Adds pragma version directive for php5 and php7.  Fixes #360.
2017-05-16 17:47:35 +12:00
William S Fulton
320df84607 Add missing return for pure virtual director wrappers for D and C# 2017-05-13 23:17:02 +01:00
William S Fulton
ebd37155a8 Fix potential use of uninitialized variables in directors 2017-05-13 22:40:59 +01:00
William S Fulton
731f175d21 propagate c++11 noexcept to director classes for Go 2017-05-13 18:13:53 +01:00
William S Fulton
f6d10278f8 Merge branch 'yag00-master'
* yag00-master:
  Add raise methods for throwing c++ exceptions in C#, Java, D
  php5: propagate c++11 noexcept to director classes
  Revert "java : noexcept method can't raise Swig::DirectorException"
  Revert "csharp : noexcept method can't raise Swig::DirectorPureVirtualException"
  csharp : noexcept method can't raise Swig::DirectorPureVirtualException
  java : noexcept method can't raise Swig::DirectorException
  #526 : propagate c++11 noexcept to director classes
  #526 : propagate c++11 noexcept to director classes test case
2017-05-13 17:05:25 +01:00
William S Fulton
07ab80b49e Add raise methods for throwing c++ exceptions in C#, Java, D
The director c++ exceptions are thrown in a helper method instead of in
the director overloaded method. This circumvents compiler warnings about
throwing exceptions when the method has an exception specification or
noexcept. If the exception is thrown, abort will still be called!
In Java, the "director:noexcept" typemap can be used to do something
else. This typemap should be ported to the other languages too.
2017-05-13 17:01:15 +01:00
William S Fulton
971404485f php5: propagate c++11 noexcept to director classes 2017-05-13 16:59:36 +01:00
William S Fulton
cedfbfbee8 Revert "java : noexcept method can't raise Swig::DirectorException"
This reverts commit e13eaaae21.
2017-05-13 16:16:29 +01:00
William S Fulton
e429a891c9 Revert "csharp : noexcept method can't raise Swig::DirectorPureVirtualException"
This reverts commit 9dcf10138e.
2017-05-13 16:16:17 +01:00
Nihal
eb9e72f3b2 Add new pragma to specify version to PHP5 and PHP7 extensions.
See issue #360, feature request to have version in php5 and php7 extensions.
2017-05-08 11:43:38 +05:30
Nihal
3adf88e9ef Refactor to generate init section before the code.
Prerequisite to address issue #360, feature request of adding extension version.
This change has been taken from Sources/Modules/php.cxx - PHP7 Backend.
2017-05-07 17:49:02 +05:30
Christophe Duvernois
9dcf10138e csharp : noexcept method can't raise Swig::DirectorPureVirtualException 2017-04-28 11:45:36 +02:00
Christophe Duvernois
e13eaaae21 java : noexcept method can't raise Swig::DirectorException 2017-04-28 11:45:02 +02:00
Christophe Duvernois
4777a0ad3c #526 : propagate c++11 noexcept to director classes 2017-04-27 23:37:15 +02:00
Philip Herron
624ec3e1b7 Fix bug with comments inline in macros
- commit fixes #974
2017-04-27 15:35:13 +01:00
Simon Marchetto
c06c9b3853 [Scilab] New parameter targetversion to specify the Scilab target version (5, 6, ..) for code generation
With Scilab 6 target specified, identifier names truncation is disabled (no longer necessary)

Signed-off-by: Simon Marchetto <simon.marchetto@scilab-enterprises.com>
2017-04-12 13:54:42 +02:00
William S Fulton
29af5c7aec Merge branch 'srepmub-coverity_args_check'
* srepmub-coverity_args_check:
  [Coverity] fix issue reported for wrapper argument checking
2017-03-24 07:26:54 +00:00