[clang] Mark CWG2943 as implemented and add a test (PR #195192)

Victor Chernyakin via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 30 15:52:16 PDT 2026


https://github.com/localspook created https://github.com/llvm/llvm-project/pull/195192

[CWG2943](https://wg21.link/cwg2943) says that calling a function that's marked `[[nodiscard]]` but returns `void` should not issue a warning. I've marked it as implemented since Clang 3.8, the first version that supports `[[nodiscard]]` at all: https://godbolt.org/z/KTz5oe1az

>From bf3b738651ca8b108070cb0ae8f935dddb44d785 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <chernyakin.victor.j at outlook.com>
Date: Thu, 30 Apr 2026 15:32:42 -0700
Subject: [PATCH] Mark CWG2943 as implemented and add a test

---
 clang/test/CXX/drs/cwg29xx.cpp | 17 +++++++++++++++++
 clang/www/cxx_dr_status.html   |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/cwg29xx.cpp b/clang/test/CXX/drs/cwg29xx.cpp
index 54f5547a1629d..5b19303a2aa8b 100644
--- a/clang/test/CXX/drs/cwg29xx.cpp
+++ b/clang/test/CXX/drs/cwg29xx.cpp
@@ -174,4 +174,21 @@ constexpr U _ = nondeterministic(true);
 #endif
 } // namespace cwg2922
 
+namespace cwg2943 { // cwg2943: 3.8
+#if __cplusplus >= 201103L
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wignored-attributes"
+[[nodiscard]] void f();
+#pragma clang diagnostic pop
+template <class T> [[nodiscard]] T g();
+
+void h() {
+  f();
+  g<void>();
+  g<int>();
+  // expected-warning at -1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+}
+#endif
+} // namespace cwg2943
+
 // cwg2947 is in cwg2947.cpp
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 51c3d87322d0a..6fab942f873bc 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -20418,7 +20418,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td>[<a href="https://wg21.link/dcl.attr.nodiscard">dcl.attr.nodiscard</a>]</td>
     <td>CD7</td>
     <td>Discarding a void return value</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Clang 3.8</td>
   </tr>
   <tr id="2944">
     <td><a href="https://cplusplus.github.io/CWG/issues/2944.html">2944</a></td>



More information about the cfe-commits mailing list