[flang-commits] [libc] [clang-tools-extra] [flang] [libcxx] [lld] [compiler-rt] [libunwind] [llvm] [libclc] [lldb] [clang] [clang] Add tests for DRs about complete-class context (PR #77444)
Vlad Serebrennikov via flang-commits
flang-commits at lists.llvm.org
Wed Jan 10 11:10:15 PST 2024
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/77444
>From 1cbf8eec15112cd6871fcfb69425c62f08c8f681 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Tue, 9 Jan 2024 14:17:21 +0300
Subject: [PATCH 1/3] [clang] Add tests for DRs about complete-class context
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[P1787](https://wg21.link/p1787): The intent for CWG2335 (contra those of the older CWG1890, CWG1626, CWG1255, and CWG287) is supported by retaining the unrestricted forward lookup in complete-class contexts (despite current implementation behavior for non-templates).
Wording: The declaration set is the result of a single search in the scope of C for N from immediately after the class-specifier of C if P is in a complete-class context of C or from P otherwise. [Drafting note: The plan for CWG2335 is to describe forbidden dependency cycles among the complete-class contexts of a class. — end drafting note] ([class.member.lookup]/4)
Complete-class context is described in [class.mem.general] [p7](http://eel.is/c++draft/class#mem.general-7) and [p8](http://eel.is/c++draft/class#mem.general-8). In this patch I add tests only for CWG issues that fall under current definition of complete-class context, because I'm not sure how CWG1255 and CWG287 are going to work. That's why I skip over them, but mark CWG1308 as superseded by CWG1330.
---
clang/test/CXX/drs/dr13xx.cpp | 2 ++
clang/test/CXX/drs/dr16xx.cpp | 22 ++++++++++++++++
clang/test/CXX/drs/dr18xx.cpp | 38 +++++++++++++++++++++++----
clang/test/CXX/drs/dr2335.cpp | 48 +++++++++++++++++++++++++++++++++++
clang/www/cxx_dr_status.html | 8 +++---
5 files changed, 109 insertions(+), 9 deletions(-)
create mode 100644 clang/test/CXX/drs/dr2335.cpp
diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index 359c04b3e0f3d4..81a8a8a361700a 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -40,6 +40,8 @@ void caller() {
#endif // __cplusplus >= 201103L
} // namespace dr1307
+// dr1308: sup 1330
+
namespace dr1310 { // dr1310: 5
struct S {} * sp = new S::S;
// expected-error at -1 {{qualified reference to 'S' is a constructor name rather than a type in this context}}
diff --git a/clang/test/CXX/drs/dr16xx.cpp b/clang/test/CXX/drs/dr16xx.cpp
index 3f074c4d57354a..342240cdc7a43d 100644
--- a/clang/test/CXX/drs/dr16xx.cpp
+++ b/clang/test/CXX/drs/dr16xx.cpp
@@ -42,6 +42,28 @@ namespace dr1611 { // dr1611: dup 1658
C c;
}
+namespace dr1626 { // dr1626: no open
+// FIXME: current consensus for CWG2335 is that the examples are well-formed.
+#if __cplusplus >= 201103L
+namespace ex1 {
+template <typename T> struct C {
+ template <typename T2> static constexpr bool _S_chk() { return false; }
+ static const bool __value = _S_chk<int>();
+};
+template struct C<double>;
+} // namespace ex1
+
+namespace ex2 {
+struct C {
+ static constexpr bool _S_chk() { return false; }
+ static const bool __value = _S_chk();
+ // expected-error at -1 {{in-class initializer for static data member is not a constant expression}}
+};
+C c;
+} // namespace ex2
+#endif
+} // namespace dr1626
+
namespace dr1631 { // dr1631: 3.7
#if __cplusplus >= 201103L
// Incorrect overload resolution for single-element initializer-list
diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index fbe67bd0c2f6db..0a0213c28595fd 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -1,10 +1,10 @@
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-17,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-17,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-17,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,cxx11-17,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,cxx11-17,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
#if __cplusplus == 199711L
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
@@ -176,6 +176,34 @@ namespace dr1881 { // dr1881: 7
static_assert(!__is_standard_layout(D), "");
}
+namespace dr1890 { // dr1890: no drafting
+// FIXME: current consensus for CWG2335 is that the examples are well-formed.
+namespace ex1 {
+#if __cplusplus >= 201402L
+struct A {
+ struct B {
+ auto foo() { return 0; } // #dr1890-foo
+ };
+ decltype(B().foo()) x;
+ // since-cxx14-error at -1 {{function 'foo' with deduced return type cannot be used before it is defined}}
+ // since-cxx14-note@#dr1890-foo {{'foo' declared here}}
+};
+#endif
+} // namespace ex1
+
+namespace ex2 {
+#if __cplusplus >= 201103L
+struct Bar {
+ struct Baz {
+ int a = 0;
+ };
+ static_assert(__is_constructible(Baz), "");
+ // since-cxx11-error at -1 {{static assertion failed due to requirement '__is_constructible(dr1890::ex2::Bar::Baz)'}}
+};
+#endif
+} // namespace ex2
+} // namespace dr1890
+
void dr1891() { // dr1891: 4
#if __cplusplus >= 201103L
int n;
diff --git a/clang/test/CXX/drs/dr2335.cpp b/clang/test/CXX/drs/dr2335.cpp
new file mode 100644
index 00000000000000..d143aaf7cb0ac0
--- /dev/null
+++ b/clang/test/CXX/drs/dr2335.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
+
+#if __cplusplus <= 201103L
+// expected-no-diagnostics
+#endif
+
+namespace dr2335 { // dr2335: no drafting
+// FIXME: current consensus is that the examples are well-formed.
+#if __cplusplus >= 201402L
+namespace ex1 {
+template <class...> struct partition_indices {
+ static auto compute_right() {}
+ static constexpr auto right = compute_right;
+};
+template struct partition_indices<int>;
+} // namespace ex1
+
+namespace ex2 {
+template <int> struct X {};
+template <class T> struct partition_indices {
+ static auto compute_right() { return X<I>(); }
+ // since-cxx14-error at -1 {{no member 'I' in 'dr2335::ex2::partition_indices<int>'; it has not yet been instantiated}}
+ // since-cxx14-note@#dr2335-ex2-right {{in instantiation of member function 'dr2335::ex2::partition_indices<int>::compute_right' requested here}}
+ // since-cxx14-note@#dr2335-ex2-inst {{in instantiation of template class 'dr2335::ex2::partition_indices<int>' requested here}}
+ // since-cxx14-note@#dr2335-ex2-I {{not-yet-instantiated member is declared here}}
+ static constexpr auto right = compute_right; // #dr2335-ex2-right
+ static constexpr int I = sizeof(T); // #dr2335-ex2-I
+};
+template struct partition_indices<int>; // #dr2335-ex2-inst
+} // namespace ex2
+
+namespace ex3 {
+struct partition_indices {
+ static auto compute_right() {} // #dr2335-compute_right
+ static constexpr auto right = compute_right; // #dr2335-ex3-right
+ // since-cxx14-error at -1 {{function 'compute_right' with deduced return type cannot be used before it is defined}}
+ // since-cxx14-note@#dr2335-compute_right {{'compute_right' declared here}}
+ // since-cxx14-error@#dr2335-ex3-right {{declaration of variable 'right' with deduced type 'const auto' requires an initializer}}
+};
+} // namespace ex3
+#endif
+} // namespace dr2335
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 22eb7ac63c7edf..6c58a5a4a178fd 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -7655,7 +7655,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/1308.html">1308</a></td>
<td>CD3</td>
<td>Completeness of class type within an <I>exception-specification</I></td>
- <td class="none" align="center">Unknown</td>
+ <td class="full" align="center">Superseded by <a href="#1330">1330</a></td>
</tr>
<tr id="1309">
<td><a href="https://cplusplus.github.io/CWG/issues/1309.html">1309</a></td>
@@ -9563,7 +9563,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/1626.html">1626</a></td>
<td>open</td>
<td><TT>constexpr</TT> member functions in <I>brace-or-equal-initializer</I>s</td>
- <td align="center">Not resolved</td>
+ <td class="none" align="center">No</td>
</tr>
<tr id="1627">
<td><a href="https://cplusplus.github.io/CWG/issues/1627.html">1627</a></td>
@@ -11147,7 +11147,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/1890.html">1890</a></td>
<td>drafting</td>
<td>Member type depending on definition of member function</td>
- <td align="center">Not resolved</td>
+ <td class="none" align="center">No</td>
</tr>
<tr id="1891">
<td><a href="https://cplusplus.github.io/CWG/issues/1891.html">1891</a></td>
@@ -13817,7 +13817,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/2335.html">2335</a></td>
<td>drafting</td>
<td>Deduced return types vs member types</td>
- <td align="center">Not resolved</td>
+ <td class="none" align="center">No</td>
</tr>
<tr id="2336">
<td><a href="https://cplusplus.github.io/CWG/issues/2336.html">2336</a></td>
>From fec9c678f79496a9758aa0c5f620b5f960fc02ac Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Wed, 10 Jan 2024 16:05:54 +0300
Subject: [PATCH 2/3] Update cxx_dr_status.html
---
clang/www/cxx_dr_status.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 8fb446a5a064fe..6d4cb532a6e17b 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -2661,7 +2661,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/437.html">437</a></td>
<td>CD1</td>
<td>Is type of class allowed in member function exception specification?</td>
- <td class="none" align="center">Superseded by <a href="#1308">1308</a></td>
+ <td class="full" align="center">Superseded by <a href="#1308">1308</a></td>
</tr>
<tr id="438">
<td><a href="https://cplusplus.github.io/CWG/issues/438.html">438</a></td>
>From ab4c2e9e06e8a97341214a5bbcfb67f3debcb1be Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Wed, 10 Jan 2024 22:09:46 +0300
Subject: [PATCH 3/3] Leave a comment about 2335 being in a separate file
---
clang/test/CXX/drs/dr23xx.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/test/CXX/drs/dr23xx.cpp b/clang/test/CXX/drs/dr23xx.cpp
index 9ced61d2aae30d..ec9aaae0b2d863 100644
--- a/clang/test/CXX/drs/dr23xx.cpp
+++ b/clang/test/CXX/drs/dr23xx.cpp
@@ -48,6 +48,7 @@ void g() {
#endif
// dr2331: na
+// dr2335 is in dr2335.cxx
#if __cplusplus >= 201103L
namespace dr2338 { // dr2338: 12
More information about the flang-commits
mailing list