From 694063d84e47f57c99d4558e789932c31a7bf6dd Mon Sep 17 00:00:00 2001 From: Sebastian Kirmayer Date: Wed, 5 Apr 2023 06:09:11 +0200 Subject: [PATCH] gccrs: parser: macro: reject separator in `?` repetition A matcher like $(a),? is no longer accepted. Fixes #2092. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_macro_match_repetition): reject separator in `?` repetition gcc/testsuite/ChangeLog: * rust/compile/macro-issue2092.rs: New test. Signed-off-by: Sebastian Kirmayer --- gcc/rust/parse/rust-parse-impl.h | 10 ++++++++++ gcc/testsuite/rust/compile/macro-issue2092.rs | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 gcc/testsuite/rust/compile/macro-issue2092.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index e636252c2558..6d20f480bb7b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2261,6 +2261,16 @@ Parser::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 index 000000000000..ec207430168d --- /dev/null +++ b/gcc/testsuite/rust/compile/macro-issue2092.rs @@ -0,0 +1,4 @@ +macro_rules! foo { + // { dg-error "does not take a separator" "#2092" { target *-*-*} .+1 } + ($(a),?) => {}; +} -- 2.47.2