mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Function pointers are now compile time constants.
const enum cannot be set to function pointer unless it's a lambda #2282.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
import std;
|
||||
fn int foo() => 0;
|
||||
alias FooFn = fn int();
|
||||
|
||||
enum Foo : (FooFn f)
|
||||
{
|
||||
FOO = fn int() => 0, // allowed
|
||||
BAR = &foo, // allowed
|
||||
}
|
||||
|
||||
enum Bar : const FooFn
|
||||
{
|
||||
FOO = fn int() => 0, // allowed
|
||||
BAR = &foo, // Error: Expected an constant enum value.
|
||||
}
|
||||
fn int main()
|
||||
{
|
||||
Bar b = FOO;
|
||||
Bar b2 = BAR;
|
||||
var $c = &foo == &foo;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
%b = alloca ptr, align 8
|
||||
%b2 = alloca ptr, align 8
|
||||
store ptr @"test.$global$lambda2", ptr %b, align 8
|
||||
store ptr @test.foo, ptr %b2, align 8
|
||||
ret i32 0
|
||||
}
|
||||
Reference in New Issue
Block a user