diff --git a/CHANGES.current b/CHANGES.current index e2072fd33..1db9cbca1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,31 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.0.0 (in progress) =========================== +2018-01-16: wsfulton + Expressions following a preprocessor directive must now be separated by whitespace + or non-numeric characters. This syntax change makes the SWIG preprocessor work like + the C preprocessor in this area. + + For example, the following code used be accepted as valid syntax: + #if1 + #define ABC 123 + #endif + + Now you get an error: + example.h:1: Error: Unknown SWIG preprocessor directive: if1 (if this is a block of + target language code, delimit it with %{ and %}) + example.h:3: Error: Extraneous #endif. + + The following is the correct syntax: + #if 1 + #define ABC 123 + #endif + + The following of course also works: + #if(1) + #define ABC 123 + #endif + 2018-01-15: wsfulton Fix issue #1183. Floating point exception evaluating preprocessor expressions resulting in division by zero. diff --git a/Examples/test-suite/errors/pp_expressions_bad.i b/Examples/test-suite/errors/pp_expressions_bad.i index 19d740942..454437f95 100644 --- a/Examples/test-suite/errors/pp_expressions_bad.i +++ b/Examples/test-suite/errors/pp_expressions_bad.i @@ -24,3 +24,20 @@ #if 0 #elif 8.8 #endif + +/* Missing whitespace after preproc directive */ +#if123 +#endif + +#if456e +#endif + +#if 0 +#warning This should not warn +#elif1 +#warning This should also not warn +#endif + +#if(1) +#warning Warning okay: #if(1) +#endif diff --git a/Examples/test-suite/errors/pp_expressions_bad.stderr b/Examples/test-suite/errors/pp_expressions_bad.stderr index 3e1112206..84104c6a8 100644 --- a/Examples/test-suite/errors/pp_expressions_bad.stderr +++ b/Examples/test-suite/errors/pp_expressions_bad.stderr @@ -12,3 +12,8 @@ pp_expressions_bad.i:21: Warning 202: Could not evaluate expression '2e3' pp_expressions_bad.i:21: Warning 202: Error: 'Floating point constant in preprocessor expression' pp_expressions_bad.i:25: Warning 202: Could not evaluate expression '8.8' pp_expressions_bad.i:25: Warning 202: Error: 'Floating point constant in preprocessor expression' +pp_expressions_bad.i:29: Error: Unknown SWIG preprocessor directive: if123 (if this is a block of target language code, delimit it with %{ and %}) +pp_expressions_bad.i:30: Error: Extraneous #endif. +pp_expressions_bad.i:32: Error: Unknown SWIG preprocessor directive: if456e (if this is a block of target language code, delimit it with %{ and %}) +pp_expressions_bad.i:33: Error: Extraneous #endif. +pp_expressions_bad.i:42: Warning 204: CPP #warning, "Warning okay: #if(1)". diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index df7458201..10018a787 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1454,7 +1454,7 @@ String *Preprocessor_parse(String *s) { break; case 41: /* Build up the name of the preprocessor directive */ - if ((isspace(c) || (!isalpha(c)))) { + if ((isspace(c) || (!isidchar(c)))) { Clear(value); Clear(comment); if (c == '\n') {