[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 10 09:37:41 PDT 2025
================
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_plus %s
+
+#ifdef __ASSERT_FUNCTION
+#undef __ASSERT_FUNCTION
+#endif
+extern "C" void __assert_fail(const char*, const char*, unsigned, const char*);
+
+#define assert(cond) \
+ ((cond) ? (void)0 : __assert_fail(#cond, __FILE__, __LINE__, __func__))
+
+consteval int square(int x) {
+ int result = x * x;
+ assert(result == 42); // expected-note {{assertion failed in consteval context: 'result == 42'}}
----------------
Fznamznon wrote:
Does the improvement also work for constexpr function, like
```
constexpr int square(int x) {
int result = x * x;
assert(result == 42);
return result;
}
void test() {
constexpr auto val = square(2);
}
```
If yes (I would expect it to), should we the note say something like "assertion failed during constexpr evaluation"?
https://github.com/llvm/llvm-project/pull/130458
More information about the cfe-commits
mailing list