Skip to content

Commit c972795

Browse files
committed
[Clang] prevent assertion failure by avoiding casts on type declarations that require complete types
1 parent 74f9579 commit c972795

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ Bug Fixes in This Version
156156

157157
- Fixed the definition of ``ATOMIC_FLAG_INIT`` in ``<stdatomic.h>`` so it can
158158
be used in C++.
159+
- Fixed a failed assertion when casting type declarations that require complete types. (#GH101304).
159160

160161
Bug Fixes to Compiler Builtins
161162
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9267,14 +9267,14 @@ bool Sema::RequireLiteralType(SourceLocation Loc, QualType T,
92679267
if (!RT)
92689268
return true;
92699269

9270-
const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
9271-
92729270
// A partially-defined class type can't be a literal type, because a literal
92739271
// class type must have a trivial destructor (which can't be checked until
92749272
// the class definition is complete).
92759273
if (RequireCompleteType(Loc, ElemType, diag::note_non_literal_incomplete, T))
92769274
return true;
92779275

9276+
const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
9277+
92789278
// [expr.prim.lambda]p3:
92799279
// This class type is [not] a literal type.
92809280
if (RD->isLambda() && !getLangOpts().CPlusPlus17) {

clang/test/Sema/constexpr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,7 @@ void infsNaNs() {
357357
constexpr double db5 = LD_SNAN; // expected-error {{constexpr initializer evaluates to nan which is not exactly representable in type 'const double'}}
358358
constexpr double db6 = INF;
359359
}
360+
361+
constexpr struct S9 s9 = { }; // expected-error {{constexpr variable cannot have non-literal type 'const struct S9'}} \
362+
// expected-note {{incomplete type 'const struct S9' is not a literal type}} \
363+
// expected-note {{forward declaration of 'struct S9'}}

0 commit comments

Comments
 (0)