aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-12-30 22:23:58 +0100
committerJakub Jelinek <jakub@redhat.com>2021-12-30 22:23:58 +0100
commit5545d1edcbdb1701443f94dde7ec97c5ce3e1a6c (patch)
tree91e1d28262ea01451faebec09a45e3545010aa87 /gcc
parentbe674bdd11d5fa6b20d469e6d6f43c26da9e744f (diff)
downloadgcc-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 'gcc')
-rw-r--r--gcc/testsuite/c-c++-common/cpp/va-opt-9.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/cpp/va-opt-9.c b/gcc/testsuite/c-c++-common/cpp/va-opt-9.c
new file mode 100644
index 0000000..5f73ad0
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/va-opt-9.c
@@ -0,0 +1,20 @@
+/* PR preprocessor/89971 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" { target c } } */
+/* { dg-options "-std=c++20" { target c++ } } */
+
+int a, c;
+#define m1(...) a /##__VA_OPT__(b) c
+#define m2(...) a /##__VA_OPT__() c
+#define m3(...) a##__VA_OPT__()##b = 1
+#define m4(...) a##__VA_OPT__(b c d)##e = 2
+
+int
+foo (void)
+{
+ int d = m1();
+ int e = m2(1);
+ int m3(1 2 3);
+ int m4();
+ return d + e + ab + ae;
+}