diff options
author | Jakub Jelinek <jakub@redhat.com> | 2021-12-30 22:23:58 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2021-12-30 22:23:58 +0100 |
commit | 5545d1edcbdb1701443f94dde7ec97c5ce3e1a6c (patch) | |
tree | 91e1d28262ea01451faebec09a45e3545010aa87 /libcpp/macro.c | |
parent | be674bdd11d5fa6b20d469e6d6f43c26da9e744f (diff) | |
download | gcc-5545d1edcbdb1701443f94dde7ec97c5ce3e1a6c.zip gcc-5545d1edcbdb1701443f94dde7ec97c5ce3e1a6c.tar.gz gcc-5545d1edcbdb1701443f94dde7ec97c5ce3e1a6c.tar.bz2 |
libcpp: Fix up ##__VA_OPT__ handling [PR89971]
In the following testcase we incorrectly error about pasting / token
with padding token (which is a result of __VA_OPT__); instead we should
like e.g. for ##arg where arg is empty macro argument clear PASTE_LEFT
flag of the previous token if __VA_OPT__ doesn't add any real tokens
(which can happen either because the macro doesn't have any tokens
passed to ... (i.e. __VA_ARGS__ expands to empty) or when __VA_OPT__
doesn't have any tokens in between ()s).
2021-12-30 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/89971
libcpp/
* macro.c (replace_args): For ##__VA_OPT__, if __VA_OPT__ expands
to no tokens at all, drop PASTE_LEFT flag from the previous token.
gcc/testsuite/
* c-c++-common/cpp/va-opt-9.c: New test.
Diffstat (limited to 'libcpp/macro.c')
-rw-r--r-- | libcpp/macro.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/libcpp/macro.c b/libcpp/macro.c index 6269c15..369383f 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -2094,8 +2094,14 @@ replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, tokens_buff_add_token (buff, virt_locs, t, t->src_loc, t->src_loc, NULL, 0); + continue; } - else if (src->flags & PASTE_LEFT) + if (start && paste_flag == start && (*start)->flags & PASTE_LEFT) + /* If __VA_OPT__ expands to nothing (either because __VA_ARGS__ + is empty or because it is __VA_OPT__() ), drop PASTE_LEFT + flag from previous token. */ + copy_paste_flag (pfile, start, &pfile->avoid_paste); + if (src->flags & PASTE_LEFT) { /* Don't avoid paste after all. */ while (paste_flag && paste_flag != start |