[clang] [clang][NFC] Mark CWG2785 as implemented and add a test (PR #195547)
Victor Chernyakin via cfe-commits
cfe-commits at lists.llvm.org
Sun May 3 13:21:14 PDT 2026
https://github.com/localspook created https://github.com/llvm/llvm-project/pull/195547
[CWG2785](https://wg21.link/cwg2785) clarifies that a *requires-expression* is never type-dependent, it always has type `bool`. That means that in a snippet like this:
```cpp
void g(void *);
template <typename T>
void f() {
g(requires { T(); });
}
```
The call to `g` should be diagnosed as invalid (`bool` is not convertible to `void *`) even if the template is never instantiated. Clang does the right thing since version 10: https://godbolt.org/z/s61rEbsfz
>From 4859e7559171bd0e8a59c05a7e95dea9f5ccb622 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <chernyakin.victor.j at outlook.com>
Date: Sun, 3 May 2026 13:16:22 -0700
Subject: [PATCH] [clang][NFC] Mark CWG2785 as implemented and add a test
---
clang/test/CXX/drs/cwg27xx.cpp | 13 +++++++++++++
clang/www/cxx_dr_status.html | 2 +-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index 29fe6ca86e773..6b110fd4ed97f 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -204,6 +204,19 @@ void g() {
} // namespace cwg2780
+namespace cwg2785 { // cwg2785: 10
+#if __cplusplus >= 202002L
+void g(void *); // #cwg2785-g
+
+template <typename T>
+void f() {
+ g(requires { T(); });
+ // since-cxx20-error at -1 {{no matching function for call to 'g'}}
+ // since-cxx20-note@#cwg2785-g {{candidate function not viable: no known conversion from 'bool' to 'void *' for 1st argument}}
+}
+#endif
+} // namespace cwg2785
+
namespace cwg2789 { // cwg2789: 18
#if __cplusplus >= 202302L
template <typename T = int>
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index feef0c3770f64..b00ee165c251b 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -19304,7 +19304,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td>[<a href="https://wg21.link/temp.dep.expr">temp.dep.expr</a>]</td>
<td>CD7</td>
<td>Type-dependence of <I>requires-expression</I></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Clang 10</td>
</tr>
<tr class="open" id="2786">
<td><a href="https://cplusplus.github.io/CWG/issues/2786.html">2786</a></td>
More information about the cfe-commits
mailing list