From eb80776988a020db7eda0a81dd44fac7e33a4719 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 14 Feb 2026 01:37:53 +0100 Subject: [PATCH] More fixes for typedef @constinit change --- lib/std/core/builtin.c3 | 2 +- lib/std/core/logging.c3 | 32 ++--- lib/std/core/sanitizer/tsan.c3 | 20 +-- lib/std/core/string.c3 | 4 +- lib/std/crypto/ed25519.c3 | 4 +- lib/std/encoding/base32.c3 | 2 +- lib/std/libc/libc.c3 | 2 +- lib/std/libc/os/posix.c3 | 118 +++++++++--------- lib/std/net/os/common.c3 | 28 ++--- lib/std/net/os/darwin.c3 | 86 ++++++------- lib/std/net/socket_private.c3 | 2 +- lib/std/time/time.c3 | 28 ++--- src/compiler/sema_casts.c | 13 +- src/compiler/sema_decls.c | 10 +- src/compiler/sema_expr.c | 12 ++ src/compiler/sema_internal.h | 1 - src/main.c | 3 +- .../test_suite/distinct/distinct_function.c3t | 4 +- .../distinct/distinct_function_call.c3 | 2 +- test/test_suite/distinct/distinct_sub.c3t | 2 +- 20 files changed, 199 insertions(+), 176 deletions(-) diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index 92b2ac263..ef4dd38f7 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -26,7 +26,7 @@ macro foo(a, #b = EMPTY_MACRO_SLOT) *> const EmptySlot EMPTY_MACRO_SLOT @builtin @deprecated("Use `#arg = ...` instead.") = null; -typedef EmptySlot = void*; +typedef EmptySlot @constinit = void*; macro bool @is_empty_macro_slot(#arg) @const @builtin @deprecated("Use `#arg = ...` to define an optional macro slot, and `$defined(#arg)` to detect whether the argument is set.") => $typeof(#arg) == EmptySlot; diff --git a/lib/std/core/logging.c3 b/lib/std/core/logging.c3 index 536895996..a297732d1 100644 --- a/lib/std/core/logging.c3 +++ b/lib/std/core/logging.c3 @@ -6,22 +6,22 @@ const FULL_LOG = env::COMPILER_SAFE_MODE || $feature(FULL_LOG); typedef LogCategory = inline char; typedef LogTag = char[12]; -const LogCategory CATEGORY_APPLICATION = 0; -const LogCategory CATEGORY_SYSTEM = 1; -const LogCategory CATEGORY_KERNEL = 2; -const LogCategory CATEGORY_AUDIO = 3; -const LogCategory CATEGORY_VIDEO = 4; -const LogCategory CATEGORY_RENDER = 5; -const LogCategory CATEGORY_INPUT = 6; -const LogCategory CATEGORY_NETWORK = 7; -const LogCategory CATEGORY_SOCKET = 8; -const LogCategory CATEGORY_SECURITY = 9; -const LogCategory CATEGORY_TEST = 10; -const LogCategory CATEGORY_ERROR = 11; -const LogCategory CATEGORY_ASSERT = 12; -const LogCategory CATEGORY_CRASH = 13; -const LogCategory CATEGORY_STATS = 14; -const LogCategory CATEGORY_CUSTOM_START = 100; +const LogCategory CATEGORY_APPLICATION = (LogCategory)0; +const LogCategory CATEGORY_SYSTEM = (LogCategory)1; +const LogCategory CATEGORY_KERNEL = (LogCategory)2; +const LogCategory CATEGORY_AUDIO = (LogCategory)3; +const LogCategory CATEGORY_VIDEO = (LogCategory)4; +const LogCategory CATEGORY_RENDER = (LogCategory)5; +const LogCategory CATEGORY_INPUT = (LogCategory)6; +const LogCategory CATEGORY_NETWORK = (LogCategory)7; +const LogCategory CATEGORY_SOCKET = (LogCategory)8; +const LogCategory CATEGORY_SECURITY = (LogCategory)9; +const LogCategory CATEGORY_TEST = (LogCategory)10; +const LogCategory CATEGORY_ERROR = (LogCategory)11; +const LogCategory CATEGORY_ASSERT = (LogCategory)12; +const LogCategory CATEGORY_CRASH = (LogCategory)13; +const LogCategory CATEGORY_STATS = (LogCategory)14; +const LogCategory CATEGORY_CUSTOM_START = (LogCategory)100; tlocal LogCategory default_category = CATEGORY_APPLICATION; tlocal LogTag current_tag; diff --git a/lib/std/core/sanitizer/tsan.c3 b/lib/std/core/sanitizer/tsan.c3 index 90dfe254c..960de0025 100644 --- a/lib/std/core/sanitizer/tsan.c3 +++ b/lib/std/core/sanitizer/tsan.c3 @@ -2,16 +2,16 @@ module std::core::sanitizer::tsan; typedef MutexFlags = inline CUInt; -const MutexFlags MUTEX_LINKER_INIT = 1 << 0; -const MutexFlags MUTEX_WRITE_REENTRANT = 1 << 1; -const MutexFlags MUTEX_READ_REENTRANT = 1 << 2; -const MutexFlags MUTEX_NOT_STATIC = 1 << 8; -const MutexFlags MUTEX_READ_LOCK = 1 << 3; -const MutexFlags MUTEX_TRY_LOCK = 1 << 4; -const MutexFlags MUTEX_TRY_LOCK_FAILED = 1 << 5; -const MutexFlags MUTEX_RECURSIVE_LOCK = 1 << 6; -const MutexFlags MUTEX_RECURSIVE_UNLOCK = 1 << 7; -const MutexFlags MUTEX_TRY_READ_LOCK = MUTEX_READ_LOCK | MUTEX_TRY_LOCK; +const MutexFlags MUTEX_LINKER_INIT = (MutexFlags)1 << 0; +const MutexFlags MUTEX_WRITE_REENTRANT = (MutexFlags)1 << 1; +const MutexFlags MUTEX_READ_REENTRANT = (MutexFlags)1 << 2; +const MutexFlags MUTEX_NOT_STATIC = (MutexFlags)1 << 8; +const MutexFlags MUTEX_READ_LOCK = (MutexFlags)1 << 3; +const MutexFlags MUTEX_TRY_LOCK = (MutexFlags)1 << 4; +const MutexFlags MUTEX_TRY_LOCK_FAILED = (MutexFlags)1 << 5; +const MutexFlags MUTEX_RECURSIVE_LOCK = (MutexFlags)1 << 6; +const MutexFlags MUTEX_RECURSIVE_UNLOCK = (MutexFlags)1 << 7; +const MutexFlags MUTEX_TRY_READ_LOCK = MUTEX_READ_LOCK | MUTEX_TRY_LOCK; const MutexFlags MUTEX_TRY_READ_LOCK_FAILED = MUTEX_TRY_READ_LOCK | MUTEX_TRY_LOCK_FAILED; macro void mutex_create(void* addr, MutexFlags flags) { $if env::THREAD_SANITIZER: __tsan_mutex_create(addr, flags); $endif } diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index 32495c79c..c3b712ec5 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -4,13 +4,13 @@ import std::core::mem::allocator; -typedef String @if(!$defined(String)) = inline char[]; +typedef String @constinit @if(!$defined(String)) = inline char[]; <* ZString is a pointer to a zero terminated array of chars. Use ZString when you need to interop with C zero terminated strings. *> -typedef ZString = inline char*; +typedef ZString @constinit = inline char*; <* WString is a pointer to a zero terminated array of Char16. diff --git a/lib/std/crypto/ed25519.c3 b/lib/std/crypto/ed25519.c3 index 2ad92ee8d..d607ceff6 100644 --- a/lib/std/crypto/ed25519.c3 +++ b/lib/std/crypto/ed25519.c3 @@ -332,7 +332,7 @@ fn Projection Projection.mul(&s, char[] n) @operator(*) module std::crypto::ed25519 @private; -typedef F25519Int = inline char[32]; +typedef F25519Int @constinit = inline char[32]; const F25519Int ZERO = {}; const F25519Int ONE = {[0] = 1}; @@ -601,7 +601,7 @@ fn F25519Int F25519Int.sqrt(&s) module std::crypto::ed25519 @private; import std::math; -typedef FBaseInt = inline char[32]; +typedef FBaseInt @constinit = inline char[32]; // Order of the field : 2^252+0x14def9dea2f79cd65812631a5cf5d3ed const FBaseInt ORDER = x"edd3f55c1a631258 d69cf7a2def9de14 0000000000000000 0000000000000010"; diff --git a/lib/std/encoding/base32.c3 b/lib/std/encoding/base32.c3 index 91aa6617b..29dd91867 100644 --- a/lib/std/encoding/base32.c3 +++ b/lib/std/encoding/base32.c3 @@ -242,7 +242,7 @@ const char INVALID @private = 0xff; const int STD_PADDING = '='; const int NO_PADDING = -1; -typedef Alphabet = char[32]; +typedef Alphabet @constinit = char[32]; // Standard base32 Alphabet const Alphabet STD_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; // Extended Hex Alphabet diff --git a/lib/std/libc/libc.c3 b/lib/std/libc/libc.c3 index c7f659fdd..3c0f41927 100644 --- a/lib/std/libc/libc.c3 +++ b/lib/std/libc/libc.c3 @@ -49,7 +49,7 @@ fn void errno_set(Errno e) os::errno_set((int)e); } -typedef Errno = inline CInt; +typedef Errno @constinit = inline CInt; alias TerminateFunction = fn void(); alias CompareFunction = fn int(void*, void*); alias JmpBuf = uptr[$$JMP_BUF_SIZE]; diff --git a/lib/std/libc/os/posix.c3 b/lib/std/libc/os/posix.c3 index 83f7b8328..5f17f234a 100644 --- a/lib/std/libc/os/posix.c3 +++ b/lib/std/libc/os/posix.c3 @@ -312,65 +312,65 @@ struct Termios Speed c_ospeed; } -const Tcactions TCOOFF @deprecated = 0; -const Tcactions TCOON @deprecated = 1; -const Tcactions TCIOFF @deprecated = 2; -const Tcactions TCION @deprecated = 3; -const Tcactions TCIFLUSH @deprecated = 0; -const Tcactions TCOFLUSH @deprecated = 1; -const Tcactions TCIOFLUSH @deprecated = 2; -const Tcactions TCSANOW @deprecated = 0; -const Tcactions TCSADRAIN @deprecated = 1; -const Tcactions TCSAFLUSH @deprecated = 2; -const Speed B0 @deprecated = 0o0000000; -const Speed B50 @deprecated = 0o0000001; -const Speed B75 @deprecated = 0o0000002; -const Speed B110 @deprecated = 0o0000003; -const Speed B134 @deprecated = 0o0000004; -const Speed B150 @deprecated = 0o0000005; -const Speed B200 @deprecated = 0o0000006; -const Speed B300 @deprecated = 0o0000007; -const Speed B600 @deprecated = 0o0000010; -const Speed B1200 @deprecated = 0o0000011; -const Speed B1800 @deprecated = 0o0000012; -const Speed B2400 @deprecated = 0o0000013; -const Speed B4800 @deprecated = 0o0000014; -const Speed B9600 @deprecated = 0o0000015; -const Speed B19200 @deprecated = 0o0000016; -const Speed B38400 @deprecated = 0o0000017; -const Speed B57600 @deprecated = 0o0010001; -const Speed B115200 @deprecated = 0o0010002; -const Speed B230400 @deprecated = 0o0010003; -const Speed B460800 @deprecated = 0o0010004; -const Speed B500000 @deprecated = 0o0010005; -const Speed B576000 @deprecated = 0o0010006; -const Speed B921600 @deprecated = 0o0010007; -const Speed B1000000 @deprecated = 0o0010010; -const Speed B1152000 @deprecated = 0o0010011; -const Speed B1500000 @deprecated = 0o0010012; -const Speed B2000000 @deprecated = 0o0010013; -const Speed B2500000 @deprecated = 0o0010014; -const Speed B3000000 @deprecated = 0o0010015; -const Speed B3500000 @deprecated = 0o0010016; -const Speed B4000000 @deprecated = 0o0010017; -const Speed MAX_BAUD @deprecated = B4000000; -const Cc VINTR @deprecated = 0; -const Cc VQUIT @deprecated = 1; -const Cc VERASE @deprecated = 2; -const Cc VKILL @deprecated = 3; -const Cc VEOF @deprecated = 4; -const Cc VTIME @deprecated = 5; -const Cc VMIN @deprecated = 6; -const Cc VSWTC @deprecated = 7; -const Cc VSTART @deprecated = 8; -const Cc VSTOP @deprecated = 9; -const Cc VSUSP @deprecated = 10; -const Cc VEOL @deprecated = 11; -const Cc VREPRINT @deprecated = 12; -const Cc VDISCARD @deprecated = 13; -const Cc VWERASE @deprecated = 14; -const Cc VLNEXT @deprecated = 15; -const Cc VEOL2 @deprecated = 16; +const Tcactions TCOOFF @deprecated = (Tcactions)0; +const Tcactions TCOON @deprecated = (Tcactions)1; +const Tcactions TCIOFF @deprecated = (Tcactions)2; +const Tcactions TCION @deprecated = (Tcactions)3; +const Tcactions TCIFLUSH @deprecated = (Tcactions)0; +const Tcactions TCOFLUSH @deprecated = (Tcactions)1; +const Tcactions TCIOFLUSH @deprecated = (Tcactions)2; +const Tcactions TCSANOW @deprecated = (Tcactions)0; +const Tcactions TCSADRAIN @deprecated = (Tcactions)1; +const Tcactions TCSAFLUSH @deprecated = (Tcactions)2; +const Speed B0 @deprecated = (Speed)0o0000000; +const Speed B50 @deprecated = (Speed)0o0000001; +const Speed B75 @deprecated = (Speed)0o0000002; +const Speed B110 @deprecated = (Speed)0o0000003; +const Speed B134 @deprecated = (Speed)0o0000004; +const Speed B150 @deprecated = (Speed)0o0000005; +const Speed B200 @deprecated = (Speed)0o0000006; +const Speed B300 @deprecated = (Speed)0o0000007; +const Speed B600 @deprecated = (Speed)0o0000010; +const Speed B1200 @deprecated = (Speed)0o0000011; +const Speed B1800 @deprecated = (Speed)0o0000012; +const Speed B2400 @deprecated = (Speed)0o0000013; +const Speed B4800 @deprecated = (Speed)0o0000014; +const Speed B9600 @deprecated = (Speed)0o0000015; +const Speed B19200 @deprecated = (Speed)0o0000016; +const Speed B38400 @deprecated = (Speed)0o0000017; +const Speed B57600 @deprecated = (Speed)0o0010001; +const Speed B115200 @deprecated = (Speed)0o0010002; +const Speed B230400 @deprecated = (Speed)0o0010003; +const Speed B460800 @deprecated = (Speed)0o0010004; +const Speed B500000 @deprecated = (Speed)0o0010005; +const Speed B576000 @deprecated = (Speed)0o0010006; +const Speed B921600 @deprecated = (Speed)0o0010007; +const Speed B1000000 @deprecated = (Speed)0o0010010; +const Speed B1152000 @deprecated = (Speed)0o0010011; +const Speed B1500000 @deprecated = (Speed)0o0010012; +const Speed B2000000 @deprecated = (Speed)0o0010013; +const Speed B2500000 @deprecated = (Speed)0o0010014; +const Speed B3000000 @deprecated = (Speed)0o0010015; +const Speed B3500000 @deprecated = (Speed)0o0010016; +const Speed B4000000 @deprecated = (Speed)0o0010017; +const Speed MAX_BAUD @deprecated = (Speed)0o0010017; +const Cc VINTR @deprecated = (Cc)0; +const Cc VQUIT @deprecated = (Cc)1; +const Cc VERASE @deprecated = (Cc)2; +const Cc VKILL @deprecated = (Cc)3; +const Cc VEOF @deprecated = (Cc)4; +const Cc VTIME @deprecated = (Cc)5; +const Cc VMIN @deprecated = (Cc)6; +const Cc VSWTC @deprecated = (Cc)7; +const Cc VSTART @deprecated = (Cc)8; +const Cc VSTOP @deprecated = (Cc)9; +const Cc VSUSP @deprecated = (Cc)10; +const Cc VEOL @deprecated = (Cc)11; +const Cc VREPRINT @deprecated = (Cc)12; +const Cc VDISCARD @deprecated = (Cc)13; +const Cc VWERASE @deprecated = (Cc)14; +const Cc VLNEXT @deprecated = (Cc)15; +const Cc VEOL2 @deprecated = (Cc)16; const Tc_lflags ISIG @deprecated = {.isig}; const Tc_lflags ICANON @deprecated = {.icanon}; const Tc_lflags ECHO @deprecated = {.echo}; diff --git a/lib/std/net/os/common.c3 b/lib/std/net/os/common.c3 index f5557e80d..27d32d04d 100644 --- a/lib/std/net/os/common.c3 +++ b/lib/std/net/os/common.c3 @@ -34,22 +34,22 @@ struct AddrInfo const PLATFORM_O_NONBLOCK @if(!$defined(PLATFORM_O_NONBLOCK)) = 0; -const AISockType SOCK_STREAM = 1; // Stream -const AISockType SOCK_DGRAM = 2; // Datagram -const AISockType SOCK_RAW = 3; // Raw -const AISockType SOCK_RDM = 4; // Reliably delivered -const AISockType SOCK_SEQPACKET = 5; // Sequential packet +const AISockType SOCK_STREAM = (AISockType)1; // Stream +const AISockType SOCK_DGRAM = (AISockType)2; // Datagram +const AISockType SOCK_RAW = (AISockType)3; // Raw +const AISockType SOCK_RDM = (AISockType)4; // Reliably delivered +const AISockType SOCK_SEQPACKET = (AISockType)5; // Sequential packet -const AIFlags AI_PASSIVE = 0x1; -const AIFlags AI_CANONNAME = 0x2; -const AIFlags AI_NUMERICHOST = 0x4; +const AIFlags AI_PASSIVE = (AIFlags)0x1; +const AIFlags AI_CANONNAME = (AIFlags)0x2; +const AIFlags AI_NUMERICHOST = (AIFlags)0x4; -const AIFamily AF_UNSPEC = 0; -const AIFamily AF_UNIX = 1; -const AIFamily AF_INET = 2; -const AIFamily AF_INET6 = PLATFORM_AF_INET6; -const AIFamily AF_IPX = PLATFORM_AF_IPX; -const AIFamily AF_APPLETALK = PLATFORM_AF_APPLETALK; +const AIFamily AF_UNSPEC = (AIFamily)0; +const AIFamily AF_UNIX = (AIFamily)1; +const AIFamily AF_INET = (AIFamily)2; +const AIFamily AF_INET6 = (AIFamily)PLATFORM_AF_INET6; +const AIFamily AF_IPX = (AIFamily)PLATFORM_AF_IPX; +const AIFamily AF_APPLETALK = (AIFamily)PLATFORM_AF_APPLETALK; const O_NONBLOCK = PLATFORM_O_NONBLOCK; diff --git a/lib/std/net/os/darwin.c3 b/lib/std/net/os/darwin.c3 index 3ef758836..2a84d0003 100644 --- a/lib/std/net/os/darwin.c3 +++ b/lib/std/net/os/darwin.c3 @@ -1,50 +1,50 @@ module std::net::os @if(env::DARWIN); import libc; -const AIFlags AI_NUMERICSERV = 0x1000; -const AIFlags AI_ALL = 0x100; -const AIFlags AI_V4MAPPED_CFG = 0x200; -const AIFlags AI_ADDRCONFIG = 0x400; -const AIFlags AI_V4MAPPED = 0x800; -const AIFlags AI_UNUSABLE = 0x10000000; -const AIFlags AI_DEFAULT = AI_V4MAPPED_CFG | AI_ADDRCONFIG; +const AIFlags AI_NUMERICSERV = (AIFlags)0x1000; +const AIFlags AI_ALL = (AIFlags)0x100; +const AIFlags AI_V4MAPPED_CFG = (AIFlags)0x200; +const AIFlags AI_ADDRCONFIG = (AIFlags)0x400; +const AIFlags AI_V4MAPPED = (AIFlags)0x800; +const AIFlags AI_UNUSABLE = (AIFlags)0x10000000; +const AIFlags AI_DEFAULT = AI_V4MAPPED_CFG | AI_ADDRCONFIG; -const AIFamily PLATFORM_AF_IMPLINK = 3; -const AIFamily PLATFORM_AF_PUP = 4; -const AIFamily PLATFORM_AF_CHAOS = 5; -const AIFamily PLATFORM_AF_NS = 6; -const AIFamily PLATFORM_AF_ISO = 7; -const AIFamily PLATFORM_AF_ECMA = 8; -const AIFamily PLATFORM_AF_DATAKIT = 9; -const AIFamily PLATFORM_AF_CCITT = 10; -const AIFamily PLATFORM_AF_SNA = 11; -const AIFamily PLATFORM_AF_DECNET = 12; -const AIFamily PLATFORM_AF_DLI = 13; -const AIFamily PLATFORM_AF_LAT = 14; -const AIFamily PLATFORM_AF_HYLINK = 15; -const AIFamily PLATFORM_AF_APPLETALK = 16; -const AIFamily PLATFORM_AF_ROUTE = 17; -const AIFamily PLATFORM_AF_LINK = 18; -const AIFamily PLATFORM_PSEUDO_AF_XTP = 19; -const AIFamily PLATFORM_AF_COIP = 20; -const AIFamily PLATFORM_AF_CNT = 21; -const AIFamily PLATFORM_PSEUDO_AF_RTIP = 22; -const AIFamily PLATFORM_AF_IPX = 23; -const AIFamily PLATFORM_AF_SIP = 24; -const AIFamily PLATFORM_PSEUDO_AF_PIP = 25; -const AIFamily PLATFORM_AF_NDRV = 27; -const AIFamily PLATFORM_AF_ISDN = 28; -const AIFamily PLATFORM_PSEUDO_AF_KEY = 29; -const AIFamily PLATFORM_AF_INET6 = 30; -const AIFamily PLATFORM_AF_NATM = 31; -const AIFamily PLATFORM_AF_SYSTEM = 32; -const AIFamily PLATFORM_AF_NETBIOS = 33; -const AIFamily PLATFORM_AF_PPP = 34; -const AIFamily PLATFORM_PSEUDO_AF_HDRCMPLT = 35; -const AIFamily PLATFORM_AF_IEEE80211 = 37; -const AIFamily PLATFORM_AF_UTUN = 38; -const AIFamily PLATFORM_AF_VSOCK = 40; -const AIFamily PLATFORM_AF_MAX = 41; +const AIFamily PLATFORM_AF_IMPLINK = (AIFamily)3; +const AIFamily PLATFORM_AF_PUP = (AIFamily)4; +const AIFamily PLATFORM_AF_CHAOS = (AIFamily)5; +const AIFamily PLATFORM_AF_NS = (AIFamily)6; +const AIFamily PLATFORM_AF_ISO = (AIFamily)7; +const AIFamily PLATFORM_AF_ECMA = (AIFamily)8; +const AIFamily PLATFORM_AF_DATAKIT = (AIFamily)9; +const AIFamily PLATFORM_AF_CCITT = (AIFamily)10; +const AIFamily PLATFORM_AF_SNA = (AIFamily)11; +const AIFamily PLATFORM_AF_DECNET = (AIFamily)12; +const AIFamily PLATFORM_AF_DLI = (AIFamily)13; +const AIFamily PLATFORM_AF_LAT = (AIFamily)14; +const AIFamily PLATFORM_AF_HYLINK = (AIFamily)15; +const AIFamily PLATFORM_AF_APPLETALK = (AIFamily)16; +const AIFamily PLATFORM_AF_ROUTE = (AIFamily)17; +const AIFamily PLATFORM_AF_LINK = (AIFamily)18; +const AIFamily PLATFORM_PSEUDO_AF_XTP = (AIFamily)19; +const AIFamily PLATFORM_AF_COIP = (AIFamily)20; +const AIFamily PLATFORM_AF_CNT = (AIFamily)21; +const AIFamily PLATFORM_PSEUDO_AF_RTIP = (AIFamily)22; +const AIFamily PLATFORM_AF_IPX = (AIFamily)23; +const AIFamily PLATFORM_AF_SIP = (AIFamily)24; +const AIFamily PLATFORM_PSEUDO_AF_PIP = (AIFamily)25; +const AIFamily PLATFORM_AF_NDRV = (AIFamily)27; +const AIFamily PLATFORM_AF_ISDN = (AIFamily)28; +const AIFamily PLATFORM_PSEUDO_AF_KEY = (AIFamily)29; +const AIFamily PLATFORM_AF_INET6 = (AIFamily)30; +const AIFamily PLATFORM_AF_NATM = (AIFamily)31; +const AIFamily PLATFORM_AF_SYSTEM = (AIFamily)32; +const AIFamily PLATFORM_AF_NETBIOS = (AIFamily)33; +const AIFamily PLATFORM_AF_PPP = (AIFamily)34; +const AIFamily PLATFORM_PSEUDO_AF_HDRCMPLT = (AIFamily)35; +const AIFamily PLATFORM_AF_IEEE80211 = (AIFamily)37; +const AIFamily PLATFORM_AF_UTUN = (AIFamily)38; +const AIFamily PLATFORM_AF_VSOCK = (AIFamily)40; +const AIFamily PLATFORM_AF_MAX = (AIFamily)41; const int PLATFORM_O_NONBLOCK = 0x04; diff --git a/lib/std/net/socket_private.c3 b/lib/std/net/socket_private.c3 index 1de41cbcd..2a8bfff03 100644 --- a/lib/std/net/socket_private.c3 +++ b/lib/std/net/socket_private.c3 @@ -47,7 +47,7 @@ fn Socket? connect_with_timeout_from_addrinfo(AddrInfo* addrinfo, SocketOption[] $if env::WIN32: os::start_wsa()!; $endif - Clock c = 0; + Clock c; @loop_over_ai(addrinfo; NativeSocket sockfd, AddrInfo* ai) { apply_sockoptions(sockfd, options)!; diff --git a/lib/std/time/time.c3 b/lib/std/time/time.c3 index 0d50650ca..e3d53e95e 100644 --- a/lib/std/time/time.c3 +++ b/lib/std/time/time.c3 @@ -6,21 +6,21 @@ typedef Duration @structlike = long; typedef Clock @structlike = ulong; typedef NanoDuration (Printable) @structlike = long; -const Time FAR_FUTURE = long.max; -const Time FAR_PAST = long.min; +const Time FAR_FUTURE = (Time)long.max; +const Time FAR_PAST = (Time)long.min; -const NanoDuration NANO_DURATION_ZERO = 0; -const Duration US = 1; -const Duration MS = 1_000; -const Duration SEC = 1_000_000; -const Duration MIN = 60 * SEC; -const Duration HOUR = 60 * MIN; -const Duration DAY = 24 * HOUR; -const Duration WEEK = 7 * DAY; -const Duration MONTH = 30 * DAY; -const Duration YEAR = 36525 * DAY / 100; -const Duration FOREVER = long.max; -const Duration DURATION_ZERO = 0; +const NanoDuration NANO_DURATION_ZERO = (NanoDuration)0; +const Duration US = (Duration)1; +const Duration MS = (Duration)1_000; +const Duration SEC = (Duration)1_000_000; +const Duration MIN = (Duration)60 * SEC; +const Duration HOUR = (Duration)60 * MIN; +const Duration DAY = (Duration)24 * HOUR; +const Duration WEEK = (Duration)7 * DAY; +const Duration MONTH = (Duration)30 * DAY; +const Duration YEAR = (Duration)36525 * DAY / 100; +const Duration FOREVER = (Duration)long.max; +const Duration DURATION_ZERO = (Duration)0; fn Duration us(long l) @inline => l * US; fn Duration ms(long l) @inline => l * MS; diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index 2ea4ea2ad..cd1065632 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -1466,7 +1466,18 @@ static bool rule_to_distinct(CastContext *cc, bool is_explicit, bool is_silent) cc->to_group = flat_group; // If it's silent or explicit, just run it: - if (is_silent || is_explicit) return cast_is_allowed(cc, is_explicit, is_silent); + if (is_silent || is_explicit) + { + if (!cast_is_allowed(cc, is_explicit, is_silent)) return false; + if (!is_explicit && !cc->is_binary_conversion && !to_type->decl->attr_constinit && !expr_is_const_untyped_list(cc->expr)) + { + if (compiler.build.warnings.deprecation == WARNING_ERROR) + { + return sema_cast_error(cc, cast_is_allowed(cc, true, true), is_silent); + } + } + return true; + } // Loud and implicit: if (cast_is_allowed(cc, false, true)) { diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 4560424f4..0efd8e718 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -1798,10 +1798,10 @@ ERR: return false; } -bool sema_analyse_const_enum_constant_val(SemaContext *context, Decl *decl) +static bool sema_analyse_const_enum_constant_val(SemaContext *context, Decl *decl, Type *underlying_type) { Expr *value = decl->enum_constant.value; - if (!sema_analyse_inferred_expr(context, decl->type, value, NULL)) return decl_poison(decl); + if (!sema_analyse_expr_rhs(context, decl->type, value, false, NULL, true)) return decl_poison(decl); if (!expr_is_runtime_const(value)) { SEMA_ERROR(value, "Expected an constant enum value."); @@ -1809,8 +1809,8 @@ bool sema_analyse_const_enum_constant_val(SemaContext *context, Decl *decl) } if (value->type != decl->type) { - if (!cast_implicit_binary(context, value, decl->type, NULL)) return decl_poison(decl); - cast_explicit_silent(context, value, decl->type); + SEMA_ERROR(value, "Expected an constant enum value of type %s, was %s", type_quoted_error_string(decl->type), type_quoted_error_string(value->type)); + return decl_poison(decl); } return true; } @@ -1901,7 +1901,7 @@ static inline bool sema_analyse_raw_enum(SemaContext *context, Decl *decl, bool { Decl *enum_value = enum_values[i]; enum_value->resolve_status = RESOLVE_RUNNING; - if (!sema_analyse_const_enum_constant_val(context, enum_value)) return decl_poison(decl); + if (!sema_analyse_const_enum_constant_val(context, enum_value, type)) return decl_poison(decl); enum_value->resolve_status = RESOLVE_DONE; } return success; diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 4a84ecefa..b554ad5e0 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -7054,6 +7054,18 @@ bool sema_expr_analyse_assign_right_side(SemaContext *context, Expr *expr, Type // 1. Evaluate right side to required type. bool to_optional = left_type && type_is_optional(left_type); + if (is_declaration && left_type) + { + switch (left_type->type_kind) + { + case TYPE_TYPEDEF: + case TYPE_CONST_ENUM: + is_declaration = false; + break; + default: + break; + } + } if (!sema_analyse_expr_rhs(context, left_type, right, is_unwrapped_var || to_optional, failed_ref, is_declaration)) return false; if (IS_OPTIONAL(right) && !to_optional) { diff --git a/src/compiler/sema_internal.h b/src/compiler/sema_internal.h index 31646dfe4..e9d4999ca 100644 --- a/src/compiler/sema_internal.h +++ b/src/compiler/sema_internal.h @@ -137,7 +137,6 @@ INLINE bool sema_set_alignment(SemaContext *context, Type *type, AlignSize *resu INLINE bool sema_set_alloca_alignment(SemaContext *context, Type *type, AlignSize *result); INLINE void sema_display_deprecated_warning_on_use(SemaContext *context, Decl *decl, SourceSpan span); bool sema_expr_analyse_ct_concat(SemaContext *context, Expr *concat_expr, Expr *left, Expr *right, bool *failed_ref); -bool sema_analyse_const_enum_constant_val(SemaContext *context, Decl *decl); bool sema_analyse_attributes(SemaContext *context, Decl *decl, Attr **attrs, AttributeDomain domain, bool *erase_decl); void unit_register_optional_global_decl(CompilationUnit *unit, Decl *decl); diff --git a/src/main.c b/src/main.c index 57bd98a07..e595035a7 100644 --- a/src/main.c +++ b/src/main.c @@ -8,7 +8,8 @@ #include #endif #if PLATFORM_WINDOWS -#include +extern bool SetConsoleCP(uint32_t codepage); +extern bool SetConsoleOutputCP(uint32_t codepage); #endif bool debug_log = false; diff --git a/test/test_suite/distinct/distinct_function.c3t b/test/test_suite/distinct/distinct_function.c3t index 2d72cae3a..d99d25945 100644 --- a/test/test_suite/distinct/distinct_function.c3t +++ b/test/test_suite/distinct/distinct_function.c3t @@ -1,8 +1,8 @@ module test; alias FnA = fn void(int*); -typedef FnB = FnA; -typedef FnC = inline FnA; +typedef FnB @constinit = FnA; +typedef FnC @constinit = inline FnA; fn void func(int*) {} diff --git a/test/test_suite/distinct/distinct_function_call.c3 b/test/test_suite/distinct/distinct_function_call.c3 index 58eeff554..870622e1b 100644 --- a/test/test_suite/distinct/distinct_function_call.c3 +++ b/test/test_suite/distinct/distinct_function_call.c3 @@ -1,5 +1,5 @@ alias Abc = fn void(); -typedef Foo = inline Abc; +typedef Foo @constinit = inline Abc; struct Bar { inline Abc a; diff --git a/test/test_suite/distinct/distinct_sub.c3t b/test/test_suite/distinct/distinct_sub.c3t index 75c3bb04a..d320a0c5b 100644 --- a/test/test_suite/distinct/distinct_sub.c3t +++ b/test/test_suite/distinct/distinct_sub.c3t @@ -1,4 +1,4 @@ -typedef Foo = inline uint; +typedef Foo @constinit = inline uint; macro @test($abc) {