[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 27 09:09:14 PST 2023


================
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -std=c++2c -verify %s
+
+namespace dr2798 { // dr2798: 17 drafting
+#if __cpp_static_assert >= 202306
+struct string {
+    constexpr string() {
+        data_ = new char[6]();
+        __builtin_memcpy(data_, "Hello", 5);
+        data_[5] = 0;
+    }
+    constexpr ~string() {
+        delete[] data_;
+    }
+    constexpr unsigned long size() const {
+        return 5;
+    };
+    constexpr const char* data() const {
+        return data_;
+    }
+
+    char* data_;
+};
+struct X {
+    string s;
+};
+consteval X f() { return {}; }
+
+static_assert(false, f().s); // expected-error {{static assertion failed: Hello}}
----------------
Endilll wrote:

I find `-1` form to work better for longer messages (removing incentive to shorten them).
More importantly, it explains by example how to use `@` in expected directives, making it more accessible for people to list notes below the error (which matches compiler's console output), instead of simply putting `expected-note` wherever it appears.

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


More information about the cfe-commits mailing list