[clang] 90d921f - [clang][Interp] Handle record initialization via CastExpr

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 2 01:09:00 PST 2023


Author: Timm Bäder
Date: 2023-03-02T10:08:41+01:00
New Revision: 90d921fa1f71ff219cb42682d123a4c3922af71e

URL: https://github.com/llvm/llvm-project/commit/90d921fa1f71ff219cb42682d123a4c3922af71e
DIFF: https://github.com/llvm/llvm-project/commit/90d921fa1f71ff219cb42682d123a4c3922af71e.diff

LOG: [clang][Interp] Handle record initialization via CastExpr

Differential Revision: https://reviews.llvm.org/D140808

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 1f5c4f6e1cd1..1740c5dd939e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1410,6 +1410,8 @@ bool ByteCodeExprGen<Emitter>::visitRecordInitializer(const Expr *Initializer) {
     return this->VisitCallExpr(CE);
   } 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;

diff  --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp
index fcf4b578d7d3..c0bfdeb090eb 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -88,6 +88,10 @@ constexpr Ints2 ints22; // expected-error {{without a user-provided default cons
                         // 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;


        


More information about the cfe-commits mailing list