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

via cfe-commits cfe-commits at lists.llvm.org
Sat May 10 01:14:45 PDT 2025


================
@@ -5975,9 +5975,15 @@ static bool CheckConstexprFunction(EvalInfo &Info, SourceLocation CallLoc,
                                         Definition->hasAttr<MSConstexprAttr>())))
     return true;
 
-  if (Info.getLangOpts().CPlusPlus11) {
-    const FunctionDecl *DiagDecl = Definition ? Definition : Declaration;
+  const FunctionDecl *DiagDecl = Definition ? Definition : Declaration;  
+  if (CallLoc.isMacroID() && (DiagDecl->getName() == "__assert_rtn" ||
----------------
cor3ntin wrote:

You need to check that the Decl actually have a name - this might not be the case for an operator, a constructor, etc

```cpp
if(CallLoc.isMacroID() && DiagDecl->getIdentifier()) {
     StringRef Name = DiagDecl->getName();
     if (Name == "__assert_fail" || ... )  {
                  ....
     } 
}
```

This is what is causing the test failures


 

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


More information about the cfe-commits mailing list