Commit graph

90 commits

Author SHA1 Message Date
William S Fulton
72964a1faf Don't accept some invalid preprocessor code
Whitespace or non-numeric characters are required after a preprocessor
directive that requires an expression.
2018-01-16 08:07:37 +00:00
William S Fulton
532999f4f2 Improve error message when preprocessor expressions result in a floating point constant
Instead of a syntax error, the error is now:
  Warning 202: Error: 'Floating point constant in preprocessor expression'
2018-01-15 08:09:14 +00:00
William S Fulton
ea5b55ecf4 Fix floating point division by zero in preprocessor expressions.
Closes #1183
2018-01-15 07:51:18 +00:00
William S Fulton
07a30249f4 Fix seg fault parsing invalid exponents
Add error message when exponents are incomplete,
for example 5e and 5.e
2018-01-14 19:36:09 +00:00
William S Fulton
e27a606335 Allow an instantiated template to have the same name as the C++ template name
For example, this is now possible:
  template<typename T> struct X { ... };
  %template(X) X<int>;
Closes #1100.
2017-09-29 23:28:04 +01:00
William S Fulton
7e4717320b Add error for constructors, destructors, static methods declared with qualifiers
SWIG parses a superset of valid C++ declarations. These ill-formed declarations
were previously successfully parsed but now result an error message.
2017-08-30 18:17:05 +01:00
William S Fulton
8a40327aa8 Add unignore for rvalue ref-qualifiers
Use std::move on this pointer as the default approach to supporting
rvalue ref-qualifiers if a user really wants to wrap.

std::move requires <memory> headers so add swigfragments.swg for all
languages to use common fragments. Just header file fragments for now.
2017-08-30 18:17:04 +01:00
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
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
09af283371 Test a few %template errors 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
b851e45e0a Fix seg fault for global declarations declared erroneously without a name 2017-03-10 23:25:31 +00:00
William S Fulton
dee6b075a8 Fix seg fault parsing unterminated raw string literals 2017-02-09 22:02:20 +00:00
William S Fulton
1efcdd8c56 Remove error test that does warn 2017-01-26 20:34:56 +00:00
William S Fulton
e6b270b6dc Suppress incorrect warning when a keyword is used in template classes
Closes https://github.com/swig/swig/issues/845
2016-12-20 19:44:57 +00:00
Lior Goldberg
c363a93d69 Added support for type alias 2016-06-22 23:13:28 +03:00
William S Fulton
260501c45f Add comment about cpp_template_repeat testcase 2016-06-01 21:25:25 +01:00
William S Fulton
fa60e9c7b0 Removing empty errors tests - template typename missing
The missing typename was not warning, but this is too
hard to provide error/warning messages given SWIG supports missing type
information.
2016-06-01 21:25:25 +01:00
William S Fulton
0f0bb3015a Removing empty error tests - this one seems to be valid C preprocessor code 2016-06-01 21:25:25 +01:00
William S Fulton
e64998d55c Removing empty errors tests - tests that are valid C/C++ code 2016-06-01 21:25:25 +01:00
William S Fulton
ddd1b38fa2 Removing empty error tests - c_default_error
C default arguments are allowed, so migrated the error test to a proper test,
as no error or warning is expected.
2016-06-01 21:25:25 +01:00
William S Fulton
3efdbc8f2e Don't issue unnecessary base class ignored message
Don't warn about base class being ignored when the derived class is
itself ignored.

Closes #669
2016-05-02 22:50:09 +01:00
William S Fulton
7e1d95de09 Move subdirectory .gitignore to top level 2016-02-21 21:36:58 +00:00
William S Fulton
ca64b06229 Consistent quoting in Makefile 2015-08-21 22:48:34 +01:00
William S Fulton
e00a8026a6 More remove SWIG_LIB variable 2015-08-21 22:48:34 +01:00
William S Fulton
c6f8aadc64 Cosmetic corrections - Mac OS X 2015-08-02 20:14:20 +01:00
William S Fulton
e69cc0c0f5 Improve python code indentation warning / error messages 2015-07-30 08:26:17 +01:00
Olly Betts
822b2355c0 Improve handling of whitespace in %pythoncode
Previously SWIG looked at the indentation of the first line and removed
that many characters from each subsequent line, regardless of what those
characters were.  This was made worse because SWIG's preprocessor removes
any whitespace before a '#'.  Fixes github issue #379, reported by Joe
Orton.
2015-06-29 22:12:38 +12:00
William S Fulton
efa84dab7c Fix warning display of types associated with 'using' and templates. 2015-06-09 07:59:49 +01:00
Olly Betts
b19d506db7 Suppress warning 325 "Nested class not currently supported (Foo
ignored)" when Foo has already been explicitly ignored with
"%ignore".
2015-05-05 18:07:49 +12:00
William S Fulton
428b6176df Add support for friend templates, including operator overloading.
Closes #196.
2015-05-05 06:48:25 +01:00
Olly Betts
50ba1ea6fa Adjust testcase for unknown directive error
Fixes testcase failure caused by fix for issue #394.
2015-04-30 15:27:12 +12:00
Olly Betts
dba8d4a7ea Add regression test for 6b6b360
Reported in issue#368 by clintonstimpson.
2015-03-28 11:26:13 +13:00
Olly Betts
be4065531e Add suggestion to check block delimiter
The fix for #217 means that blocks of target code delimited by { } with
'#' comments in now give errors (previously these lines were quietly
discarded).

The fix is generally to use %{ %} delimiters instead, so suggest this
might be the issue in the error message to help users hitting this issue
with wrappers which were apparently working before.
2015-01-14 16:08:08 +13:00
Olly Betts
a2f803bb5a Add explanatory comment to pp_unknowndirective2.i 2015-01-14 16:00:40 +13:00
Olly Betts
02b10195fc Add regression test for #217 2015-01-12 22:33:15 +13:00
William S Fulton
af43f90484 Wording change for missing semicolon error 2015-01-08 23:37:52 +00:00
Olly Betts
62670e756e Improve errors for missing ; and unexpected ) 2015-01-08 15:27:57 +13:00
Olly Betts
8fbdd75a0b Add test coverage for unterminated %{ ... %} block 2015-01-08 13:26:39 +13:00
Olly Betts
ce90ff6a77 When reporting an error for a construct which hasn't been terminated
when the end of the file is reached, report it at the start line rather
than "EOF" as then tools like editors and IDEs will take you to a
generally more useful place for fixing the problem.
2015-01-08 13:19:17 +13:00
Olly Betts
51487c1acc Improve error message for extraneous '%}'. 2015-01-08 12:47:12 +13:00
Olly Betts
19961d7135 Add .gitignore for Examples/test-suite/errors/ 2015-01-08 12:25:47 +13:00
Olly Betts
809ebef1f8 Fix testcase name in expected output 2015-01-08 12:21:23 +13:00
Olly Betts
04715f74e2 Improve error message when an unknown SWIG directive is used
This previously gave the cryptic "Error: Syntax error in input(1).", but
now gives "Error: Unknown directive '%foo'."
2015-01-08 12:07:54 +13:00
Olly Betts
6eaec9ce7c Update expected output for pp_constant error test 2014-09-04 09:29:20 -03:00
Olly Betts
b9fe7b5f00 Disable case in pp_constant.i which never actually worked 2014-09-03 17:18:11 -03:00
William S Fulton
b71eb53bae Fix errors test-suite on windows 2014-05-29 11:47:38 +01:00
Karl Wette
3fe1eb7056 Set SRCDIR when calling test-suite clean targets, in case it's needed 2014-05-29 02:29:27 +02:00
William S Fulton
8ece62b945 Neaten up test-suite Makefile regeneration 2014-05-15 23:11:08 +01:00
William S Fulton
2b5499a262 Slight simplification of test-suite build for new out-of-source changes
Provide default SRCDIR and SCRIPTDIR variables in common.mk and override
only where needed.
2014-05-15 23:11:07 +01:00