Skip to content

[libc++][test] Fix Clang -Wunused-variable warnings in time.zone.members/to_sys.pass.cpp #100504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

StephanTLavavej
Copy link
Member

Recently introduced by @mordante's #90394. This newly added test contains code like:

TEST_VALIDATE_EXCEPTION(
std::chrono::nonexistent_local_time,
[&]([[maybe_unused]] const std::chrono::nonexistent_local_time& e) {
std::string_view what =
R"(1986-03-30 02:30:00.000000000 is in a gap between
1986-03-30 02:00:00 CET and
1986-03-30 03:00:00 CEST which are both equivalent to
1986-03-30 01:00:00 UTC)";
TEST_LIBCPP_REQUIRE(
e.what() == what,
TEST_WRITE_CONCATENATED("Expected exception\n", what, "\n\nActual exception\n", e.what(), '\n'));
},
tz->to_sys(time + 0ns));

The usage in TEST_LIBCPP_REQUIRE is libc++-specific, which expands to nothing for MSVC's STL. That's good, but any variables that are only used within libc++-specific test code need to be marked as [[maybe_unused]]. The std::string_view what isn't, emitting warnings:

D:\GitHub\STL\llvm-project\libcxx\test\std\time\time.zone\time.zone.timezone\time.zone.members\to_sys.pass.cpp(92,26): error: unused variable 'what' [-Werror,-Wunused-variable]
   92 |         std::string_view what =
      |                          ^~~~
D:\GitHub\STL\llvm-project\libcxx\test\support\assert_macros.h(136,9): note: expanded from macro 'TEST_VALIDATE_EXCEPTION'
  136 |         PRED(EXCEPTION);                                                                                               \
      |         ^~~~

@StephanTLavavej StephanTLavavej requested a review from a team as a code owner July 25, 2024 03:02
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2024

@llvm/pr-subscribers-libcxx

Author: Stephan T. Lavavej (StephanTLavavej)

Changes

Recently introduced by @mordante's #90394. This newly added test contains code like:

TEST_VALIDATE_EXCEPTION(
std::chrono::nonexistent_local_time,
[&]([[maybe_unused]] const std::chrono::nonexistent_local_time& e) {
std::string_view what =
R"(1986-03-30 02:30:00.000000000 is in a gap between
1986-03-30 02:00:00 CET and
1986-03-30 03:00:00 CEST which are both equivalent to
1986-03-30 01:00:00 UTC)";
TEST_LIBCPP_REQUIRE(
e.what() == what,
TEST_WRITE_CONCATENATED("Expected exception\n", what, "\n\nActual exception\n", e.what(), '\n'));
},
tz->to_sys(time + 0ns));

The usage in TEST_LIBCPP_REQUIRE is libc++-specific, which expands to nothing for MSVC's STL. That's good, but any variables that are only used within libc++-specific test code need to be marked as [[maybe_unused]]. The std::string_view what isn't, emitting warnings:

D:\GitHub\STL\llvm-project\libcxx\test\std\time\time.zone\time.zone.timezone\time.zone.members\to_sys.pass.cpp(92,26): error: unused variable 'what' [-Werror,-Wunused-variable]
   92 |         std::string_view what =
      |                          ^~~~
D:\GitHub\STL\llvm-project\libcxx\test\support\assert_macros.h(136,9): note: expanded from macro 'TEST_VALIDATE_EXCEPTION'
  136 |         PRED(EXCEPTION);                                                                                               \
      |         ^~~~

Full diff: https://github.com/llvm/llvm-project/pull/100504.diff

1 Files Affected:

  • (modified) libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp (+8-8)
diff --git a/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp b/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp
index 874c3d52e460b..e32b6d523d0ed 100644
--- a/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp
+++ b/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp
@@ -89,7 +89,7 @@ static void test_nonexistent() {
   TEST_VALIDATE_EXCEPTION(
       std::chrono::nonexistent_local_time,
       [&]([[maybe_unused]] const std::chrono::nonexistent_local_time& e) {
-        std::string_view what =
+        [[maybe_unused]] std::string_view what =
             R"(1986-03-30 02:30:00.000000000 is in a gap between
 1986-03-30 02:00:00 CET and
 1986-03-30 03:00:00 CEST which are both equivalent to
@@ -103,7 +103,7 @@ static void test_nonexistent() {
   TEST_VALIDATE_EXCEPTION(
       std::chrono::nonexistent_local_time,
       [&]([[maybe_unused]] const std::chrono::nonexistent_local_time& e) {
-        std::string_view what =
+        [[maybe_unused]] std::string_view what =
             R"(1986-03-30 02:30:00.000000 is in a gap between
 1986-03-30 02:00:00 CET and
 1986-03-30 03:00:00 CEST which are both equivalent to
@@ -117,7 +117,7 @@ static void test_nonexistent() {
   TEST_VALIDATE_EXCEPTION(
       std::chrono::nonexistent_local_time,
       [&]([[maybe_unused]] const std::chrono::nonexistent_local_time& e) {
-        std::string_view what =
+        [[maybe_unused]] std::string_view what =
             R"(1986-03-30 02:30:00.000 is in a gap between
 1986-03-30 02:00:00 CET and
 1986-03-30 03:00:00 CEST which are both equivalent to
@@ -131,7 +131,7 @@ static void test_nonexistent() {
   TEST_VALIDATE_EXCEPTION(
       std::chrono::nonexistent_local_time,
       [&]([[maybe_unused]] const std::chrono::nonexistent_local_time& e) {
-        std::string_view what =
+        [[maybe_unused]] std::string_view what =
             R"(1986-03-30 02:30:00 is in a gap between
 1986-03-30 02:00:00 CET and
 1986-03-30 03:00:00 CEST which are both equivalent to
@@ -173,7 +173,7 @@ static void test_ambiguous() {
   TEST_VALIDATE_EXCEPTION(
       std::chrono::ambiguous_local_time,
       [&]([[maybe_unused]] const std::chrono::ambiguous_local_time& e) {
-        std::string_view what =
+        [[maybe_unused]] std::string_view what =
             R"(1986-09-28 02:30:00.000000000 is ambiguous.  It could be
 1986-09-28 02:30:00.000000000 CEST == 1986-09-28 00:30:00.000000000 UTC or
 1986-09-28 02:30:00.000000000 CET == 1986-09-28 01:30:00.000000000 UTC)";
@@ -186,7 +186,7 @@ static void test_ambiguous() {
   TEST_VALIDATE_EXCEPTION(
       std::chrono::ambiguous_local_time,
       [&]([[maybe_unused]] const std::chrono::ambiguous_local_time& e) {
-        std::string_view what =
+        [[maybe_unused]] std::string_view what =
             R"(1986-09-28 02:30:00.000000 is ambiguous.  It could be
 1986-09-28 02:30:00.000000 CEST == 1986-09-28 00:30:00.000000 UTC or
 1986-09-28 02:30:00.000000 CET == 1986-09-28 01:30:00.000000 UTC)";
@@ -199,7 +199,7 @@ static void test_ambiguous() {
   TEST_VALIDATE_EXCEPTION(
       std::chrono::ambiguous_local_time,
       [&]([[maybe_unused]] const std::chrono::ambiguous_local_time& e) {
-        std::string_view what =
+        [[maybe_unused]] std::string_view what =
             R"(1986-09-28 02:30:00.000 is ambiguous.  It could be
 1986-09-28 02:30:00.000 CEST == 1986-09-28 00:30:00.000 UTC or
 1986-09-28 02:30:00.000 CET == 1986-09-28 01:30:00.000 UTC)";
@@ -212,7 +212,7 @@ static void test_ambiguous() {
   TEST_VALIDATE_EXCEPTION(
       std::chrono::ambiguous_local_time,
       [&]([[maybe_unused]] const std::chrono::ambiguous_local_time& e) {
-        std::string_view what =
+        [[maybe_unused]] std::string_view what =
             R"(1986-09-28 02:30:00 is ambiguous.  It could be
 1986-09-28 02:30:00 CEST == 1986-09-28 00:30:00 UTC or
 1986-09-28 02:30:00 CET == 1986-09-28 01:30:00 UTC)";

Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM!

@StephanTLavavej StephanTLavavej merged commit b27360c into llvm:main Jul 25, 2024
59 checks passed
@StephanTLavavej StephanTLavavej deleted the what-is-the-meaning-of-this branch July 25, 2024 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants