[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 10 16:51:31 PDT 2025


================
@@ -8361,6 +8361,17 @@ class ExprEvaluatorBase
         return false;
     }
 
+    // If an assertion fails during constant evaluation, give a specific note explaining that
+    if (FD->getName() == "__assert_fail") {
----------------
Sirraide wrote:

> Maybe we can instead check if
> 
> * `PP.getImmediateMacroName(E->getBeginLoc())` is a macro call assert
> * `FD->getName()` contains the string "assert"
> 
> It might be less brittle

Yeah, I like the idea of checking for the `assert()` macro so we don’t have to concern ourselves with how every C standard library implements this.

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


More information about the cfe-commits mailing list