[libc-commits] [libc] [libc] Fix implict cast to time_t warning (PR #126947)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Wed Feb 12 09:36:41 PST 2025


https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/126947

On some systems time_t is 32 bit, causing build errors (with -Werror)
in get_epoch which attempts to implicitly convert an int64_t to a
time_t.


>From 3a4a310df39a0632b50bdb12ade4cc06b979335c Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Wed, 12 Feb 2025 09:34:48 -0800
Subject: [PATCH] [libc] Fix implict cast to time_t warning

On some systems time_t is 32 bit, causing build errors (with -Werror)
in get_epoch which attempts to implicitly convert an int64_t to a
time_t.
---
 libc/src/time/time_utils.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libc/src/time/time_utils.h b/libc/src/time/time_utils.h
index 324e129f6f780..68eaac8c04f11 100644
--- a/libc/src/time/time_utils.h
+++ b/libc/src/time/time_utils.h
@@ -328,7 +328,9 @@ class TMReader final {
     return BASE_YEAR + IS_NEXT_YEAR;
   }
 
-  LIBC_INLINE time_t get_epoch() const { return mktime_internal(timeptr); }
+  LIBC_INLINE time_t get_epoch() const {
+    return static_cast<time_t>(mktime_internal(timeptr));
+  }
 
   // returns the timezone offset in microwave time:
   // return (hours * 100) + minutes;



More information about the libc-commits mailing list