[libcxx-commits] [libcxx] 8b53523 - [libc++][chrono][NFC] Refactor `nodiscard.verify.cpp` (#175411)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jan 10 23:38:24 PST 2026
Author: Hristo Hristov
Date: 2026-01-11T09:38:19+02:00
New Revision: 8b53523163249d41eabf12867a89a05e9d018f8c
URL: https://github.com/llvm/llvm-project/commit/8b53523163249d41eabf12867a89a05e9d018f8c
DIFF: https://github.com/llvm/llvm-project/commit/8b53523163249d41eabf12867a89a05e9d018f8c.diff
LOG: [libc++][chrono][NFC] Refactor `nodiscard.verify.cpp` (#175411)
A pre-requisite for https://github.com/llvm/llvm-project/pull/174968 -
just moved around a few lines as a first step to splitting the test.
Added:
Modified:
libcxx/test/libcxx/time/nodiscard.verify.cpp
Removed:
################################################################################
diff --git a/libcxx/test/libcxx/time/nodiscard.verify.cpp b/libcxx/test/libcxx/time/nodiscard.verify.cpp
index 94be9679bde7f..82f8080586f38 100644
--- a/libcxx/test/libcxx/time/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/time/nodiscard.verify.cpp
@@ -107,103 +107,140 @@ void test(std::chrono::time_zone tz, std::chrono::time_zone_link link, std::chro
}
#endif // TEST_STD_VER >= 20
-void test() {
- { // [time.duration]
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::microseconds(2));
+void test_duration() { // [time.duration]
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::microseconds(2));
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::duration_values<int>::zero();
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::duration_values<int>::max();
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::duration_values<int>::min();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::duration_values<int>::zero();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::duration_values<int>::max();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::duration_values<int>::min();
- std::chrono::duration<int, std::ratio<1, 30> > dr;
+ std::chrono::duration<int, std::ratio<1, 30> > dr;
#if TEST_STD_VER >= 17
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::floor<std::chrono::seconds>(dr);
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::ceil<std::chrono::seconds>(dr);
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::round<std::chrono::seconds>(dr);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::floor<std::chrono::seconds>(dr);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::ceil<std::chrono::seconds>(dr);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::round<std::chrono::seconds>(dr);
#endif
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- dr.count();
-
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- +dr;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- -dr;
-
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::duration<int, std::ratio<1, 30> >::zero();
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::duration<int, std::ratio<1, 30> >::max();
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::duration<int, std::ratio<1, 30> >::min();
-
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- dr + dr;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- dr - dr;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- dr * 94;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 94 * dr;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- dr / 82;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- dr / dr;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- dr % 47;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- dr % dr;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ dr.count();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ +dr;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ -dr;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::duration<int, std::ratio<1, 30> >::zero();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::duration<int, std::ratio<1, 30> >::max();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::duration<int, std::ratio<1, 30> >::min();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ dr + dr;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ dr - dr;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ dr * 94;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 94 * dr;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ dr / 82;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ dr / dr;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ dr % 47;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ dr % dr;
#if TEST_STD_VER >= 17
- using namespace std::chrono_literals;
-
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 94h;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 82.5h;
+ using namespace std::chrono_literals;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 94h;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 82.5h;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 94min;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 82.5min;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 94s;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 82.5s;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 94ms;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 82.5ms;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 94us;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 82.5us;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 94ns;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 82.5ns;
+#endif // TEST_STD_VER >= 14
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 94min;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 82.5min;
+#if TEST_STD_VER >= 26
+ std::hash<std::chrono::duration<int, std::ratio<1, 30>>> hash;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 94s;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 82.5s;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ hash(dr);
+#endif
+}
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 94ms;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 82.5ms;
+void test_time_point() { // [time.point]
+ std::chrono::time_point<std::chrono::system_clock> tp;
+ std::chrono::duration<double, std::ratio<1, 30> > dr;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 94us;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 82.5us;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ tp.time_since_epoch();
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 94ns;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- 82.5ns;
-#endif // TEST_STD_VER >= 14
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ tp.min();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ tp.max();
-#if TEST_STD_VER >= 26
- std::hash<std::chrono::duration<int, std::ratio<1, 30>>> hash;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::time_point_cast<std::chrono::seconds>(tp);
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- hash(dr);
+#if TEST_STD_VER >= 17
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::floor<std::chrono::seconds>(tp);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::ceil<std::chrono::seconds>(tp);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::round<std::chrono::seconds>(tp);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::chrono::abs(dr);
#endif
- }
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ tp + dr;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ dr + tp;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ tp - dr;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ tp - tp;
+}
+
+void test_clocks() { // [time.clock]
#if TEST_STD_VER >= 20
{ // [time.clock.file]
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -274,43 +311,6 @@ void test() {
}
#endif
- { // [time.point]
- std::chrono::time_point<std::chrono::system_clock> tp;
- std::chrono::duration<double, std::ratio<1, 30> > dr;
-
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- tp.time_since_epoch();
-
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- tp.min();
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- tp.max();
-
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::time_point_cast<std::chrono::seconds>(tp);
-
-#if TEST_STD_VER >= 17
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::floor<std::chrono::seconds>(tp);
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::ceil<std::chrono::seconds>(tp);
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::round<std::chrono::seconds>(tp);
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::chrono::abs(dr);
-#endif
-
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- tp + dr;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- dr + tp;
-
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- tp - dr;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- tp - tp;
- }
-
#if TEST_STD_VER >= 20
{ // [time.clock.utc]
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
More information about the libcxx-commits
mailing list