[clang] [Clang] prevent assertion failure by avoiding casts on type declarations that require complete types (PR #101426)
Mital Ashok via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 1 01:48:28 PDT 2024
================
@@ -9267,14 +9267,14 @@ bool Sema::RequireLiteralType(SourceLocation Loc, QualType T,
if (!RT)
return true;
- const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
-
// A partially-defined class type can't be a literal type, because a literal
// class type must have a trivial destructor (which can't be checked until
// the class definition is complete).
if (RequireCompleteType(Loc, ElemType, diag::note_non_literal_incomplete, T))
return true;
+ const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
----------------
MitalAshok wrote:
You don't require a literal type for C23 `constexpr`, so part of the condition should be `if (getLangOpts().CPlusPlus && NewVD->isConstexpr() && ... && RequireLiteralType`, just like how `CheckC23ConstexprVarType` is gated behind `getLangOpts().C23 &&`. And add an assertion for `getLangOpts().CPlusPlus` in RequireLiteralType for good measure.
The declaration will be marked invalid later by the same code that marks `/*!constexpr*/ struct Incomplete s = {};` invalid.
https://github.com/llvm/llvm-project/pull/101426
More information about the cfe-commits
mailing list