Skip to content

Commit 40c26ec

Browse files
committed
[clang][Interp] Fix diagnosing uninitialized ctor record arrays
Differential Revision: https://reviews.llvm.org/D143334
1 parent 2bca692 commit 40c26ec

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

clang/lib/AST/Interp/Interp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static bool CheckArrayInitialized(InterpState &S, CodePtr OpPC,
386386
size_t NumElems = CAT->getSize().getZExtValue();
387387
QualType ElemType = CAT->getElementType();
388388

389-
if (isa<RecordType>(ElemType.getTypePtr())) {
389+
if (ElemType->isRecordType()) {
390390
const Record *R = BasePtr.getElemRecord();
391391
for (size_t I = 0; I != NumElems; ++I) {
392392
Pointer ElemPtr = BasePtr.atIndex(I).narrow();

clang/test/AST/Interp/cxx20.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ static_assert(!b4); // ref-error {{not an integral constant expression}} \
138138
namespace UninitializedFields {
139139
class A {
140140
public:
141-
int a; // expected-note 2{{subobject declared here}} \
142-
// ref-note 2{{subobject declared here}}
141+
int a; // expected-note 3{{subobject declared here}} \
142+
// ref-note 3{{subobject declared here}}
143143
constexpr A() {}
144144
};
145145
constexpr A a; // expected-error {{must be initialized by a constant expression}} \
@@ -174,19 +174,15 @@ namespace UninitializedFields {
174174
// ref-error {{must be initialized by a constant expression}} \
175175
// ref-note {{subobject 'a' is not initialized}}
176176

177-
178-
// FIXME: These two are currently disabled because the array fields
179-
// cannot be initialized.
180-
#if 0
181177
class C3 {
182178
public:
183179
A a[2];
184180
constexpr C3() {}
185181
};
186182
constexpr C3 c3; // expected-error {{must be initialized by a constant expression}} \
187-
// expected-note {{subobject of type 'int' is not initialized}} \
183+
// expected-note {{subobject 'a' is not initialized}} \
188184
// ref-error {{must be initialized by a constant expression}} \
189-
// ref-note {{subobject of type 'int' is not initialized}}
185+
// ref-note {{subobject 'a' is not initialized}}
190186

191187
class C4 {
192188
public:
@@ -195,10 +191,9 @@ namespace UninitializedFields {
195191
constexpr C4(){}
196192
};
197193
constexpr C4 c4; // expected-error {{must be initialized by a constant expression}} \
198-
// expected-note {{subobject of type 'bool' is not initialized}} \
194+
// expected-note {{subobject 'B' is not initialized}} \
199195
// ref-error {{must be initialized by a constant expression}} \
200-
// ref-note {{subobject of type 'bool' is not initialized}}
201-
#endif
196+
// ref-note {{subobject 'B' is not initialized}}
202197
};
203198

204199
namespace ConstThis {

0 commit comments

Comments
 (0)