Skip to content
Snippets Groups Projects
Commit e7c1948f authored by 0xn4utilus's avatar 0xn4utilus Committed by Arthur Cohen
Browse files

gccrs: Add variadic check on function params


gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
	Add variadic check on all parameters.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2850.rs: New test.

Signed-off-by: default avatar0xn4utilus <gyanendrabanjare8@gmail.com>
parent cdd76382
No related branches found
No related tags found
No related merge requests found
...@@ -132,10 +132,14 @@ ASTValidation::visit (AST::Function &function) ...@@ -132,10 +132,14 @@ ASTValidation::visit (AST::Function &function)
rust_error_at (function.get_locus (), "free function without a body"); rust_error_at (function.get_locus (), "free function without a body");
} }
if (function.is_variadic ()) auto &function_params = function.get_function_params ();
rust_error_at ( for (auto it = function_params.begin (); it != function_params.end (); it++)
function.get_function_params ().back ()->get_locus (), {
"only foreign or %<unsafe extern \"C\"%> functions may be C-variadic"); if (it->get ()->is_variadic ())
rust_error_at (it->get ()->get_locus (),
"only foreign or %<unsafe extern \"C\"%> functions may "
"be C-variadic");
}
AST::ContextualASTVisitor::visit (function); AST::ContextualASTVisitor::visit (function);
} }
......
fn myfun0(...,_:i32) {}
// { dg-error "only foreign or .unsafe extern \"C\". functions may be C-variadic" "" { target *-*-* } .-1 }
fn myfun1(a:i32,...,_:i32) {}
// { dg-error "only foreign or .unsafe extern \"C\". functions may be C-variadic" "" { target *-*-* } .-1 }
struct z {
x: f64,
y: f64,
}
impl z {
fn new(x: f64, ..., y: f64) -> z {
// { dg-error "only foreign or .unsafe extern \"C\". functions may be C-variadic" "" { target *-*-* } .-1 }
z { x: x, y: y }
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment