From: Sebastian Kirmayer Date: Wed, 5 Apr 2023 04:09:11 +0000 (+0200) Subject: gccrs: parser: macro: reject separator in `?` repetition X-Git-Tag: basepoints/gcc-15~2663 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=694063d84e47f57c99d4558e789932c31a7bf6dd;p=thirdparty%2Fgcc.git 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 --- 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),?) => {}; +}