[clang] [clang][Sema] Guard diagnose_if value-dependent conditions (PR #197647)

via cfe-commits cfe-commits at lists.llvm.org
Fri May 15 05:24:26 PDT 2026


TPPPP72 wrote:

Instead of bypassing the assertion, we should consider why the incorrect attribute is being generated here.

So I think this is a correct fix:

```diff
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 55b6cbcbba57..70f948fd77f9 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7508,6 +7508,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
   if (S.checkCommonAttributeFeatures(D, AL, MustDelayArgs))
     return;

+  if (S.getDiagnostics().hasFatalErrorOccurred() && AL.getNumArgs() > 0)
+    return;
+
   if (MustDelayArgs) {
     AL.handleAttrWithDelayedArgs(S, D);
     return;
```

When a fatal error occurs and there is an incorrect expression that might be evaluated, we should stop handling its Attr.

@AaronBallman CC

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


More information about the cfe-commits mailing list