Skip to content

Commit 430b254

Browse files
authored
[Clang] Do not attempt to access the DefinitionData of an incomplete type (#99998)
We were asserting here because we were trying to access the `DefinitionData` of an incomplete type in the `Visit` lambda in `CXXRecordDecl::hasSubobjectAtOffsetZeroOfEmptyBaseType`. The code that creates `FieldDecl`s always marks them as invalid if their type is incomplete, so checking whether the field decl whose type we’re about to look at is invalid fixes this issue. Fixes #99868.
1 parent 229e118 commit 430b254

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ Bug Fixes to C++ Support
11051105
- Clang now diagnoses explicit object parameters in member pointers and other contexts where they should not appear.
11061106
Fixes (#GH85992).
11071107
- Fixed a crash-on-invalid bug involving extraneous template parameter with concept substitution. (#GH73885)
1108+
- Fixed assertion failure by skipping the analysis of an invalid field declaration. (#GH99868)
11081109

11091110
Bug Fixes to AST Handling
11101111
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/DeclCXX.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ bool CXXRecordDecl::hasSubobjectAtOffsetZeroOfEmptyBaseType(
675675
if (!IsFirstField && !FD->isZeroSize(Ctx))
676676
continue;
677677

678+
if (FD->isInvalidDecl())
679+
continue;
680+
678681
// -- If X is n array type, [visit the element type]
679682
QualType T = Ctx.getBaseElementType(FD->getType());
680683
if (auto *RD = T->getAsCXXRecordDecl())

clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ X1<int, X1a> inst_x1a;
3838
X1<long, X1b> inst_x1b;
3939
X1<short, X1c> inst_x1c;
4040
X1<short, X1d> inst_x1d; // expected-error{{template template argument has different template parameters than its corresponding template template paramete}}
41+
42+
template <int> class X2; // expected-note{{template is declared here}} \
43+
// expected-note{{template is declared here}}
44+
class X3 : X2<1> {}; // expected-error{{implicit instantiation of undefined template 'X2<1>'}}
45+
46+
template <int> class X4 : X3 {
47+
struct {
48+
X2<1> e; // expected-error{{implicit instantiation of undefined template 'X2<1>'}}
49+
} f;
50+
};

0 commit comments

Comments
 (0)