Commit Graph

160 Commits

Author SHA1 Message Date
William S Fulton 8d17973f08 Add support for C++20 constexpr destructors
In the parser, cpp_end and cpp_vend are very similar. cpp_end is removed
and instead replaced by cpp_vend and additional checks that ensure a
non-virtual destructor does not have a pure specifier.
2023-11-24 20:12:02 +00:00
William S Fulton 705d5b875a Warning 302 rewording update for %extend 2023-07-28 07:51:32 +01:00
William S Fulton 52ede59cdf Reword and simplify warnings 302 and 322
The declaration is not displayed in the warning if it is the same as the
identifier.
2023-07-28 07:16:49 +01:00
William S Fulton 454c3bc52d Correct display of redundant typedefs in Warnings 302 and 322 2023-07-28 07:16:49 +01:00
William S Fulton 7cea399cba Correct display of class names in Warnings 302 and 322 2023-07-28 07:15:41 +01:00
William S Fulton 856d6f25e9 Redefinition/redeclaration warning message improvements
Add more information to these warning messages, including the
declaration for easier identification of the conflicting symbols.
Provides more consistent identifier names for constructors and methods.
Previously constructors did not display the template parameters, whereas
methods did. Incorrect 'renamed from' was also been shown for templated
methods (mmm in new testcase cpp_template_redefine.i).
2023-07-25 21:39:52 +01:00
William S Fulton 44fcdbd290 Fix display of template names in error messages in parser 2023-07-24 23:52:53 +01:00
William S Fulton b27ad0a923 Add warning for incorrect using declarations for inheriting constructors 2023-07-14 08:39:27 +01:00
William S Fulton feb8e2e641 Fix C++11 using declarations for inheriting implicit base constructors
Parser no longer checks for a declared constructor when handling a
using declaration in order to correct the name as it won't find
implicitly declared constructors. Now it checks that a using
declaration is for something that looks like a constructor instead
by checking the immediate base classes for allowed constructors.
2023-07-14 08:39:27 +01:00
William S Fulton 655d43769e Move adding members due to using declaration from Allocate to TypePass
Adding using declarations to the parse tree is done in this later
TypePass stage of processing the parse tree as the implicitly defined
constructors in the base class have already been added. The implicitly
defined constructors are also added in TypePass and are added during
processing of a base class, which is always before a derived class.
These constructors are thus available for a derived class to use when
TypePass::usingDeclaration is looking for base class constructors to add
to the parse tree.

This is a another step towards supporting C++11 using declarations for
inheriting base class constructors that are implicitly defined, both
template and non-template classes.
2023-07-14 08:39:27 +01:00
Olly Betts 365a540fdb Add test coverage for #error and #warning
This replaces and extends the coverage lost by the removal of
errors testcase pp_deprecated.

See #2635
2023-06-15 15:05:16 +12:00
Olly Betts 736c052d7d Remove long deprecated features
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.
2023-06-15 15:05:15 +12:00
Olly Betts 4180b48ad4 Revert attempt to improve parsing of &&
The fix itself works, but causes problems in other cases so back it
out for now.

Reopens #2228

This reverts commit 82ee2f8cd4.
This reverts commit 0f0d7cb00d.
2023-06-06 12:58:07 +12:00
Olly Betts 0f0d7cb00d Fix regression from previous change
The previous change broke the cpp_missing_rtemplate error testcase.
Fix this (and as a bonus, we now give a better error message for
this case).
2023-06-06 11:53:45 +12:00
Olly Betts df5f5497b8 Suppress syntax error after skip_balanced() fails
In this situation, skip_balanced() reports a useful error such as
(the '}' part varies depending what we're trying to skip over):

Error: Missing '}'. Reached end of input.

We now exit after such failures which avoids reporting a second more
generic error like:

Error: Syntax error in input(1).

or:

Error: Syntax error in input(3).

Fixes #2606
2023-05-23 17:56:03 +12:00
Olly Betts a3db89c6ee Document what c_spaceship.i is testing 2023-05-16 11:45:36 +12:00
William S Fulton 0c56f3557e Improved error checking when defining classes and using %template.
1. When a template is instantiated via %template and uses the unary scope
operator ::, an error occurs if the instantiation is attempted within a
namespace that does not enclose the instantiated template.
For example, the following will now error as ::test::max is not enclosed within test1:

Error: '::test::max' resolves to 'test::max' and was incorrectly instantiated in
scope 'test1' instead of within scope 'test'.
  namespace test1 {
    %template(maxchar) ::test::max<char>;
  }

2. SWIG previously failed to always detect a template did not exist when using
%template. In particular when instantiating a global template incorrectly within
namespace. The code below now correctly emits an error:

Error: Template 'test5::GlobalVector' undefined.
  namespace test5 {
  }
  template<typename T> struct GlobalVector {};
  %template(GVI) test5::GlobalVector<int>;

3. Also error out if an attempt is made to define a class using the unary scope
operator ::. The following is not legal C++ and now results in an error:

Error: Using the unary scope operator :: in class definition '::Space2::B' is invalid.
  namespace Space2 {
    struct B;
  }
  struct ::Space2::B {};
2023-03-13 22:39:59 +00:00
William S Fulton 7c043d4713 Redefined identifer testcase now correctly errors 2023-03-13 22:27:08 +00:00
William S Fulton 2171115d38 Update errors tests to use new template error
Old: Error: Template 'X' undefined.
New: No matching function template 'X' found.
2023-03-09 20:38:30 +00:00
William S Fulton 9924c5c3e1 Partial template specialization fixes to support default arguments
Default argments come from the primary template's parameter list.

Example:
  template<class Y, class T=int> struct X { void primary() {} };
  // Previously the specialization below resulted in:
  // Error: Inconsistent argument count in template partial specialization. 1 2
  template<class YY> struct X<YY*> { void special(YY*) {} };

  // Both of these correctly wrap the partially specialized template
  %template(StringPtr) X<const char *>;
  %template(ShortPtr) X<short *, int>;
2023-03-01 19:42:00 +00:00
William S Fulton 4729cf2b1f Duplicate class template instantiations via %template changes
Named duplicate class template instantiations now issue a warning and are ignored.
Duplicate empty class template instantiations are quietly ignored.

The test cases are fixed for this new behaviour.

This commit is a pre-requisite for the near future so that the Python
builtin wrappers can correctly use the SwigType_namestr function without
generating duplicate symbol names.
2022-11-18 19:35:47 +00:00
Olly Betts 06296a7128 Report errors in preprocessor expressions by default
Until now SWIG quietly ignored such errors unless -Wextra (or -Wall
which implies -Wextra) was passed, but this is unhelpful as it hides
problems.  To illustrate this point, enabling this warning by
default revealled a typo in the preproc_defined.i testcase in
SWIG's own testsuite.

If you really don't want to see this warning, you can suppress it
with command line option -w202 or by using this in your interface
file:

%warnfilter(SWIGWARN_PP_EVALUATION);

Both will work with older versions of SWIG too.

Fixes #1465
Fixes #2389
2022-10-05 17:07:06 +13:00
Olly Betts 346ede21c3 Fix spaceship preproc tests for previous change 2022-07-27 18:17:31 +12:00
Olly Betts 100d4d5350 Only recognise spaceship operator for C++
I don't think any valid C program can contain `<=>` in a tokenisable
context, but it's more helpful to fail with a syntax error at SWIG
parse time and not potentially generate C code trying to use `<=>` in
an expression which then fails at compile time.
2022-07-27 13:46:53 +12:00
Olly Betts 02b4bd8eca Fix spaceship operator bugs, document, add tests
Remove some erroneously added brackets_increment() calls.

Reject <=> in preprocessor expressions with a clear error message (it
seems it isn't supported here - clang and gcc don't at least).

The type returned by `<=>` is not `bool`.  We pretend it's
`int` for now, which should work for how it's likely to be used
in constant expressions.

Fixes #1622
2022-07-27 09:12:40 +12:00
Olly Betts 07f0b732ba Add machinery for C++14, C++17 and C++20 testing
Support running testcases conditional on the compiler supporting
a each language version, like we already handle C++11.

Currently no testcases are actually run in this way for these
newer language versions.
2022-07-26 15:28:51 +12:00
William S Fulton 5cc4591ae7 Consistent cpp11 testing in test-suite
Move HAVE_CXX11 into makefiles so that running test-suite
from top level directory or in the language's test-suite directory
is consistent. For example, running 'make check-java-test-suite'
behaves the same as 'cd Examples/test-suite/java && make check'.
2022-03-27 19:34:20 +01:00
Olly Betts d7e83c1cbc Fix checking of "optimal" typemap attribute
Previously SWIG checked that the typemap action contained ";\n" not
followed by an identifier character, and that it contained no other
`;`, but that incorrectly allows some cases it shouldn't.

Instead check that the action ends with `;\n` and contains no other
`;`, which is simpler and correctly rejects these cases.
2022-03-19 08:13:09 +13:00
William S Fulton e53f51b89d Add missing symtab for functions added by using declarations
Fixes fully qualified names for functions added by using declarations:
- Error messages show fully qualified names in Lua
- Overload warning messages show fully qualified names
- Error messages calling dispatch functions for handling overloaded methods in OCaml, Python and Tcl
2022-03-10 22:18:23 +00:00
Olly Betts 7bdef23304 Fix incorrect expected output in new testcase 2022-03-06 12:13:51 +13:00
Olly Betts 8cd2cfa9d1 Improve the change to allow parsing `9%a`
If there was a later syntax error, this could incorrectly get
reported as:

Error: Unknown directive '%a'.
2022-03-04 17:00:20 +13:00
Olly Betts 9eb75a0c07 Improve typemap method and attribute checking
Specifying a value on the typemap method now gives an error, e.g.:

%typemap(argout=123) char * ""

The old way of specifying a language name in the typemap attributes
is no longer supported (it has been deprecated for 16 years).

Closes #891
2022-03-03 18:46:15 +13:00
Olly Betts aa24e6b22b Handle typemap argument without a value
This now gives an error, previously SWIG segfaulted.

Fixes #891
2022-03-02 15:56:43 +13:00
William S Fulton 961424a986 Fix line/file info for methods added by using declarations 2022-02-26 20:07:58 +00:00
William S Fulton eb32a6298d Add omitted testcase cpp_using_rename.i 2022-02-26 20:01:57 +00:00
William S Fulton 79a1bbee8b Using declarations in inheritance hierarchy improvements.
- Improved documentation for using declarations.
- Issue new warning WARN_LANG_USING_NAME_DIFFERENT when there
  is a conflict in the target language name to be used when
  introducing a method via a using declaration. Previously
  the method was silently ignored. Issue #1840. Issue #655.
2022-02-26 12:46:06 +00:00
Olly Betts 7f37bfe2b5 Mark error messages more consistent
Always include English name of a mentioned character.
2022-02-25 10:07:17 +13:00
Olly Betts 4986b8793d Emit preprocessor expr error for unary + on string
Previously other unary operators on a string all gave an error, but
unary + was handled as a no-op and so didn't.
2022-02-24 09:50:22 +13:00
Olly Betts 74d12d8c4c Don't report "Warning 202: Error: ..."
An invalid preprocessor expression is reported as a pair of
warnings with the second giving a more detailed message from the
expression evaluator.  Previously SWIG prefixed the second message
with "Error:" - that was confusing as it's actually only a warning
by default so we've now dropped this prefix.

Before:

x.i:1: Warning 202: Could not evaluate expression '1.2'
x.i:1: Warning 202: Error: 'Floating point constant in preprocessor expression'

Now:

x.i:1: Warning 202: Could not evaluate expression '1.2'
x.i:1: Warning 202: Floating point constant in preprocessor expression

See #1465
2022-02-24 08:40:27 +13:00
Olly Betts 0deb8a855d Add another testcase for #1384
A string in parentheses could be treated as an integer (depending on
the state the stack was left in by previously evaluated expressions).
2022-02-24 08:30:32 +13:00
Olly Betts a7ff0da1f3 Improve parsing of % followed immediately by identifier
If it's not a recognised directive the scanner now emits MODULO and then
rescans what follows, and if the parser then gives a syntax error we
report it as an unknown directive. This means that `a%b` is now allowed
in an expression, and that things like `%std::vector<std::string>` now
give an error rather than being quietly ignored.

Fixes #300
Fixes #368
2022-02-15 15:09:44 +13:00
Olly Betts 89a0a3c5f7
Merge pull request #2197 from swig-fortran/rename-warn
Print rename warnings except anonymous template methods
2022-02-10 16:15:10 +13:00
Olly Betts 467c530e65 Remove support for the "command" encoder
The "command" encoder was mostly intended for use in `%rename` - most
uses can be achieved using the "regex" encoder, so we recommend using
that instead.

The "command" encoder suffers from a number of issues - as the
documentation for it admitted, "[it] is extremely slow compared to all
the other [encoders] as it involves spawning a separate process and
using it for many declarations is not recommended" and that it "should
generally be avoided because of performance considerations".

But it's also not portable.  The design assumes that `/bin/sh` supports
`<<<` but that's a bash-specific feature so it doesn't work on platforms
where `/bin/sh` is not bash - it fails on Debian, Ubuntu and probably
some other Linux distros, plus most non-Linux platforms.  Microsoft
Windows doesn't even have a /bin/sh as standard.

Finally, no escaping of the passed string is done, so it has potential
security issues (though at least with %rename the input is limited to
valid C/C++ symbol names).

Fixes #1806
2022-02-07 09:47:01 +13:00
Seth R Johnson 018254cca3 Reformat name warnings to reduce changes 2022-02-06 13:51:37 -05:00
Seth R Johnson de78b80de9 Renames performed by `%namewarn` with `rename=` are printed in warning message
This is necessary for regex-like renames (where you can't use the #define trick
as is done in many of the %keywordwarn directives). It's now unnecessary to print
the "renaming to '`x`'" code explicitly by the kw.swg files.
2022-02-06 13:51:37 -05:00
Olly Betts 282e4ed4ab Issue error for missing ; after %constant
Previously there was no warning or error, no files were produced,
but exit status was 0.

Fixes #346
2022-01-27 15:35:24 +13:00
Olly Betts 0a7192ce8b [doxygen] Fix crash on unclosed HTML tag
Fixes #1935
2022-01-26 15:12:21 +13:00
William S Fulton 017900d57e Extern template tweaks
Document extern template functions support.
Extern templates result in new warning to differentiate
from template explicit instantiation definition warning.
2022-01-25 00:28:08 +00:00
Olly Betts 9ddc9dceb7 Remove support for $source and $target
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
2021-04-30 10:20:14 +12:00
William S Fulton 0d76eb3b56 The errors testcases use -module to obtain a unique module name
Fixes parallel make where each invocation of swig was writing and
deleting the same file resulting in lots of the newly introduced
warning messages:

  On exit, could not delete file xxx.py: No such file or directory
2019-07-31 00:08:49 +01:00