[PATCH] D84637: [AST] Enhance the const expression evaluator to support error-dependent exprs.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 30 16:32:54 PDT 2020


rsmith added inline comments.


================
Comment at: clang/lib/AST/ExprConstant.cpp:4876
+        assert(E->containsErrors());
+        return ESR_Failed;
+      }
----------------
This should not result in failure when checking for a potential constant expression; if an expression contains errors we should treat it as being potentially constant, because (depending on how the error is resolved) it could be constant. We should `noteSideEffect()` here and continue unless it asks us to stop.

I guess I'm thinking of something like:

```
if (E->isValueDependent()) {
  if (E->noteSideEffect())
    return ESR_Succeeded;
  assert(E->containsErrors() && "non-value-dependent expression should never reach valid value-dependent expression");
  return ESR_Failed;
}
```

It might also be interesting to produce a diagnostic saying that evaluation failed due to a prior error on the `ESR_Failed` path; we could special-case that diagnostic when we diagnose expressions that are supposed to be constant but aren't in order to fully suppress the follow-on diagnostic.

(Same comment on all the below instances of this same pattern; adding a helper function for the above seems warranted.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84637/new/

https://reviews.llvm.org/D84637



More information about the cfe-commits mailing list