]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Ignore semicolon following a macro expansion in expression context
authorOwen Avery <powerboat9.gamer@gmail.com>
Tue, 13 Jun 2023 04:25:03 +0000 (00:25 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:49:31 +0000 (18:49 +0100)
gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc
(transcribe_expression): Skip trailing semicolon.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/expand/rust-macro-expand.cc
gcc/testsuite/rust/compile/macro-issue2273.rs [new file with mode: 0644]

index a4ad16a915c99ab088636ed4cd4ac45d6f9cc8a5..4ac6fdc3762e8967d17c5e7a66329cd7384e8bf3 100644 (file)
@@ -911,6 +911,15 @@ transcribe_expression (Parser<MacroInvocLexer> &parser)
   if (expr == nullptr)
     return AST::Fragment::create_error ();
 
+  // FIXME: make this an error for some edititons
+  if (parser.peek_current_token ()->get_id () == SEMICOLON)
+    {
+      rust_warning_at (
+       parser.peek_current_token ()->get_locus (), 0,
+       "trailing semicolon in macro used in expression context");
+      parser.skip_token ();
+    }
+
   auto end = lexer.get_offs ();
 
   return AST::Fragment ({std::move (expr)}, lexer.get_token_slice (start, end));
diff --git a/gcc/testsuite/rust/compile/macro-issue2273.rs b/gcc/testsuite/rust/compile/macro-issue2273.rs
new file mode 100644 (file)
index 0000000..ee3dd1f
--- /dev/null
@@ -0,0 +1,7 @@
+macro_rules! mac {
+    () => {();} // { dg-warning "trailing semicolon" }
+}
+
+pub fn foo() {
+    mac!()
+}