Skip to content

Commit

Permalink
Add multiple check on variadics position
Browse files Browse the repository at this point in the history
Variadics are forbidden alone as well as non final position, this should
be checked during ast validation.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
	check for additional named argument as well as variadic argument's
	position.
	* checks/errors/rust-ast-validation.h: Add visit function prototype for
	external functions.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
  • Loading branch information
P-E-P committed Nov 9, 2023
1 parent 980730e commit 65226bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gcc/rust/checks/errors/rust-ast-validation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,23 @@ ASTValidation::visit (AST::ConstantItem &const_item)
AST::ContextualASTVisitor::visit (const_item);
}

void
ASTValidation::visit (AST::ExternalFunctionItem &item)
{
auto &params = item.get_function_params ();

if (params.size () == 1)
rust_error_at (
params[0].get_locus (),
"C-variadic function must be declared with at least one named argument");

for (auto it = params.begin (); it != params.end (); it++)
if (it->is_variadic () && it + 1 != params.end ())
rust_error_at (
it->get_locus (),
"%<...%> must be the last argument of a C-variadic function");

AST::ContextualASTVisitor::visit (item);
}

} // namespace Rust
1 change: 1 addition & 0 deletions gcc/rust/checks/errors/rust-ast-validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ASTValidation : public AST::ContextualASTVisitor
virtual void visit (AST::ConstantItem &const_item);
virtual void visit (AST::Lifetime &lifetime);
virtual void visit (AST::LoopLabel &label);
virtual void visit (AST::ExternalFunctionItem &item);
};

} // namespace Rust
Expand Down

0 comments on commit 65226bc

Please sign in to comment.