[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 08:50:01 PDT 2026


================
@@ -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}}
----------------
Endilll wrote:

Those are examples from the Standard. My understanding is that arguments to the equality operator are different evaluations, and they end up pointing out to the same offset (of 0) of a (potentially) same backing array of those two initializer_lists, which are potentially non-unique objects.

Here are minutes of the Core discussion in Croydon. `b7` case is mentioned towards the end: https://wiki.isocpp.org/2026-03_Croydon:CoreWorkingGroup#CWG2765

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


More information about the cfe-commits mailing list