[clang] [clang] Add tests for some of CWG issues resolved in Croydon (2026-03) (PR #189299)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Mon May 4 01:21:01 PDT 2026
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/189299
>From c185a2bc57aa640ed1b4530574f368c076cc19a9 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Mon, 30 Mar 2026 04:50:27 +0300
Subject: [PATCH] [clang] Add tests for some of CWG issues resolved in Croydon
(2026-03) as P4160R0
---
clang/test/CXX/drs/cwg26xx.cpp | 2 +
clang/test/CXX/drs/cwg27xx.cpp | 67 ++++++++++++++++++++++++++++++----
clang/test/CXX/drs/cwg29xx.cpp | 10 +++++
clang/test/CXX/drs/cwg30xx.cpp | 11 ++++++
clang/test/CXX/drs/cwg31xx.cpp | 40 ++++++++++++++++++++
5 files changed, 123 insertions(+), 7 deletions(-)
create mode 100644 clang/test/CXX/drs/cwg31xx.cpp
diff --git a/clang/test/CXX/drs/cwg26xx.cpp b/clang/test/CXX/drs/cwg26xx.cpp
index 5fe409a3b2905..7f99cd684e08e 100644
--- a/clang/test/CXX/drs/cwg26xx.cpp
+++ b/clang/test/CXX/drs/cwg26xx.cpp
@@ -267,6 +267,8 @@ void f() {
}
} // namespace cwg2654
+// cwg2660: na
+
namespace cwg2681 { // cwg2681: 17
#if __cplusplus >= 202002L
using size_t = decltype(sizeof(int));
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index ae5874ce3c46d..1d615ffa5a303 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected,cxx98 %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++14 -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++17 -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++20 -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected,since-cxx20 %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected,since-cxx20,since-cxx23 %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++2c -fexceptions -fcxx-exceptions -pedantic-errors -verify-directives -verify=expected,since-cxx20,since-cxx23,since-cxx26 %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,cxx98
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++14 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11,since-cxx14
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++17 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11,since-cxx14
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++20 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11,since-cxx14,since-cxx20
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11,since-cxx14,since-cxx20,since-cxx23
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++2c -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11,since-cxx14,since-cxx20,since-cxx23,since-cxx26
#if __cplusplus == 199711L
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
@@ -18,6 +18,25 @@
#endif
namespace std {
+#if __cplusplus >= 201103L
+using size_t = decltype(sizeof(0));
+template <typename T>
+struct initializer_list {
+ const T *p;
+ size_t n;
+
+ #if __cplusplus >= 201402L
+ constexpr
+ #endif
+ initializer_list(const T *p, size_t n);
+
+ #if __cplusplus >= 201402L
+ constexpr
+ #endif
+ const T* begin() const { return {}; };
+};
+#endif
+
#if __cplusplus >= 202002L
struct strong_ordering {
int n;
@@ -174,6 +193,40 @@ static_assert(!__is_layout_compatible(StructWithAnonUnion, StructWithAnonUnion3)
#endif
} // namespace cwg2759
+namespace cwg2765 { // cwg2765: partial
+static_assert(+"foo" == "foo", "");
+// expected-error at -1 {{static assertion expression is not an integral constant expression}}
+// expected-note at -2 {{comparison of addresses of potentially overlapping literals has unspecified value}}
+static_assert("xfoo" + 1 == "foo\0y", "");
+// expected-warning at -1 {{adding 'int' to a string does not append to the string}}
+// expected-note at -2 {{use array indexing to silence this warning}}
+// expected-error at -3 {{static assertion expression is not an integral constant expression}}
+// expected-note at -4 {{comparison of addresses of potentially overlapping literals has unspecified value}}
+static_assert("foo" + 0 != "bar", "");
+// expected-warning at -1 {{adding 'int' to a string does not append to the string}}
+// expected-note at -2 {{use array indexing to silence this warning}}
+// cxx98-error at -3 {{static assertion expression is not an integral constant expression}} FIXME
+static_assert((const char*)"foo" != "oo", "");
+// cxx98-error at -1 {{static assertion expression is not an integral constant expression}} FIXME
+
+#if __cplusplus >= 201103L
+constexpr const char *f() { return "foo"; }
+constexpr bool b2 = f() == f();
+// since-cxx11-error at -1 {{constexpr variable 'b2' must be initialized by a constant expression}}
+// since-cxx11-note at -2 {{comparison of addresses of potentially overlapping literals has unspecified value}}
+constexpr const char *p = f();
+constexpr bool b3 = p == p;
+#endif
+
+#if __cplusplus >= 201402L
+constexpr std::initializer_list<int *> il1 = { (int *)nullptr };
+constexpr std::initializer_list<unsigned long> il2 = { 0 };
+constexpr bool b7 = il1.begin() == (void *)il2.begin();
+// FIXME-error at -1 {{constexpr variable 'b2' must be initialized by a constant expression}}
+// FIXME-note at -2 {{address of a constexpr-unknown object cannot be used for comparison}}
+#endif
+} // namespace cwg2765
+
namespace cwg2770 { // cwg2770: 20 open 2023-07-14
#if __cplusplus >= 202002L
template<typename T>
diff --git a/clang/test/CXX/drs/cwg29xx.cpp b/clang/test/CXX/drs/cwg29xx.cpp
index 54f5547a1629d..165c2943b6b4a 100644
--- a/clang/test/CXX/drs/cwg29xx.cpp
+++ b/clang/test/CXX/drs/cwg29xx.cpp
@@ -175,3 +175,13 @@ constexpr U _ = nondeterministic(true);
} // namespace cwg2922
// cwg2947 is in cwg2947.cpp
+
+namespace cwg2966 { // cwg2966: 2.7
+#if __cplusplus >= 201103L
+static_assert(sizeof(decltype(nullptr)) == sizeof(void*), "");
+static_assert(alignof(decltype(nullptr)) == alignof(void*), "");
+#endif
+} // namespace cwg2966
+
+// cwg2983: na
+// cwg2992: na
diff --git a/clang/test/CXX/drs/cwg30xx.cpp b/clang/test/CXX/drs/cwg30xx.cpp
index 356c2cd68b4b7..a625acfb6f585 100644
--- a/clang/test/CXX/drs/cwg30xx.cpp
+++ b/clang/test/CXX/drs/cwg30xx.cpp
@@ -21,3 +21,14 @@ void f(
}
} // namespace cwg3005
+
+namespace cwg3035 { // cwg3035: no
+#if __cplusplus >= 201103L
+static union {
+ int x = [] { return 42; }();
+ // FIXME-error at -1 {{lambda expressions are not allowed in anonymous unions}}
+};
+#endif
+} // namespace cwg3035
+
+// cwg3058: na
diff --git a/clang/test/CXX/drs/cwg31xx.cpp b/clang/test/CXX/drs/cwg31xx.cpp
new file mode 100644
index 0000000000000..803ace4d06202
--- /dev/null
+++ b/clang/test/CXX/drs/cwg31xx.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -std=c++98 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,cxx98-11
+// RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,cxx98-11
+// RUN: %clang_cc1 -std=c++14 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx14
+// RUN: %clang_cc1 -std=c++17 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx14
+// RUN: %clang_cc1 -std=c++20 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx14
+// RUN: %clang_cc1 -std=c++23 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx14
+// RUN: %clang_cc1 -std=c++2c -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx14
+
+// cxx98-11-no-diagnostics
+
+namespace cwg3128 { // cwg3128: 2.7
+#if __cplusplus >= 201103L
+void f();
+static_assert(noexcept(noexcept(f())), "");
+#endif
+} // namespace cwg3128
+
+namespace cwg3151 { // cwg3151: 2.7
+#if __cplusplus >= 201402L
+auto lambda = []{};
+struct S : decltype(lambda) {};
+#endif
+} // namespace cwg3151
+
+namespace cwg3156 { // cwg3156: 3.5
+#if __cplusplus >= 201402L
+struct C { // #cwg3156-C
+ C(int) = delete; // #cwg3156-C-int
+ C(){};
+};
+
+int x = [b = C(3)](){ return 4; }();
+// since-cxx14-error at -1 {{functional-style cast from 'int' to 'C' uses deleted function}}
+// since-cxx14-note@#cwg3156-C-int {{candidate constructor has been explicitly deleted}}
+// since-cxx14-note@#cwg3156-C {{candidate constructor (the implicit copy constructor)}}
+// since-cxx14-note@#cwg3156-C {{candidate constructor (the implicit move constructor)}}
+#endif
+} // namespace cwg3156
+
+// cwg3172: na
More information about the cfe-commits
mailing list