Commit Graph

200 Commits

Author SHA1 Message Date
William S Fulton a95017050e More maintainable warning messages 2024-10-06 12:28:17 +01:00
Olly Betts 0b26a3cd29 Warn and ignore C++11 auto variables we can't parse
See #3041
2024-09-29 09:31:34 +13:00
Olly Betts bbd822e25e Revert "Adjust c_decl_tail grammar rule"
This rule for function bodies currently also handles C++ {...}
initialisers, so this change broke cases such as:

  int x, y {2};

Just revert for 4.3.0 - not accepting valid C++ we previously accepted
is much worse that accepting invalid C++.

This reverts commit 18abdbca87.
2024-09-27 12:03:12 +12:00
Olly Betts 3c396ced31 Rework cpp_c_bool testcase
Check _Complex is also not treated as a keyword in C++ mode.

Check that `bool bool;` fails since if it doesn't then our test of
`bool _Bool;` succeeding doesn't prove anything).
2024-09-26 11:07:30 +12:00
Olly Betts 6567c5d186 Add support for C99 _Bool
SWIG now treats _Bool as an alias for the bool keyword when in C mode.
2024-09-25 06:23:48 +12:00
Olly Betts 18abdbca87 Adjust c_decl_tail grammar rule
The new version generates identical partialcheck output for the
testsuite, but avoids right recursion.

This refactoring means SWIG no longer accepts the invalid definition
of a function as the final part of a declaration, e.g.

  int x, f() { return 42; }

was previously accepted but now gives:

  c_bad_function_definition.i:4: Error: Syntax error - possibly a missing semicolon (';').

GCC gives:

  c_bad_function_definition.i:4:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token

clang gives:

  c_bad_function_definition.i:4:11: error: expected ';' after top level declarator

See #2884
2024-09-24 08:34:58 +12:00
Olly Betts f413a71804 Drop -Werror for cpp_final_destructor.i
I'd thought errors tests needed to fail but that's not the case so
this isn't necessary.
2024-09-22 07:57:39 +12:00
William S Fulton 64649df343 Don't show incorrect warning SWIGWARN_LANG_SMARTPTR_MISSING (520)
Was showing for an ignored derived class.

Closes #2879
2024-09-21 13:28:03 +01:00
Olly Betts 4663459d7f Don't ignore `final` after `noexcept` 2024-09-21 10:33:12 +12:00
Olly Betts ff2bedb72a Check specified underlying type of enum is valid
E.g. this:

  enum stuff : float { FOO, BAR };

Now gives:

Error: Underlying type of enum must be an integral type
2024-09-18 09:19:54 +12:00
Olly Betts 1b0900b511 Use ECHO_PROGRESS for C errors testcases too
Extends #2929
2024-09-16 13:21:36 +12:00
Olly Betts 4cc18abc11 Use ECHO_PROGRESS in the errors test suite too
Extends #2929
2024-09-16 13:06:22 +12:00
Olly Betts 4d2ba48b75 Improve error for unexpected token
Report "Unexpected token" rather than "Illegal token" since this
error fires for certain valid C/C++ tokens when used in an invalid way
(as well as `@` and `$`, but it's reasonable to report these as
"unexpected" too).

Also we now exit after this error rather than trying to continue
parsing, which used to just lead to a potentially confusing second
error.

For example instead of:

  c_unexpected_token.i:1: Error: Illegal token '/='.
  c_unexpected_token.i:1: Error: Syntax error - possibly a missing semicolon (';').

we now report:

  c_unexpected_token.i:1: Error: Unexpected token '/='.
2024-09-13 09:39:10 +12:00
Olly Betts c4fffb50b5 Restrict where we allow a bitfield width specifier
This was being handled in the wrong place in the grammar leading to
SWIG accepting nonsensical uses.  The new handling isn't perfect
(not least because C++20 added support for a bitfield with an
initialiser) but it's much less wrong than it was.
2024-09-12 10:58:22 +12:00
Olly Betts 30030583da Improve handling of zero bytes in input files
This is certainly a corner case, but GCC and clang both accept zero
bytes at least in comments, and SWIG's current handling is to ignore
the zero byte and all following characters up to and including the next
newline, so for example if a // comment contains a zero byte SWIG would
quietly ignore the next line.

Closes #3010
2024-09-03 10:14:01 +12:00
Olly Betts c6aca7eb08 Add error test for new error 2024-08-17 09:43:42 +12:00
Olly Betts 16680f59da Improve handling of bad octal and binary numbers
SWIG now gives an error for digits 8 and 9 in octal constants -
previously these were quietly accepted resulting in a bogus value.

C++11 binary constants are now treated similarly - only digits 0
and 1 were allowed before, but trying to use other digits now gives
a clearer error.
2024-08-15 13:47:47 +12:00
Olly Betts 4231b9d60d Allow unmatched ' and " in #error and #warning
Fixes #657
2024-08-12 16:55:44 +12:00
William S Fulton be03cd4176 Fix pointless warnings 330 for empty template instantiations
Appearing recently since 8c8e27d246.
Fixes warnings in test cases:
complextest, li_std_pair_extra, std_containers, template_nested_typemaps

Also attempts to instantiate a template for an unsupported nested template class
now have a separate new warning number 331 (SWIGWARN_PARSE_TEMPLATE_NESTED).

Closes #2965
2024-07-19 09:16:11 +01:00
William S Fulton 9a06c17e19 Add testcase for avoiding warning WARN_PARSE_USING_UNDEF
Closes issue #2941
2024-07-15 20:15:26 +01:00
William S Fulton 93887e5715 Merge branch 'github-win-ci'
* github-win-ci:
  No need to test so many versions of Python
  More cosmetic tweaks
  Cosmetic corrections - MinGW-w64
  Revert PYTHON_LIB change
  fromdos consistency for removing CR
  Show notest in name
  Restore appveyor testing
  Follow @wsfulton feedback
  Remove win32 userenv library.
  Replace 'cmd' with 'powershell'. As powershell stop on error. With 'Install MSYS2', as 'pacman' works with cmd,  add checks after each command for errors. Revert Windows 'SWIG_LIB'. SWIG Main, check SWIG_LIB environment for  null and empty string. Build with MING w64 compiler. Configure improve Windows python 3, try python-config first.
  Add "Machine Info" to CMAKE-WIN workflows. Replace here-documents and tabs with multiple echo lines. Add comments.
  As we add a new GitHub Windows test in ".github/workflows/win_ci.yml"
  Add windows actions using GitHub. Update Windows document. Small update in configuration. Remove SWIG_LIB_SET, windows should use the same value. Add better striping for multiple test in common make file. Add library path to dynamic python linking,  MSVC need to find the windows library linking file (*.lib). For other GCC, it does not change.

Closes issue #2813
2024-07-15 19:18:00 +01:00
William S Fulton 068f08df00 fromdos consistency for removing CR
Also fix mistakenly named todos which should be fromdos.
tr is used as it is always available and unfortunately
common.mk is not currently setup to use configure.ac output.
2024-07-13 13:43:33 +01:00
Erez Geva 36f7cdfb9e Replace 'cmd' with 'powershell'.
As powershell stop on error.
With 'Install MSYS2', as 'pacman' works with cmd,
 add checks after each command for errors.
Revert Windows 'SWIG_LIB'.
SWIG Main, check SWIG_LIB environment for
 null and empty string.
Build with MING w64 compiler.
Configure improve Windows python 3, try python-config first.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-07-02 11:07:56 +02:00
William S Fulton a24461dbac Update errors test-suite with correct warning text 2024-06-30 14:33:23 +01:00
William S Fulton 8c8e27d246 Add warning for ineffective %template instantiations
on forward template class declarations. A full template class definition is
required in order to wrap a template class as a proxy class.

Also tidyup handling of classforward code (no observable changes in
test-suite).
2024-06-29 17:36:46 +01:00
Erez Geva 44ede9e3cf Add windows actions using GitHub.
Update Windows document.
Small update in configuration.
Remove SWIG_LIB_SET, windows should use the same value.
Add better striping for multiple test in common make file.
Add library path to dynamic python linking,
 MSVC need to find the windows library linking file (*.lib).
For other GCC, it does not change.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-06-26 10:47:50 +02:00
William S Fulton 1e2b0b8079 Warning fix for redefined friend declarations that are also constexpr 2024-06-16 22:23:20 +01:00
William S Fulton 54916f150e Improved namespace validity checks for the nspace feature 2024-06-01 13:41:59 +01:00
William S Fulton e4795e9af0 Validate scopename in nspace feature 2024-06-01 08:04:14 +01:00
William S Fulton 59827e7191 Fix %nspace and %nspacemove for nested classes and enums in a class
For example:

  %nspace Space::OuterClass80;
  namespace Space {
    struct OuterClass80 {
      struct InnerClass80 {
        struct BottomClass80 {};
      };
      enum InnerEnum80 { ie80a, ie80b };
    };
  }

Previously the following were additionally required for some languages:

  %nspace Space::OuterClass80::InnerClass80;
  %nspace Space::OuterClass80::InnerClass80::Bottom80;

Now the appropriate nspace setting is taken from the outer class.

A new warning has also been introduced to check and correct conflicting
nspace usage, for example if the following is additionally added:

  %nspacemove(AnotherSpace) Space::OuterClass80::InnerClass80;

The following warning appears as an inner class can't be moved outside
of the outer class:

  Warning 406: Ignoring nspace setting (AnotherSpace) for 'Space::OuterClass80::InnerClass80',
  Warning 406: as it conflicts with the nspace setting (Space) for outer class 'Space::OuterClass80'.

This really helps with %nspacemove as now one can simply move an outer
class to another namespace, like this:

  %nspacemove(AnotherSpace) Space::OuterClass80;

and all the nested classes will automatically also be moved
into the appropriate namespace.
2024-06-01 08:04:08 +01:00
William S Fulton ce911f8ae3 Fix incomplete ignoring of duplicating %template instantiations
When template parameter typedefs are involved, a duplicate %template
instantiation was not properly ignoring the duplicate instantiation,
resulting in compile time errors.

Closes #2814
2024-02-23 22:08:10 +00:00
William S Fulton dc11837c64 Command encoder error message improvement
Show the actual command to help diagnose as the line number info is missing
2024-02-03 14:29:01 +00:00
William S Fulton 4cb2b253d0 Consistently set line number to 0 in DOH strings 2024-02-03 14:27:37 +00:00
William S Fulton a742321f11 Fix missing line/file info in error message 'Recursive typedef detected...' 2024-02-03 14:27:37 +00:00
William S Fulton 8e86058c5d Correctly report line numbering for warnings/errors for base classes that are templates
String is now also consistent with Hash and List wrt clearing contents,
but not the file/line numbering.

Closes issue #2781
2024-02-03 14:27:34 +00:00
William S Fulton 3be670e8db Fix assertion handling upcasting when using %shared_ptr on some templates.
A different approach is taken for supporting casting smart pointers up the
inheritance hierarchy. We no longer try to replace the underlying pointer type,
provided in the 'feature:smartptr', with the base class type. Such as morphing
'std::shared_ptr<(Derived)>' into 'std::shared_ptr<(Base)>'. Instead, we simply
use 'feature:smartptr' from the base class. This is more reliable than trying to
pattern match the pointer type in the feature. The base class must of course
also have the 'feature:smartptr' set, and this is still checked for as before.
The feature is now parsed in one place and stored in the parse tree in the
new 'smart' attribute for handling by the target languages.

Fix also improves the handling of the type parsed in 'feature:smartptr' in that
the type is now normalized and resolved in the scope of the class it is attached
to.

Closes #2768
2024-01-30 22:24:42 +00:00
Olly Betts 88d5d50899 Improve preprocessor warning
SWIG now warns:

Warning 202: Could not evaluate expression 'MY_VERSION_AT_LEAST(1,2,3)'
Warning 202: Use of undefined function-like macro

instead of:

Warning 202: Could not evaluate expression 'MY_VERSION_AT_LEAST(1,2,3)'
Warning 202: Syntax error: expected operator
2024-01-12 13:31:25 +13:00
Olly Betts 3d1a20a6c7 Expand cpp_decltype_unsupported error testcase 2023-12-13 07:42:24 +13:00
Olly Betts 02c45b9145 Expand cpp_decltype_unsupported error testcase 2023-12-06 15:59:47 +13:00
Olly Betts 58efc8b5f5 Add testcase for decltype cases we don't yet deduce 2023-12-04 17:39:23 +13:00
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