[libcxx-commits] [PATCH] D143140: [libc++] avoid a GCC -Wsigned-compare warning where time_t is unsigned

YAMAMOTO Takashi via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 2 00:11:20 PST 2023


yamt created this revision.
Herald added a project: All.
yamt requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Note: For some reasons, GCC -Wall enables the warning for C++
while it doesn't for C.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143140

Files:
  libcxx/src/condition_variable.cpp


Index: libcxx/src/condition_variable.cpp
===================================================================
--- libcxx/src/condition_variable.cpp
+++ libcxx/src/condition_variable.cpp
@@ -63,15 +63,12 @@
     seconds s = duration_cast<seconds>(d);
     typedef decltype(ts.tv_sec) ts_sec;
     _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max();
-    if (s.count() < ts_sec_max)
-    {
-        ts.tv_sec = static_cast<ts_sec>(s.count());
-        ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
-    }
-    else
-    {
-        ts.tv_sec = ts_sec_max;
-        ts.tv_nsec = giga::num - 1;
+    if ((unsigned long long)s.count() < ts_sec_max) {
+      ts.tv_sec  = static_cast<ts_sec>(s.count());
+      ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
+    } else {
+      ts.tv_sec  = ts_sec_max;
+      ts.tv_nsec = giga::num - 1;
     }
     int ec = __libcpp_condvar_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
     if (ec != 0 && ec != ETIMEDOUT)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143140.494181.patch
Type: text/x-patch
Size: 1013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230202/b894908b/attachment.bin>


More information about the libcxx-commits mailing list