[clang] [clang] Tests for CWG1670 and CWG1878: `auto` in conversion functions (PR #187850)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 21 02:53:13 PDT 2026
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/187850
This PR adds tests for [CWG1670](https://cplusplus.github.io/CWG/issues/1670.html) "`auto` as _conversion-type-id_" and [CWG1878](https://cplusplus.github.io/CWG/issues/1878.html) "`operator auto` template". The long and short of it is that placeholder type specifier (`auto`) cannot be used to declare conversion function or conversion function template. We've always diagnosed template case but not non-template case.
>From 522fd82433a07613da58c2b9c520f72d692e3db6 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Sat, 21 Mar 2026 12:46:45 +0300
Subject: [PATCH] [clang] Tests for CWG1670 and CWG1878: `auto` in declarations
of conversion functions
---
clang/test/CXX/drs/cwg16xx.cpp | 9 +++++++++
clang/test/CXX/drs/cwg18xx.cpp | 13 ++++++++++++-
clang/www/cxx_dr_status.html | 4 ++--
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/clang/test/CXX/drs/cwg16xx.cpp b/clang/test/CXX/drs/cwg16xx.cpp
index 673916ee40d6f..bcae9e0b6d177 100644
--- a/clang/test/CXX/drs/cwg16xx.cpp
+++ b/clang/test/CXX/drs/cwg16xx.cpp
@@ -328,6 +328,15 @@ namespace cwg1658 { // cwg1658: 5
// assignment case is superseded by cwg2180
} // namespace cwg1658
+namespace cwg1670 { // cwg1670: no
+#if __cpusplus >= 201103L
+struct S {
+ operator auto() { return 0; }
+ // FIXME-error at -1 {{'auto' not allowed in declaration of conversion function}}
+};
+#endif
+} // namespace cwg1670
+
namespace cwg1672 { // cwg1672: 7
struct Empty {};
struct A : Empty {};
diff --git a/clang/test/CXX/drs/cwg18xx.cpp b/clang/test/CXX/drs/cwg18xx.cpp
index ebee9bc4c3e16..f0424a1021abc 100644
--- a/clang/test/CXX/drs/cwg18xx.cpp
+++ b/clang/test/CXX/drs/cwg18xx.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected,cxx98-14,cxx98
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected,cxx11-20,cxx98-14,cxx11-17,since-cxx11
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected,cxx11-20,cxx98-14,cxx11-17,since-cxx11,cxx11
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected,cxx11-20,since-cxx14,cxx98-14,cxx11-17,since-cxx11,since-cxx14
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected,cxx11-20,since-cxx14,since-cxx17,cxx11-17,since-cxx11,since-cxx14,cxx17
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected,cxx11-20,since-cxx14,since-cxx17,since-cxx20,since-cxx11,since-cxx14
@@ -467,6 +467,17 @@ template<int U>
int A<int>::i() { (void)c.private_int; }
} // namespace cwg1862
+namespace cwg1870 { // cwg1870: 2.7
+#if __cplusplus >= 201103L
+struct S {
+ // FIXME: why C++11 has its own diagnostic message?
+ template<class T> operator auto() { return 42; }
+ // cxx11-error at -1 {{'auto' not allowed in conversion function type}}
+ // since-cxx14-error at -2 {{'auto' not allowed in declaration of conversion function template}}
+};
+#endif
+} // namespace cwg1870
+
namespace cwg1872 { // cwg1872: 9
#if __cplusplus >= 201103L
template<typename T> struct A : T {
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index cb0236b46e580..347f48ed7d87f 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -11475,7 +11475,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td>[<a href="https://wg21.link/dcl.spec.auto">dcl.spec.auto</a>]</td>
<td>DR</td>
<td><TT>auto</TT> as <I>conversion-type-id</I></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="none" align="center">No</td>
</tr>
<tr id="1671">
<td><a href="https://cplusplus.github.io/CWG/issues/1671.html">1671</a></td>
@@ -12875,7 +12875,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td>[<a href="https://wg21.link/basic.def">basic.def</a>]</td>
<td>CD4</td>
<td>Contradictory wording about definitions vs explicit specialization/instantiation</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Clang 2.7</td>
</tr>
<tr id="1871">
<td><a href="https://cplusplus.github.io/CWG/issues/1871.html">1871</a></td>
More information about the cfe-commits
mailing list