[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 27 09:41:29 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}}
----------------
AaronBallman wrote:
I think it's a subjective decision whether to go on the same line or a nearby line; we have no requirements either way. But I don't think we should write tests as a way to show examples of how to use various diagnostic verifier features; documentation should be written instead and the tests should use whatever is most clear to folks reading them.
(FWIW, what I find easiest to read tends to be:
```
void foo(); // #decl
...
int foo; // #note1
...
foo(); // expected-error {{something is wrong; did you mean to do it the right way?}} \
expected-note@#note1 {{note text here}} \
expected-note@#decl {{declared here}}
```
but I realize that not everyone will agree with that.)
https://github.com/llvm/llvm-project/pull/73234
More information about the cfe-commits
mailing list