================ @@ -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'}} ---------------- jj-marr wrote:
Perhaps it should say "during constant evaluation". Both `constexpr` and `consteval` functions can be constant evaluated (i.e. evaluated at compile-time), but it's also possible for a `constexpr` function to be used at runtime, in which case the assertion would _not_ be triggered. https://github.com/llvm/llvm-project/pull/130458 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits