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

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 15 14:09:48 PDT 2022


shafik 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:
> 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.


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

https://reviews.llvm.org/D131874



More information about the cfe-commits mailing list