Skip to content

Commit

Permalink
[Clang] prevent assertion failure by avoiding required literal type c…
Browse files Browse the repository at this point in the history
…hecking in C context (#101426)

Fixes #101304
  • Loading branch information
a-tarasyuk authored Aug 2, 2024
1 parent 58964c8 commit b21df4b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Bug Fixes in This Version

- Fixed the definition of ``ATOMIC_FLAG_INIT`` in ``<stdatomic.h>`` so it can
be used in C++.
- Fixed a failed assertion when checking required literal types in C context. (#GH101304).

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8756,7 +8756,8 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
return;
}

if (NewVD->isConstexpr() && !T->isDependentType() &&
if (getLangOpts().CPlusPlus && NewVD->isConstexpr() &&
!T->isDependentType() &&
RequireLiteralType(NewVD->getLocation(), T,
diag::err_constexpr_var_non_literal)) {
NewVD->setInvalidDecl();
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Sema/constexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,6 @@ void infsNaNs() {
constexpr double db5 = LD_SNAN; // expected-error {{constexpr initializer evaluates to nan which is not exactly representable in type 'const double'}}
constexpr double db6 = INF;
}

constexpr struct S9 s9 = { }; // expected-error {{variable has incomplete type 'const struct S9'}} \
// expected-note {{forward declaration of 'struct S9'}}

0 comments on commit b21df4b

Please sign in to comment.