Skip to content

Conversation

@StephanTLavavej
Copy link
Member

MSVC's STL marks std::make_shared, std::allocate_shared, std::bitset::to_ulong, and std::bitset::to_ullong as [[nodiscard]], which causes these libcxx tests to emit righteous warnings. They should use the traditional (void) cast technique to ignore the return values.

@StephanTLavavej StephanTLavavej requested a review from a team as a code owner August 20, 2025 21:27
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Aug 20, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 20, 2025

@llvm/pr-subscribers-libcxx

Author: Stephan T. Lavavej (StephanTLavavej)

Changes

MSVC's STL marks std::make_shared, std::allocate_shared, std::bitset::to_ulong, and std::bitset::to_ullong as [[nodiscard]], which causes these libcxx tests to emit righteous warnings. They should use the traditional (void) cast technique to ignore the return values.


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

3 Files Affected:

  • (modified) libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/shared_ptr_array.pass.cpp (+4-4)
  • (modified) libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp (+1-1)
  • (modified) libcxx/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp (+1-1)
diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/shared_ptr_array.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/shared_ptr_array.pass.cpp
index 9bc695cd7fb76..f71f688afc52e 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/shared_ptr_array.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/shared_ptr_array.pass.cpp
@@ -20,11 +20,11 @@
 #include <memory>
 
 int main(int, char**) {
-  std::allocate_shared<int[]>(std::allocator<int>{}, 10);
-  std::make_shared<int[]>(10);
+  (void)std::allocate_shared<int[]>(std::allocator<int>{}, 10);
+  (void)std::make_shared<int[]>(10);
 
-  std::allocate_shared<int[10]>(std::allocator<int>{});
-  std::make_shared<int[10]>();
+  (void)std::allocate_shared<int[10]>(std::allocator<int>{});
+  (void)std::make_shared<int[10]>();
 
   return 0;
 }
diff --git a/libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp b/libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp
index 3c5a57d1c7fec..980dbe9ba15d0 100644
--- a/libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp
+++ b/libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp
@@ -65,7 +65,7 @@ TEST_CONSTEXPR_CXX23 bool test() {
     std::bitset<std::numeric_limits<unsigned long long>::digits + 1> q(0);
     q.flip();
     try {
-      q.to_ullong(); // throws
+      (void)q.to_ullong(); // throws
       assert(false);
     } catch (const std::overflow_error&) {
       // expected
diff --git a/libcxx/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp b/libcxx/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp
index d943030a16287..47ad127513ade 100644
--- a/libcxx/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp
+++ b/libcxx/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp
@@ -64,7 +64,7 @@ TEST_CONSTEXPR_CXX23 bool test() {
     std::bitset<std::numeric_limits<unsigned long>::digits + 1> q(0);
     q.flip();
     try {
-      q.to_ulong(); // throws
+      (void)q.to_ulong(); // throws
       assert(false);
     } catch (const std::overflow_error&) {
       // expected

@StephanTLavavej StephanTLavavej merged commit f60ff00 into llvm:main Aug 21, 2025
69 of 74 checks passed
@StephanTLavavej StephanTLavavej deleted the know-this-card branch August 21, 2025 07:28
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.

4 participants