[clang] b21df4b - [Clang] prevent assertion failure by avoiding required literal type checking in C context (#101426)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 2 05:42:08 PDT 2024
Author: Oleksandr T.
Date: 2024-08-02T08:42:04-04:00
New Revision: b21df4b1cf718e48259133054caa2ce5966358e9
URL: https://github.com/llvm/llvm-project/commit/b21df4b1cf718e48259133054caa2ce5966358e9
DIFF: https://github.com/llvm/llvm-project/commit/b21df4b1cf718e48259133054caa2ce5966358e9.diff
LOG: [Clang] prevent assertion failure by avoiding required literal type checking in C context (#101426)
Fixes #101304
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/constexpr.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 866adefd5d3c4..efa01bfc92cf6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a3f8126a9f915..4fea38d1b02a9 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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();
diff --git a/clang/test/Sema/constexpr.c b/clang/test/Sema/constexpr.c
index 8286cd2107d2f..5ea2ac24a503a 100644
--- a/clang/test/Sema/constexpr.c
+++ b/clang/test/Sema/constexpr.c
@@ -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'}}
More information about the cfe-commits
mailing list