[PATCH] D145860: [clang][Interp] Fix initializing fields after base class members
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 3 06:58:41 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG056042d21b72: [clang][Interp] Fix initializing fields after base class members (authored by tbaeder).
Changed prior to commit:
https://reviews.llvm.org/D145860?vs=504408&id=510487#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145860/new/
https://reviews.llvm.org/D145860
Files:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/cxx20.cpp
Index: clang/test/AST/Interp/cxx20.cpp
===================================================================
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -583,3 +583,20 @@
constexpr Outer O;
static_assert(O.bar() == 12);
}
+
+namespace BaseAndFieldInit {
+ struct A {
+ int a;
+ };
+
+ struct B : A {
+ int b;
+ };
+
+ struct C : B {
+ int c;
+ };
+
+ constexpr C c = {1,2,3};
+ static_assert(c.a == 1 && c.b == 2 && c.c == 3);
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1384,6 +1384,7 @@
if (!this->emitPopPtr(Initializer))
return false;
+ ++InitIndex;
} else {
// Initializer for a direct base class.
if (const Record::Base *B = R->getBase(Init->getType())) {
@@ -1395,6 +1396,8 @@
if (!this->emitPopPtr(Initializer))
return false;
+ // Base initializers don't increase InitIndex, since they don't count
+ // into the Record's fields.
} else {
const Record::Field *FieldToInit = R->getField(InitIndex);
// Non-primitive case. Get a pointer to the field-to-initialize
@@ -1407,9 +1410,9 @@
if (!this->emitPopPtr(Initializer))
return false;
+ ++InitIndex;
}
}
- ++InitIndex;
}
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145860.510487.patch
Type: text/x-patch
Size: 1509 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230403/dd64e103/attachment-0001.bin>
More information about the cfe-commits
mailing list