diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-03-12 08:07:05 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-03-15 23:52:18 +0100 |
| commit | 5c2338f694cda83c28a96e198f8de13bc1cde8b4 (patch) | |
| tree | e57287cb59c7beb2c330d41e65e2f3158a433714 /validation/preprocessor | |
| parent | 0e3729b3edb8d3f384c907127f664e38bd7adab8 (diff) | |
| download | sparse-dev-5c2338f694cda83c28a96e198f8de13bc1cde8b4.tar.gz | |
cpp: silently allow conditional directives within a macro
The presence of preprocessor directives within the arguments
of a macro invocation is Undefined Behaviour [6.10.3p11].
However, conditional directives are harmless here and are
useful (and commonly used in the kernel).
So, relax the warning by restricting it to non-conditional
directives.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/preprocessor')
| -rw-r--r-- | validation/preprocessor/directive-within-macro.c | 40 | ||||
| -rw-r--r-- | validation/preprocessor/preprocessor22.c | 2 |
2 files changed, 41 insertions, 1 deletions
diff --git a/validation/preprocessor/directive-within-macro.c b/validation/preprocessor/directive-within-macro.c new file mode 100644 index 00000000..5269d4a7 --- /dev/null +++ b/validation/preprocessor/directive-within-macro.c @@ -0,0 +1,40 @@ +#define f(x) x + +f(1 +#if 1 // OK + a +#elif 2 // OK + b +#else // OK + c +#endif // OK +#ifdef f // OK + d +#endif // OK +#ifndef f // OK + e +#endif // OK + 3) + +f(1 +#define x y // KO + 3) + +/* + * check-name: directive-within-macro + * check-command: sparse -E $file + * + * check-output-start + +1 +a +d +3 +1 +3 + * check-output-end + * + * check-error-start +preprocessor/directive-within-macro.c:20:1: warning: directive in macro's argument list + * check-error-end + */ diff --git a/validation/preprocessor/preprocessor22.c b/validation/preprocessor/preprocessor22.c index 277334c6..11f625c0 100644 --- a/validation/preprocessor/preprocessor22.c +++ b/validation/preprocessor/preprocessor22.c @@ -17,7 +17,7 @@ define_struct(a, { * check-description: Directives are not allowed within a macro argument list, * although cpp deals with it to treat macro more like C functions. * - * check-command: sparse -E $file + * check-command: sparse -pedantic -E $file * * check-error-start preprocessor/preprocessor22.c:6:1: warning: directive in macro's argument list |
