mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- Support int $foo... arguments. #2601
This commit is contained in:
6
test/test_suite/functions/const_vaarg_untyped.c3
Normal file
6
test/test_suite/functions/const_vaarg_untyped.c3
Normal file
@@ -0,0 +1,6 @@
|
||||
macro foo2(int $a, $i...) // #error: Untyped constant vaargs are not supported. Use raw macro vaargs instead
|
||||
{
|
||||
$foreach $ab : $i:
|
||||
$echo $ab;
|
||||
$endforeach
|
||||
}
|
||||
4
test/test_suite/functions/expr_vaarg_untyped.c3
Normal file
4
test/test_suite/functions/expr_vaarg_untyped.c3
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
macro @foo3(int $a, int #i...) // #error: Expression parameters may not be vaargs, use untyped macro vaargs '...' instead
|
||||
{
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// #target: macos-x64
|
||||
fn void test1()
|
||||
{
|
||||
int x;
|
||||
|
||||
35
test/test_suite/functions/splat_const_vaarg.c3t
Normal file
35
test/test_suite/functions/splat_const_vaarg.c3t
Normal file
@@ -0,0 +1,35 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
macro foo(int $a, int... $i)
|
||||
{
|
||||
$foreach $ab : $i:
|
||||
{
|
||||
int x = $ab;
|
||||
}
|
||||
$endforeach
|
||||
}
|
||||
fn int main()
|
||||
{
|
||||
foo(3, 1, 2);
|
||||
int[3] $x = { 1, 2, 3 };
|
||||
foo(3, ...$x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
%x = alloca i32, align 4
|
||||
%x1 = alloca i32, align 4
|
||||
%x2 = alloca i32, align 4
|
||||
%x3 = alloca i32, align 4
|
||||
%x4 = alloca i32, align 4
|
||||
store i32 1, ptr %x, align 4
|
||||
store i32 2, ptr %x1, align 4
|
||||
store i32 1, ptr %x2, align 4
|
||||
store i32 2, ptr %x3, align 4
|
||||
store i32 3, ptr %x4, align 4
|
||||
ret i32 0
|
||||
}
|
||||
17
test/test_suite/functions/splat_const_vaarg_fail.c3
Normal file
17
test/test_suite/functions/splat_const_vaarg_fail.c3
Normal file
@@ -0,0 +1,17 @@
|
||||
module test;
|
||||
|
||||
macro foo(int $a, int... $i)
|
||||
{
|
||||
$foreach $ab : $i:
|
||||
$echo $ab;
|
||||
$endforeach
|
||||
}
|
||||
fn int main()
|
||||
{
|
||||
int a;
|
||||
foo(3, 1, 2, a); // #error: All vaargs must be contant values
|
||||
int[3] x = { 1, 2, 3 };
|
||||
foo(3, ...x); // #error: The splat must be a compile time value
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user