[PATCH] D134020: [clang][Interp] Handle enums

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 16 23:03:01 PDT 2022


tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:861
+
+    return this->emitConst(T, getIntWidth(ECD->getType()), ECD->getInitVal(),
+                           E);
----------------
tbaeder wrote:
> shafik wrote:
> > If I check out `IntExprEvaluator::CheckReferenceDecl(...)` it is checking the sign and width match between the expression and the `EnumConstantDecl`. I am guessing we need to do that here as well?
> I'm having a hard time trying to cause that code to trigger.  e.g. in
> 
> ```
> enum Foo : unsigned int {
>   A = -1,
> };
> static_assert(A == -1);
> ```
> Both with the new and current interpreter, I get a`-Wc++11-narrowing` error by default, and the assertion works if I pass `-Wno-c++11-narrowing`.
Reading the code again, this seems to just compute a new value to not trigger assertions in `Success()`. Since those assertions don't exist in the new interpreter, the special casing shouldn't be needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020



More information about the cfe-commits mailing list