Skip to content

Commit 74d12d8

Browse files
committed
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 swig#1465
1 parent 0deb8a8 commit 74d12d8

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

CHANGES.current

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.1.0 (in progress)
88
===========================
99

10+
2022-02-24: olly
11+
#1465 An invalid preprocessor expression is reported as a pair of
12+
warnings with the second giving a more detailed message from the
13+
expression evaluator. Previously SWIG prefixed the second message
14+
with "Error:" - that was confusing as it's actually only a warning
15+
by default so we've now dropped this prefix.
16+
17+
Before:
18+
19+
x.i:1: Warning 202: Could not evaluate expression '1.2'
20+
x.i:1: Warning 202: Error: 'Floating point constant in preprocessor expression'
21+
22+
Now:
23+
24+
x.i:1: Warning 202: Could not evaluate expression '1.2'
25+
x.i:1: Warning 202: Floating point constant in preprocessor expression
26+
1027
2022-02-23: olly
1128
#1384 Fix a preprocessor expression evaluation bug. A
1229
subexpression in parentheses lost its string/int type flag and
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pp_badeval.i:4: Warning 202: Could not evaluate expression 'FOO==4+'
2-
pp_badeval.i:4: Warning 202: Error: 'Expected an expression'
2+
pp_badeval.i:4: Warning 202: Expected an expression
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
pp_expressions_bad.i:7: Warning 202: Could not evaluate expression '1%ZERO'
2-
pp_expressions_bad.i:7: Warning 202: Error: 'Modulo by zero in expression'
2+
pp_expressions_bad.i:7: Warning 202: Modulo by zero in expression
33
pp_expressions_bad.i:9: Warning 202: Could not evaluate expression '2/ZERO'
4-
pp_expressions_bad.i:9: Warning 202: Error: 'Division by zero in expression'
4+
pp_expressions_bad.i:9: Warning 202: Division by zero in expression
55
pp_expressions_bad.i:12: Warning 202: Could not evaluate expression '1%(5-5)'
6-
pp_expressions_bad.i:12: Warning 202: Error: 'Modulo by zero in expression'
6+
pp_expressions_bad.i:12: Warning 202: Modulo by zero in expression
77
pp_expressions_bad.i:14: Warning 202: Could not evaluate expression '2/(55-55)'
8-
pp_expressions_bad.i:14: Warning 202: Error: 'Division by zero in expression'
8+
pp_expressions_bad.i:14: Warning 202: Division by zero in expression
99
pp_expressions_bad.i:18: Warning 202: Could not evaluate expression '1.2'
10-
pp_expressions_bad.i:18: Warning 202: Error: 'Floating point constant in preprocessor expression'
10+
pp_expressions_bad.i:18: Warning 202: Floating point constant in preprocessor expression
1111
pp_expressions_bad.i:21: Warning 202: Could not evaluate expression '2e3'
12-
pp_expressions_bad.i:21: Warning 202: Error: 'Floating point constant in preprocessor expression'
12+
pp_expressions_bad.i:21: Warning 202: Floating point constant in preprocessor expression
1313
pp_expressions_bad.i:25: Warning 202: Could not evaluate expression '8.8'
14-
pp_expressions_bad.i:25: Warning 202: Error: 'Floating point constant in preprocessor expression'
14+
pp_expressions_bad.i:25: Warning 202: Floating point constant in preprocessor expression
1515
pp_expressions_bad.i:29: Error: Unknown SWIG preprocessor directive: if123 (if this is a block of target language code, delimit it with %{ and %})
1616
pp_expressions_bad.i:30: Error: Extraneous #endif.
1717
pp_expressions_bad.i:32: Error: Unknown SWIG preprocessor directive: if456e (if this is a block of target language code, delimit it with %{ and %})
1818
pp_expressions_bad.i:33: Error: Extraneous #endif.
1919
pp_expressions_bad.i:42: Warning 204: CPP #warning, "Warning okay: #if(1)".
2020
pp_expressions_bad.i:48: Warning 202: Could not evaluate expression '"TWO" == 1'
21-
pp_expressions_bad.i:48: Warning 202: Error: 'Can't mix strings and integers in expression'
21+
pp_expressions_bad.i:48: Warning 202: Can't mix strings and integers in expression
2222
pp_expressions_bad.i:52: Warning 202: Could not evaluate expression '1 == ("TWO")'
23-
pp_expressions_bad.i:52: Warning 202: Error: 'Can't mix strings and integers in expression'
23+
pp_expressions_bad.i:52: Warning 202: Can't mix strings and integers in expression
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:EOF: Error: Exponent does not have any digits
22
pp_invalid_exponents.i:3: Warning 202: Could not evaluate expression '123e'
3-
pp_invalid_exponents.i:3: Warning 202: Error: 'Syntax error'
3+
pp_invalid_exponents.i:3: Warning 202: Syntax error
44
:EOF: Error: Exponent does not have any digits
55
pp_invalid_exponents.i:6: Warning 202: Could not evaluate expression '456.e'
6-
pp_invalid_exponents.i:6: Warning 202: Error: 'Syntax error'
6+
pp_invalid_exponents.i:6: Warning 202: Syntax error

Source/Preprocessor/cpp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,7 @@ String *Preprocessor_parse(String *s) {
16861686
Seek(value, 0, SEEK_SET);
16871687
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Could not evaluate expression '%s'\n", value);
16881688
if (msg)
1689-
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Error: '%s'\n", msg);
1689+
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "%s\n", msg);
16901690
allow = 0;
16911691
} else {
16921692
if (val == 0)
@@ -1720,7 +1720,7 @@ String *Preprocessor_parse(String *s) {
17201720
Seek(value, 0, SEEK_SET);
17211721
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Could not evaluate expression '%s'\n", value);
17221722
if (msg)
1723-
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Error: '%s'\n", msg);
1723+
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "%s\n", msg);
17241724
allow = 0;
17251725
} else {
17261726
if (val)

0 commit comments

Comments
 (0)