public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] macros: Add test cases for macro repetition separators
@ 2022-06-08 12:15 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:15 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0c7e16e1258b67ba8efa1b019802bee4d802d4a5

commit 0c7e16e1258b67ba8efa1b019802bee4d802d4a5
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Thu Mar 3 14:26:23 2022 +0100

    macros: Add test cases for macro repetition separators

Diff:
---
 gcc/testsuite/rust/compile/macro9.rs           | 17 +++++++++++++++++
 gcc/testsuite/rust/execute/torture/macros19.rs | 14 ++++++++++++++
 gcc/testsuite/rust/execute/torture/macros20.rs | 14 ++++++++++++++
 3 files changed, 45 insertions(+)

diff --git a/gcc/testsuite/rust/compile/macro9.rs b/gcc/testsuite/rust/compile/macro9.rs
new file mode 100644
index 00000000000..9a59089b1e4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macro9.rs
@@ -0,0 +1,17 @@
+macro_rules! add {
+    ($e:expr, $($es:expr),*) => {
+        $e + add!($($es),*)
+    };
+    ($e:expr) => {
+        $e
+    };
+}
+
+fn main() -> i32 {
+    let a = add!(15 2 9); // { dg-error "Failed to match any rule within macro" }
+    let b = add!(15);
+    let b = add!(15 14); // { dg-error "Failed to match any rule within macro" }
+    let b = add!(15, 14,); // { dg-error "Failed to match any rule within macro" }
+
+    0
+}
diff --git a/gcc/testsuite/rust/execute/torture/macros19.rs b/gcc/testsuite/rust/execute/torture/macros19.rs
new file mode 100644
index 00000000000..4732545410e
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/macros19.rs
@@ -0,0 +1,14 @@
+macro_rules! add {
+    ($e:expr, $($es:expr),*) => {
+        $e + add!($($es),*)
+    };
+    ($e:expr) => {
+        $e
+    };
+}
+
+fn main() -> i32 {
+    let a = add!(15, 2, 9); // 26
+
+    a - 26
+}
diff --git a/gcc/testsuite/rust/execute/torture/macros20.rs b/gcc/testsuite/rust/execute/torture/macros20.rs
new file mode 100644
index 00000000000..fc116d089c4
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/macros20.rs
@@ -0,0 +1,14 @@
+macro_rules! add {
+    ($e:expr big_tok $($es:expr) big_tok *) => {
+        $e + add!($($es) big_tok *)
+    };
+    ($e:expr) => {
+        $e
+    };
+}
+
+fn main() -> i32 {
+    let a = add!(15 big_tok 2 big_tok 9); // 26
+
+    a - 26
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:15 [gcc/devel/rust/master] macros: Add test cases for macro repetition separators Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).