[clang] [clang-tools-extra] [Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit (PR #95580)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 19 05:39:07 PDT 2024
================
@@ -9392,6 +9392,57 @@ ExprResult InitializationSequence::Perform(Sema &S,
// Wrap it in a construction of a std::initializer_list<T>.
CurInit = new (S.Context) CXXStdInitializerListExpr(Step->Type, MTE);
+ if (!Step->Type->isDependentType()) {
+ assert(S.isCompleteType(CurInit.get()->getExprLoc(), Step->Type,
+ Sema::CompleteTypeKind::Normal) &&
+ "std::initializer_list<E> incomplete when used during "
+ "initialization");
+ QualType ElementType;
+ [[maybe_unused]] bool IsStdInitializerList =
+ S.isStdInitializerList(Step->Type, &ElementType);
+ assert(IsStdInitializerList &&
+ "StdInitializerList step to non-std::initializer_list");
+ RecordDecl *Record = Step->Type->castAs<RecordType>()->getDecl();
+
+ auto InvalidType = [&] {
+ S.Diag(Record->getLocation(),
+ diag::err_std_initializer_list_malformed)
+ << Step->Type.getUnqualifiedType();
+ return ExprError();
+ };
+
+ // FIXME: What if the initializer_list type has base classes, etc?
----------------
Sirraide wrote:
We should check for that here. I don’t think there is a point in allowing `std::initializer_list` have bases or be polymorphic.
https://github.com/llvm/llvm-project/pull/95580
More information about the cfe-commits
mailing list