Don't accept some invalid preprocessor code

Whitespace or non-numeric characters are required after a preprocessor
directive that requires an expression.
This commit is contained in:
William S Fulton 2018-01-15 19:57:10 +00:00
commit 72964a1faf
4 changed files with 48 additions and 1 deletions

View file

@ -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

View file

@ -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)".