[PATCH] D131874: [Clang] Tighten restrictions on enum out of range diagnostic to avoid constant initialization

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 16 06:42:38 PDT 2022


aaron.ballman added inline comments.


================
Comment at: clang/lib/AST/ExprConstant.cpp:13547-13551
+      if (auto ValD = Info.EvaluatingDecl.dyn_cast<const ValueDecl *>()) {
+        const VarDecl *VD = dyn_cast_or_null<VarDecl>(ValD);
+        if (VD && !VD->isConstexpr())
+          NotConstexprVar = true;
+      }
----------------
shafik wrote:
> shafik wrote:
> > aaron.ballman wrote:
> > > This seems to be equivalent unless I'm misunderstanding something about the member dyn_cast.
> > I think the problem is that `PointerUnion` requires that it be one of the static types it was defined with and in this case that is `const ValueDecl *, const Expr *` but maybe I am missing something.
> It looks like the big difference is that in `doCastIfPossible(...)` we end up calling `Self::isPossible(f)` which ends up in `PointerUnion::isPossible...)` which uses `FirstIndexOfType` and if the template arguments don't contain the type then it fail.
Whelp, TIL!

Then I guess I'd go with:

`if (const auto *VD = dyn_cast_or_null<VarDecl>(Info.EvaluatingDecl.dyn_cast<const ValueDecl *>))`


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

https://reviews.llvm.org/D131874



More information about the cfe-commits mailing list