Stop removing `f` and `F` suffixes from float literals

This was resulting in incorrect generated C# and Java code.  For
some cases such as `#define CONSTANT 1.0f` this was a regression
introduced in 4.2.0 when we started more correctly wrapping these
as `float` rather than `double`.

Fixes #1917
This commit is contained in:
Olly Betts 2024-07-10 09:56:19 +12:00
parent eb5a599e1c
commit 6eb2560e8d
3 changed files with 18 additions and 3 deletions

View File

@ -7,6 +7,13 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.3.0 (in progress)
===========================
2024-07-18: olly
#1917 Stop removing `f` and `F` suffixes from float literals.
This was resulting in incorrect generated C# and Java code. For
some cases such as `#define CONSTANT 1.0f` this was a regression
introduced in 4.2.0 when we started more correctly wrapping these
as `float` rather than `double`.
2024-07-15: vadz
#2941 Suppress warning WARN_PARSE_USING_UNDEF for ignored using declarations.

View File

@ -77,3 +77,14 @@ const int s9a = sizeof(-s8a);
// const int s9b = sizeof -s8a; /* not currently supported */
%}
/* Regression test for #1917, fixed in 4.3.0. */
#ifdef SWIGCSHARP
%csconst(1) float_suffix_test;
#endif
#ifdef SWIGJAVA
%javaconst(1) float_suffix_test;
#endif
%constant const float float_suffix_test = 4.0f;
%constant const float float_suffix_test2 = 4.0f;
#define float_suffix_test3 4.0f

View File

@ -1118,7 +1118,6 @@ static int look(Scanner *s) {
} else if ((c == 'e') || (c == 'E')) {
state = 82;
} else if ((c == 'f') || (c == 'F')) {
Delitem(s->text, DOH_END);
return SWIG_TOKEN_FLOAT;
} else if (isdigit(c)) {
state = 8;
@ -1139,7 +1138,6 @@ static int look(Scanner *s) {
else if ((c == 'e') || (c == 'E'))
state = 820;
else if ((c == 'f') || (c == 'F')) {
Delitem(s->text, DOH_END);
return SWIG_TOKEN_FLOAT;
} else if ((c == 'l') || (c == 'L')) {
Delitem(s->text, DOH_END);
@ -1276,7 +1274,6 @@ static int look(Scanner *s) {
if (isdigit(c))
state = 86;
else if ((c == 'f') || (c == 'F')) {
Delitem(s->text, DOH_END);
return SWIG_TOKEN_FLOAT;
} else if ((c == 'l') || (c == 'L')) {
Delitem(s->text, DOH_END);