[clang] [clang] Add tests for some of CWG issues resolved in Croydon (2026-03) (PR #189299)

via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 29 20:19:38 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)

<details>
<summary>Changes</summary>

This PR adds test for the following Core issues:
- [CWG2765](https://cplusplus.github.io/CWG/issues/2765.html) "Address comparisons between potentially non-unique objects during constant evaluation";
- [CWG2966](https://cplusplus.github.io/CWG/issues/2966.html) "Alignment and value representation of `std::nullptr_t`";
- [CWG3035](https://cplusplus.github.io/CWG/issues/3035.html) "Lambda expressions in anonymous unions";
- [CWG3128](https://cplusplus.github.io/CWG/issues/3128.html) "Potentially-throwing unevaluated operands";
- [CWG3151](https://cplusplus.github.io/CWG/issues/3151.html) "Closure types that are `final`";
- [CWG3156](https://cplusplus.github.io/CWG/issues/3156.html) "Handling of deleted functions in unevaluated _lambda-captures_".

Additionally, the following Core issues are marked as "N/A", because I don't think they can be tested:
- [CWG2660](https://cplusplus.github.io/CWG/issues/2660.html) "Confusing term "this parameter"";
- [CWG2983](https://cplusplus.github.io/CWG/issues/2983.html) "Non-type template parameters are not variables";
- [CWG2992](https://cplusplus.github.io/CWG/issues/2992.html) "Labels do not have names";
- [CWG3058](https://cplusplus.github.io/CWG/issues/3058.html) ""Program point" is not defined";
- [CWG3172](https://cplusplus.github.io/CWG/issues/3172.html) "Reference to wrong placeholder".

-------

[P4160R0](https://wiki.isocpp.org/uploads/2026-03_Croydon-StrawPolls_-_p4160r0.html) "Core Language Working Group "ready" Issues for the March, 2026 meeting" is what was voted in, but doesn't seem to be uploaded to publicly accessible WG21 paper system. However, individual Core issues pages linked above contain up-to-date resolutions.

---
Full diff: https://github.com/llvm/llvm-project/pull/189299.diff


5 Files Affected:

- (modified) clang/test/CXX/drs/cwg26xx.cpp (+2) 
- (modified) clang/test/CXX/drs/cwg27xx.cpp (+60-7) 
- (modified) clang/test/CXX/drs/cwg29xx.cpp (+10) 
- (modified) clang/test/CXX/drs/cwg30xx.cpp (+11) 
- (added) clang/test/CXX/drs/cwg31xx.cpp (+40) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/189299


More information about the cfe-commits mailing list