[gcc r14-7476] gccrs: parser: macro: reject separator in `?` repetition
Arthur Cohen
cohenarthur@gcc.gnu.org
Tue Jan 16 17:37:12 GMT 2024
https://gcc.gnu.org/g:694063d84e47f57c99d4558e789932c31a7bf6dd
commit r14-7476-g694063d84e47f57c99d4558e789932c31a7bf6dd
Author: Sebastian Kirmayer <gnu@kirmayer.eu>
Date: Wed Apr 5 06:09:11 2023 +0200
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<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>
Diff:
---
gcc/rust/parse/rust-parse-impl.h | 10 ++++++++++
gcc/testsuite/rust/compile/macro-issue2092.rs | 4 ++++
2 files changed, 14 insertions(+)
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index e636252c255..6d20f480bb7 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -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
index 00000000000..ec207430168
--- /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),?) => {};
+}
More information about the Gcc-cvs
mailing list