]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: parser: macro: reject separator in `?` repetition
authorSebastian Kirmayer <gnu@kirmayer.eu>
Wed, 5 Apr 2023 04:09:11 +0000 (06:09 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:34:08 +0000 (18:34 +0100)
A matcher like $(a),? is no longer accepted.

Fixes #2092.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser<ManagedTokenSource>::parse_macro_match_repetition):
reject separator in `?` repetition

gcc/testsuite/ChangeLog:

* rust/compile/macro-issue2092.rs: New test.

Signed-off-by: Sebastian Kirmayer <gnu@kirmayer.eu>
gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/macro-issue2092.rs [new file with mode: 0644]

index e636252c2558c4349fa0248b40628b9afb67e8a3..6d20f480bb7ba1ba78f4ee1b531fb571ebd725cc 100644 (file)
@@ -2261,6 +2261,16 @@ Parser<ManagedTokenSource>::parse_macro_match_repetition ()
     case QUESTION_MARK:
       op = AST::MacroMatchRepetition::ZERO_OR_ONE;
       lexer.skip_token ();
+
+      if (separator != nullptr)
+       {
+         add_error (
+           Error (separator->get_locus (),
+                  "the %<?%> macro repetition operator does not take a "
+                  "separator"));
+         separator = nullptr;
+       }
+
       break;
     default:
       add_error (
diff --git a/gcc/testsuite/rust/compile/macro-issue2092.rs b/gcc/testsuite/rust/compile/macro-issue2092.rs
new file mode 100644 (file)
index 0000000..ec20743
--- /dev/null
@@ -0,0 +1,4 @@
+macro_rules! foo {
+    // { dg-error "does not take a separator" "#2092" { target *-*-*} .+1 }
+    ($(a),?) => {};
+}