Skip to content

Commit b21df4b

Browse files
authored
[Clang] prevent assertion failure by avoiding required literal type checking in C context (#101426)
Fixes #101304
1 parent 58964c8 commit b21df4b

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
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 checking required literal types in C context. (#GH101304).
159160

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

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8756,7 +8756,8 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
87568756
return;
87578757
}
87588758

8759-
if (NewVD->isConstexpr() && !T->isDependentType() &&
8759+
if (getLangOpts().CPlusPlus && NewVD->isConstexpr() &&
8760+
!T->isDependentType() &&
87608761
RequireLiteralType(NewVD->getLocation(), T,
87618762
diag::err_constexpr_var_non_literal)) {
87628763
NewVD->setInvalidDecl();

clang/test/Sema/constexpr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,6 @@ 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 {{variable has incomplete type 'const struct S9'}} \
362+
// expected-note {{forward declaration of 'struct S9'}}

0 commit comments

Comments
 (0)