diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-31 00:04:38 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-31 00:04:38 +0900 |
| commit | 76b0c6bb6bbc339789943ada1f79ec1eba52239f (patch) | |
| tree | 083f3a6a8f6bb8275b5c6f9bb6a4c12d22b175ee | |
| parent | 75193c09f1dfcb3c7c726e5492f973a43402e270 (diff) | |
| download | ducc-76b0c6bb6bbc339789943ada1f79ec1eba52239f.tar.gz ducc-76b0c6bb6bbc339789943ada1f79ec1eba52239f.tar.zst ducc-76b0c6bb6bbc339789943ada1f79ec1eba52239f.zip | |
fix: #else/#endif with trailing whitespace or comment
| -rw-r--r-- | src/preprocess.c | 2 | ||||
| -rw-r--r-- | tests/109.sh | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/preprocess.c b/src/preprocess.c index 6923367..c2dd3a8 100644 --- a/src/preprocess.c +++ b/src/preprocess.c @@ -1084,6 +1084,7 @@ static BOOL preprocess_elif_groups_opt(Preprocessor* pp, BOOL did_include) { // '#' 'else' group? static void preprocess_else_group(Preprocessor* pp, BOOL did_include) { skip_pp_token(pp, TokenKind_pp_directive_else); + skip_whitespaces(pp); expect_pp_token(pp, TokenKind_newline); include_conditionally(pp, GroupDelimiterKind_after_else_directive, !did_include); @@ -1093,6 +1094,7 @@ static void preprocess_else_group(Preprocessor* pp, BOOL did_include) { // '#' 'endif' new-line static void preprocess_endif_directive(Preprocessor* pp) { skip_pp_token(pp, TokenKind_pp_directive_endif); + skip_whitespaces(pp); expect_pp_token(pp, TokenKind_newline); } diff --git a/tests/109.sh b/tests/109.sh new file mode 100644 index 0000000..40b2c82 --- /dev/null +++ b/tests/109.sh @@ -0,0 +1,10 @@ +cat <<'EOF' > expected +EOF + +test_diff <<'EOF' +#if 1 // a +#else // b +#endif // c + +int main() {} +EOF |
