[PATCH] D140808: [clang][Interp] Handle record initialization via CastExpr

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 31 09:31:12 PST 2022


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In particular, via a `CXXFunctionalCastExpr`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140808

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===================================================================
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -88,6 +88,10 @@
                         // expected-error {{must be initialized by a constant expression}} \
                         // ref-error {{without a user-provided default constructor}}
 
+constexpr Ints2 I2 = Ints2{12, 25};
+static_assert(I2.a == 12, "");
+static_assert(I2.b == 25, "");
+
 class C {
   public:
     int a;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1318,6 +1318,8 @@
     }
   } else if (const auto *DIE = dyn_cast<CXXDefaultInitExpr>(Initializer)) {
     return this->visitInitializer(DIE->getExpr());
+  } else if (const auto *CE = dyn_cast<CastExpr>(Initializer)) {
+    return this->visitInitializer(CE->getSubExpr());
   }
 
   return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140808.485781.patch
Type: text/x-patch
Size: 1031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221231/af091c29/attachment.bin>


More information about the cfe-commits mailing list