https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/101426
>From 314766a02c096bd5c867383b55e75451961af231 Mon Sep 17 00:00:00 2001 From: Oleksandr T <oleksandr.taras...@outlook.com> Date: Thu, 1 Aug 2024 13:00:04 +0300 Subject: [PATCH] [Clang] prevent assertion failure by avoiding required literal type checking in C context --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaDecl.cpp | 3 ++- clang/test/Sema/constexpr.c | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3c2e0282d1c72..1a25d270e9509 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'}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits