From 50f66bdbdbc3a1a6c6d09ecc579d51d7dfd76561 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Tue, 22 Nov 2005 18:24:23 -0500 Subject: [PATCH] [PATCH] shut up the bogus warnings about the #if'ed-out section Standard requires much more relaxed treatment of the groups that are #if...'ed out. We used to generate bogus warnings there; fixed, testcase added. Signed-off-by: Al Viro Signed-off-by: Linus Torvalds --- pre-process.c | 13 +++++++++---- validation/preprocessor16.c | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 validation/preprocessor16.c diff --git a/pre-process.c b/pre-process.c index 63eb73ca..bd7bcd0a 100644 --- a/pre-process.c +++ b/pre-process.c @@ -1061,12 +1061,13 @@ static int do_handle_define(struct stream *stream, struct token **line, struct t struct symbol *sym; struct ident *name; + if (false_nesting) + return free_preprocessor_line(token); + if (token_type(left) != TOKEN_IDENT) { sparse_error(token->pos, "expected identifier to 'define'"); return 0; } - if (false_nesting) - return free_preprocessor_line(token); if (stream->constant == CONSTANT_FILE_MAYBE) MARK_STREAM_NONCONST(token->pos); @@ -1133,12 +1134,13 @@ static int handle_undef(struct stream *stream, struct token **line, struct token struct token *left = token->next; struct symbol **sym; + if (false_nesting) + return free_preprocessor_line(token); + if (token_type(left) != TOKEN_IDENT) { sparse_error(token->pos, "expected identifier to 'undef'"); return 0; } - if (false_nesting) - return free_preprocessor_line(token); if (stream->constant == CONSTANT_FILE_MAYBE) MARK_STREAM_NONCONST(token->pos); @@ -1602,6 +1604,9 @@ static void handle_preprocessor_line(struct stream *stream, struct token **line, return; } + if (false_nesting) + return; + sparse_error(token->pos, "unrecognized preprocessor line '%s'", show_token_sequence(token)); } diff --git a/validation/preprocessor16.c b/validation/preprocessor16.c new file mode 100644 index 00000000..caba3c85 --- /dev/null +++ b/validation/preprocessor16.c @@ -0,0 +1,19 @@ +#if 0 +From 6.10.1(5): + Each directive's condition is checked in order. If it evaluates + to false (zero), the group it controls is skipped: directives are + processed only through the name that determines the directive in + order to keep track of the level of nested conditionals; the rest + of the directives' preprocessing tokens are ignores, >>as are the + other preprocessing tokens in the group<<. + +In other words, bogus arguments of directives are silently ignored and +so are text lines and non-directives (# ). We *do* +complain about the things like double #else or #elif after #else, since +they hit before we get to the level of groups. + +#define 1 +#undef 1 +#bullshit + +#endif -- 2.11.4.GIT