Index: lib/AST/ASTContext.cpp =================================================================== --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -1511,6 +1511,8 @@ QualType BaseT = getBaseElementType(T); if (T->isFunctionType()) Align = getTypeInfoImpl(T.getTypePtr()).Align; + // "Incomplete" rather than "indefinite" since sizeless types do not have + // a meaningful alignment. Sema should reject attempts to specify one. else if (!BaseT->isIncompleteType()) { // Adjust alignments of declarations with array type by the // large-array alignment on the target. @@ -1636,6 +1638,8 @@ // If we have an (array of) complete type, we're done. T = getBaseElementType(T); + // "Incomplete" rather than "indefinite" since sizeless types do not have + // a meaningful alignment. Sema should reject attempts to specify one. if (!T->isIncompleteType()) return getTypeAlign(T); @@ -2917,6 +2921,8 @@ const llvm::APInt &ArySizeIn, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const { + // "Incomplete" rather than "indefinite" since arrays of sizeless type + // are not allowed. assert((EltTy->isDependentType() || EltTy->isIncompleteType() || EltTy->isConstantSizeType()) && "Constant array of VLAs is illegal!"); Index: lib/AST/ExprConstant.cpp =================================================================== --- lib/AST/ExprConstant.cpp +++ lib/AST/ExprConstant.cpp @@ -1931,6 +1931,8 @@ if (Decl && isa(Decl)) { QualType Ty = Decl->getType(); if (Ty->isArrayType()) + // "Complete" and "definite" are the same here, since arrays of sizeless + // type are not allowed. return Ty->isIncompleteType() || Decl->getASTContext().getTypeSize(Ty) == 0; } @@ -7660,6 +7662,8 @@ bool DetermineForCompleteObject = refersToCompleteObject(LVal); auto CheckedHandleSizeof = [&](QualType Ty, CharUnits &Result) { + // "Incomplete" rather than "indefinite" since sizeof cannot be applied + // to sizeless types. if (Ty.isNull() || Ty->isIncompleteType() || Ty->isFunctionType()) return false; return HandleSizeof(Info, ExprLoc, Ty, Result); @@ -8114,6 +8118,9 @@ QualType PointeeType = E->getArg(1)->IgnoreImpCasts()->getType()-> castAs()->getPointeeType(); + // "Incomplete" rather than "indefinite" since sizeless types do + // not have a meaningful alignment, and so cannot guarantee atomicity + // for even a fixed-size prefix. if (!PointeeType->isIncompleteType() && Info.Ctx.getTypeAlignInChars(PointeeType) >= Size) { // OK, we will inline operations on this object. Index: lib/AST/Type.cpp =================================================================== --- lib/AST/Type.cpp +++ lib/AST/Type.cpp @@ -2305,6 +2305,9 @@ // -- a scalar type; or // As an extension, Clang treats vector types and complex types as // literal types. + // + // Sizeless types are not treated as literal types since sizeless objects + // cannot usefully be created at compile time. if (BaseTy->isScalarType() || BaseTy->isVectorType() || BaseTy->isAnyComplexType()) return true; @@ -2354,6 +2357,10 @@ // Return false for incomplete types after skipping any incomplete array // types which are expressly allowed by the standard and thus our API. + // + // We do not treat sizeless types as standard layout, since the lack of + // a computable size makes them somewhat special. There's no strong reason + // either way though. if (BaseTy->isIncompleteType()) return false; Index: lib/Sema/Sema.cpp =================================================================== --- lib/Sema/Sema.cpp +++ lib/Sema/Sema.cpp @@ -1046,6 +1046,9 @@ QualType T = Context.getConstantArrayType(ArrayT->getElementType(), One, ArrayType::Normal, 0); VD->setType(T); + // "Complete" rather than "definite" because tentative definitions + // make no sense for sizeless types. Variables of sizeless type + // can never be global anyway. } else if (RequireCompleteType(VD->getLocation(), VD->getType(), diag::err_tentative_def_incomplete_type)) VD->setInvalidDecl(); Index: lib/Sema/SemaCXXScopeSpec.cpp =================================================================== --- lib/Sema/SemaCXXScopeSpec.cpp +++ lib/Sema/SemaCXXScopeSpec.cpp @@ -220,6 +220,9 @@ if (loc.isInvalid()) loc = SS.getRange().getBegin(); // The type must be complete. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures, and sizeless enums make no sense. if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec, SS.getRange())) { SS.SetInvalid(SS.getRange()); Index: lib/Sema/SemaCast.cpp =================================================================== --- lib/Sema/SemaCast.cpp +++ lib/Sema/SemaCast.cpp @@ -642,6 +642,8 @@ if (DestPointee->isVoidType()) { assert(DestPointer && "Reference to void is not possible"); } else if (DestRecord) { + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (Self.RequireCompleteType(OpRange.getBegin(), DestPointee, diag::err_bad_dynamic_cast_incomplete, DestRange)) { @@ -687,6 +689,8 @@ const RecordType *SrcRecord = SrcPointee->getAs(); if (SrcRecord) { + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (Self.RequireCompleteType(OpRange.getBegin(), SrcPointee, diag::err_bad_dynamic_cast_incomplete, SrcExpr.get())) { @@ -1305,6 +1309,9 @@ QualType OrigDestType, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath) { // We can only work with complete types. But don't complain if it doesn't work + // + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (!Self.isCompleteType(OpRange.getBegin(), SrcType) || !Self.isCompleteType(OpRange.getBegin(), DestType)) return TC_NotApplicable; @@ -1535,6 +1542,8 @@ SourceRange OpRange, unsigned &msg, CastKind &Kind, bool ListInitialization) { if (DestType->isRecordType()) { + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (Self.RequireCompleteType(OpRange.getBegin(), DestType, diag::err_bad_dynamic_cast_incomplete) || Self.RequireNonAbstractType(OpRange.getBegin(), DestType, @@ -2438,6 +2447,8 @@ } } + // "Complete" rather than "definite" because there's no point casting + // sizeless types. if (Self.RequireCompleteType(OpRange.getBegin(), DestType, diag::err_typecheck_cast_to_incomplete)) { SrcExpr = ExprError(); Index: lib/Sema/SemaChecking.cpp =================================================================== --- lib/Sema/SemaChecking.cpp +++ lib/Sema/SemaChecking.cpp @@ -3182,6 +3182,8 @@ << IsC11 << Ptr->getType() << Ptr->getSourceRange(); return ExprError(); } + // "Complete" rather than "definite" because pointer arithmetic on + // sizeless types is not well-formed. if (IsC11 && ValType->isPointerType() && RequireCompleteType(Ptr->getLocStart(), ValType->getPointeeType(), diag::err_incomplete_type)) { @@ -7565,6 +7567,8 @@ if (const UnaryOperator *UnaryOp = dyn_cast(Dest)) if (UnaryOp->getOpcode() == UO_AddrOf) ActionIdx = 1; // If its an address-of operator, just remove it. + // "Incomplete" rather than "indefinite" since we can't compute + // the size of sizeless types. if (!PointeeTy->isIncompleteType() && (Context.getTypeSize(PointeeTy) == Context.getCharWidth())) ActionIdx = 2; // If the pointee's size is sizeof(char), @@ -11088,6 +11092,8 @@ // If the destination has alignment 1, we're done. QualType DestPointee = DestPtr->getPointeeType(); + // "Incomplete" rather than "indefinite" since sizeless types do not have + // a meaningful alignment, and we should reject attempts to specify one. if (DestPointee->isIncompleteType()) return; CharUnits DestAlign = Context.getTypeAlignInChars(DestPointee); if (DestAlign.isOne()) return; @@ -12569,6 +12575,8 @@ if (isa(Op)) { auto MA = std::find(MisalignedMembers.begin(), MisalignedMembers.end(), MisalignedMember(Op)); + // "Incomplete" rather than "indefinite" since sizeless types do not have + // a meaningful alignment, and we should reject attempts to specify one. if (MA != MisalignedMembers.end() && (T->isIntegerType() || (T->isPointerType() && (T->getPointeeType()->isIncompleteType() || Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -4451,6 +4451,9 @@ // If expression's type is CXXRecordDecl, it may overload the function // call operator, so we check if it does and add them as candidates. // A complete type is needed to lookup for member function call operators. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (isCompleteType(Loc, NakedFn->getType())) { DeclarationName OpName = Context.DeclarationNames .getCXXOperatorName(OO_Call); Index: lib/Sema/SemaCoroutine.cpp =================================================================== --- lib/Sema/SemaCoroutine.cpp +++ lib/Sema/SemaCoroutine.cpp @@ -109,6 +109,8 @@ S.CheckTemplateIdType(TemplateName(CoroTraits), KwLoc, Args); if (CoroTrait.isNull()) return QualType(); + // "Complete" and "definite" are the same here, since std::coroutine_traits + // is never sizeless. if (S.RequireCompleteType(KwLoc, CoroTrait, diag::err_coroutine_type_missing_specialization)) return QualType(); @@ -143,6 +145,8 @@ << buildElaboratedType(); return QualType(); } + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (S.RequireCompleteType(FuncLoc, buildElaboratedType(), diag::err_coroutine_promise_type_incomplete)) return QualType(); @@ -187,6 +191,8 @@ S.CheckTemplateIdType(TemplateName(CoroHandle), Loc, Args); if (CoroHandleType.isNull()) return QualType(); + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (S.RequireCompleteType(Loc, CoroHandleType, diag::err_coroutine_type_missing_specialization)) return QualType(); @@ -876,6 +882,9 @@ if (!OperatorDelete) { // Look for a global declaration. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. const bool CanProvideSize = S.isCompleteType(Loc, PromiseType); const bool Overaligned = false; OperatorDelete = S.FindUsualDeallocationFunction(Loc, CanProvideSize, @@ -1052,6 +1061,8 @@ "cannot make statement while the promise type is dependent"); QualType PromiseType = Fn.CoroutinePromise->getType(); + // "Complete" rather than "definite" because we do not (yet?) want to + // support sizeless promise types. if (S.RequireCompleteType(Loc, PromiseType, diag::err_incomplete_type)) return false; Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -4921,6 +4921,8 @@ Chain.push_back(Anon); RecordDecl *RecordDef = Record->getDefinition(); + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (RequireCompleteType(Anon->getLocation(), RecTy, diag::err_field_incomplete) || InjectAnonymousStructOrUnionMembers(*this, S, CurContext, RecordDef, @@ -11143,6 +11145,8 @@ if (!Var->isInvalidDecl()) { if (const IncompleteArrayType *ArrayT = Context.getAsIncompleteArrayType(Type)) { + // "Complete" and "definite" are the same here, since arrays + // of sizeless type are not allowed. if (RequireCompleteType(Var->getLocation(), ArrayT->getElementType(), diag::err_illegal_decl_array_incomplete_type)) @@ -11158,6 +11162,9 @@ // an error and we do not invalidate the static declaration. // NOTE: to avoid multiple warnings, only check the first declaration. if (Var->isFirstDecl()) + // "Complete" rather than "definite" because tentative definitions + // make no sense for sizeless types. Variables of sizeless type + // can never be global anyway. RequireCompleteType(Var->getLocation(), Type, diag::ext_typecheck_decl_incomplete_type); } @@ -14657,6 +14664,9 @@ // C++ 9.6p3: A bit-field shall have integral or enumeration type. if (!FieldTy->isDependentType() && !FieldTy->isIntegralOrEnumerationType()) { // Handle incomplete types with specific error. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures (and thus sizeless fields). if (RequireCompleteType(FieldLoc, FieldTy, diag::err_field_incomplete)) return ExprError(); if (FieldName) @@ -14890,6 +14900,8 @@ QualType EltTy = Context.getBaseElementType(T); if (!EltTy->isDependentType()) { + // "Complete" rather than "definite" because fields cannot + // have sizeless types. if (RequireCompleteType(Loc, EltTy, diag::err_field_incomplete)) { // Fields of incomplete type force their record to be invalid. Record->setInvalidDecl(); @@ -15416,6 +15428,8 @@ // elsewhere, after synthesized ivars are known. } } else if (!FDTy->isDependentType() && + // "Complete" rather than "definite" because fields cannot + // have sizeless types. RequireCompleteType(FD->getLocation(), FD->getType(), diag::err_field_incomplete)) { // Incomplete type @@ -15641,6 +15655,8 @@ } else { ++NonBitFields; QualType FieldType = I->getType(); + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures (and thus sizeless fields). if (FieldType->isIncompleteType() || !Context.getTypeSizeInChars(FieldType).isZero()) ZeroSize = false; Index: lib/Sema/SemaDeclAttr.cpp =================================================================== --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -451,6 +451,9 @@ // If it's an incomplete type, it could be a smart pointer; skip it. // (We don't want to force template instantiation if we can avoid it, // since that would alter the order in which templates are instantiated.) + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (RT->isIncompleteType()) return true; @@ -483,6 +486,9 @@ return false; // Don't check for the capability if the class hasn't been defined yet. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (RT->isIncompleteType()) return true; @@ -1271,6 +1277,8 @@ TD->addAttr(::new (S.Context) PackedAttr(AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); else if (auto *FD = dyn_cast(D)) { + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures (and thus sizeless fields). bool BitfieldByteAligned = (!FD->getType()->isDependentType() && !FD->getType()->isIncompleteType() && FD->isBitField() && @@ -3312,12 +3320,16 @@ return; } + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless unions (and thus sizeless fields). if (FirstType->isIncompleteType()) return; uint64_t FirstSize = S.Context.getTypeSize(FirstType); uint64_t FirstAlign = S.Context.getTypeAlign(FirstType); for (; Field != FieldEnd; ++Field) { QualType FieldType = Field->getType(); + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless unions (and thus sizeless fields). if (FieldType->isIncompleteType()) return; // FIXME: this isn't fully correct; we also need to test whether the Index: lib/Sema/SemaDeclCXX.cpp =================================================================== --- lib/Sema/SemaDeclCXX.cpp +++ lib/Sema/SemaDeclCXX.cpp @@ -975,6 +975,8 @@ QualType TraitTy = S.CheckTemplateIdType(TemplateName(TraitTD), Loc, Args); if (TraitTy.isNull()) return true; + // "Complete" and "definite" are the same here, since trait classes are never + // sizeless. if (!S.isCompleteType(Loc, TraitTy)) { if (DiagID) S.RequireCompleteType( @@ -1117,6 +1119,9 @@ // access lookup LookupResult MemberGet(S, GetDN, Src->getLocation(), Sema::LookupMemberName); bool UseMemberGet = false; + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures (and there can therefore be no "get" + // member for sizeless types). if (S.isCompleteType(Src->getLocation(), DecompType)) { if (auto *RD = DecompType->getAsCXXRecordDecl()) S.LookupQualifiedName(MemberGet, RD); @@ -2223,6 +2228,9 @@ // C++ [class.derived]p2: // The class-name in a base-specifier shall not be an incompletely // defined class. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (RequireCompleteType(BaseLoc, BaseType, diag::err_incomplete_base_class, SpecifierRange)) { Class->setInvalidDecl(); @@ -2491,6 +2499,9 @@ // FIXME: In a modules build, do we need the entire path to be visible for us // to be able to use the inheritance relationship? + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (!isCompleteType(Loc, Derived) && !DerivedRD->isBeingDefined()) return false; @@ -2512,6 +2523,8 @@ if (!BaseRD) return false; + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (!isCompleteType(Loc, Derived) && !DerivedRD->isBeingDefined()) return false; @@ -13420,6 +13433,7 @@ Mode = 2; DK = diag::err_catch_incomplete_ref; } + // "Complete" rather than "definite" because sizeless types cannot be thrown. if (!Invalid && (Mode == 0 || !BaseType->isVoidType()) && !BaseType->isDependentType() && RequireCompleteType(Loc, BaseType, DK)) Invalid = true; @@ -14464,6 +14478,8 @@ // type D. if (const RecordType *RT = NewClassTy->getAs()) { if (!RT->isBeingDefined() && + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. RequireCompleteType(New->getLocation(), NewClassTy, diag::err_covariant_return_incomplete, New->getDeclName())) Index: lib/Sema/SemaExceptionSpec.cpp =================================================================== --- lib/Sema/SemaExceptionSpec.cpp +++ lib/Sema/SemaExceptionSpec.cpp @@ -125,6 +125,10 @@ // pointer or reference to an incomplete type, other than (cv) void* or a // pointer or reference to a class currently being defined. // In Microsoft mode, downgrade this to a warning. + // + // This remains true with the sizeless type extension. It would be + // possible to support throwing pointers to sizeless types, but it + // doesn't seem worthwhile. unsigned DiagID = diag::err_incomplete_in_exception_spec; bool ReturnValueOnError = true; if (getLangOpts().MicrosoftExt) { Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -3618,6 +3618,8 @@ // be complete (and will attempt to complete it if it's an array of unknown // bound). if (ExprKind == UETT_AlignOf) { + // "Complete" rather than "definite" because alignof cannot be + // applied to sizeless types. if (RequireCompleteType(E->getExprLoc(), Context.getBaseElementType(E->getType()), diag::err_sizeof_alignof_incomplete_type, ExprKind, @@ -3721,6 +3723,8 @@ ExprKind)) return false; + // "Complete" rather than "definite" because alignof & co. cannot be applied + // to sizeless types. if (RequireCompleteType(OpLoc, ExprType, diag::err_sizeof_alignof_incomplete_type, ExprKind, ExprRange)) @@ -4482,6 +4486,8 @@ // See IsCForbiddenLValueType. if (!ResultType.hasQualifiers()) VK = VK_RValue; } else if (!ResultType->isDependentType() && + // "Complete" rather than "definite" because arrays of sizeless type + // and arithmetic on pointers to sizeless types are both invalid. RequireCompleteType(LLoc, ResultType, diag::err_subscript_incomplete_type, BaseExpr)) return ExprError(); @@ -5656,6 +5662,8 @@ QualType literalType = TInfo->getType(); if (literalType->isArrayType()) { + // "Complete" rather than "definite" because arrays of sizeless types + // are not allowed. if (RequireCompleteType(LParenLoc, Context.getBaseElementType(literalType), diag::err_illegal_decl_array_incomplete_type, SourceRange(LParenLoc, @@ -8707,6 +8715,8 @@ assert(ResType->isAnyPointerType() && !ResType->isDependentType()); QualType PointeeTy = ResType->getPointeeType(); + // "Complete" rather than "definite" because arithmetic on pointers to + // sizeless types is not allowed. return S.RequireCompleteType(Loc, PointeeTy, diag::err_typecheck_arithmetic_incomplete_type, PointeeTy, Operand->getSourceRange()); @@ -12730,6 +12740,10 @@ // Type must be complete per C99 7.17p3 because a declaring a variable // with an incomplete type would be ill-formed. + // + // The condition remains completeness rather than definiteness with + // the sizeless type extension because offsetof cannot be applied to + // sizeless types. if (!Dependent && RequireCompleteType(BuiltinLoc, ArgTy, diag::err_offsetof_incomplete_type, TypeRange)) @@ -12780,6 +12794,10 @@ } // We need to have a complete type to look into. + // + // The condition remains completeness rather than definiteness with + // the sizeless type extension because offsetof cannot be applied to + // sizeless types. if (RequireCompleteType(OC.LocStart, CurrentType, diag::err_offsetof_incomplete_type)) return ExprError(); @@ -14614,6 +14632,11 @@ } // Make sure that by-copy captures are of a complete and non-abstract type. + // + // The condition remains completeness rather than definiteness with + // the sizeless type extension because by-value capture of sizeless + // types would give a sizeless closure type. (Capturing references + // to sizeless types is OK.) if (BuildAndDiagnose) { if (!CaptureType->isDependentType() && S.RequireCompleteType(Loc, CaptureType, @@ -15996,6 +16019,9 @@ Expr *CastExpr, CastKind &CastKind, ExprValueKind &VK, CXXCastPath &Path) { // The type we're casting to must be either void or complete. + // + // "Complete" rather than "definite" because there doesn't seem much + // point extending this to sizeless definite types. if (!CastType->isVoidType() && RequireCompleteType(TypeRange.getBegin(), CastType, diag::err_typecheck_cast_to_incomplete)) Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -174,6 +174,8 @@ // cv-qualified) T. LookupCtx = computeDeclContext(SearchType); isDependent = SearchType->isDependentType(); + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. assert((isDependent || !SearchType->isIncompleteType()) && "Caller should have completed object type"); @@ -398,6 +400,8 @@ = Context.getUnqualifiedArrayType(Operand->getType().getNonReferenceType(), Quals); if (T->getAs() && + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. RequireCompleteType(TypeidLoc, T, diag::err_incomplete_typeid)) return ExprError(); @@ -427,6 +431,9 @@ // C++ [expr.typeid]p3: // [...] If the type of the expression is a class type, the class // shall be completely-defined. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (RequireCompleteType(TypeidLoc, T, diag::err_incomplete_typeid)) return ExprError(); @@ -798,6 +805,10 @@ QualType ExceptionObjectTy, Expr *E) { // If the type of the exception would be an incomplete type or a pointer // to an incomplete type other than (cv) void the program is ill-formed. + // + // This remains true with the sizeless type extension. It would be + // possible to support throwing pointers to sizeless types, but it + // doesn't seem worthwhile. QualType Ty = ExceptionObjectTy; bool isPointer = false; if (const PointerType* Ptr = Ty->getAs()) { @@ -2124,6 +2135,10 @@ SourceRange R) { // C++ 5.3.4p1: "[The] type shall be a complete object type, but not an // abstract class type or array thereof. + // + // The condition remains completeness rather than definiteness with + // the sizeless type extension; it isn't possible to use "new" with + // sizeless definite types. if (AllocType->isFunctionType()) return Diag(Loc, diag::err_bad_new_type) << AllocType << 0 << R; @@ -3240,6 +3255,9 @@ return ExprError(Diag(StartLoc, diag::err_delete_operand) << Type << Ex.get()->getSourceRange()); } else if (!Pointee->isDependentType()) { + // "Complete" rather than "definite" because it isn't possible to + // use "new" or "delete" with sizeless definite types. + // // FIXME: This can result in errors if the definition was imported from a // module but is hidden. if (!RequireCompleteType(StartLoc, Pointee, @@ -3298,6 +3316,9 @@ } if (!OperatorDelete) { + // "Complete" rather than "definite" because it isn't possible to + // use "new" or "delete" with sizeless definite types. It also + // wouldn't make sense to use size forms for sizeless types. bool IsComplete = isCompleteType(StartLoc, Pointee); bool CanProvideSize = IsComplete && (!ArrayForm || UsualArrayDeleteWantsSize || @@ -4301,6 +4322,8 @@ case UTT_IsAbstract: if (const auto *RD = ArgTy->getAsCXXRecordDecl()) if (!RD->isUnion()) + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. return !S.RequireCompleteType( Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr); return true; @@ -4310,6 +4333,8 @@ case UTT_IsFinal: case UTT_IsSealed: if (ArgTy->getAsCXXRecordDecl()) + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. return !S.RequireCompleteType( Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr); return true; @@ -5013,6 +5038,9 @@ // If Base and Derived are class types and are different types // (ignoring possible cv-qualifiers) then Derived shall be a // complete type. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (Self.RequireCompleteType(KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr)) return false; @@ -5360,6 +5388,9 @@ if (!Context.hasSameUnqualifiedType(Class, LHSType)) { // If we want to check the hierarchy, we need a complete type. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (RequireCompleteType(Loc, LHSType, diag::err_bad_memptr_lhs, OpSpelling, (int)isIndirect)) { return QualType(); @@ -6712,6 +6743,8 @@ // the member function body. if (!BaseType->isDependentType() && !isThisOutsideMemberFunctionBody(BaseType) && + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. RequireCompleteType(OpLoc, BaseType, diag::err_incomplete_member_access)) return ExprError(); Index: lib/Sema/SemaExprMember.cpp =================================================================== --- lib/Sema/SemaExprMember.cpp +++ lib/Sema/SemaExprMember.cpp @@ -644,6 +644,8 @@ SourceRange BaseRange = BaseExpr ? BaseExpr->getSourceRange() : SourceRange(); RecordDecl *RDecl = RTy->getDecl(); if (!SemaRef.isThisOutsideMemberFunctionBody(QualType(RTy, 0)) && + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. SemaRef.RequireCompleteType(OpLoc, QualType(RTy, 0), diag::err_typecheck_incomplete_tag, BaseRange)) Index: lib/Sema/SemaInit.cpp =================================================================== --- lib/Sema/SemaInit.cpp +++ lib/Sema/SemaInit.cpp @@ -3680,6 +3680,8 @@ !SecondStepOfCopyInit) { Expr *Initializer = Args[0]; auto *SourceRD = Initializer->getType()->getAsCXXRecordDecl(); + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (SourceRD && S.isCompleteType(DeclLoc, Initializer->getType())) { const auto &Conversions = SourceRD->getVisibleConversionFunctions(); for (auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) { @@ -4240,6 +4242,8 @@ const RecordType *T1RecordType = nullptr; if (AllowRValues && (T1RecordType = T1->getAs()) && + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. S.isCompleteType(Kind.getLocation(), T1)) { // The type we're converting to is a class type. Enumerate its constructors // to see if there is a suitable conversion. @@ -4846,6 +4850,9 @@ = cast(DestRecordType->getDecl()); // Try to complete the type we're converting to. + // + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (S.isCompleteType(Kind.getLocation(), DestType)) { for (NamedDecl *D : S.LookupConstructors(DestRecordDecl)) { auto Info = getConstructorInfo(D); @@ -4876,6 +4883,9 @@ // We can only enumerate the conversion functions for a complete type; if // the type isn't complete, simply skip this step. + // + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (S.isCompleteType(DeclLoc, SourceType)) { CXXRecordDecl *SourceRecordDecl = cast(SourceRecordType->getDecl()); @@ -5798,6 +5808,9 @@ SourceLocation Loc = getInitializationLoc(Entity, CurInit.get()); // Make sure that the type we are copying is complete. + // + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (S.RequireCompleteType(Loc, T, diag::err_temp_copy_incomplete)) return CurInit; @@ -8716,6 +8729,8 @@ case OR_No_Viable_Function: { CXXRecordDecl *Primary = cast(Template)->getTemplatedDecl(); + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. bool Complete = isCompleteType(Kind.getLocation(), Context.getTypeDeclType(Primary)); Diag(Kind.getLocation(), Index: lib/Sema/SemaLookup.cpp =================================================================== --- lib/Sema/SemaLookup.cpp +++ lib/Sema/SemaLookup.cpp @@ -424,6 +424,8 @@ // array type. if (VarDecl *DVD = dyn_cast(DUnderlying)) { VarDecl *EVD = cast(EUnderlying); + // "Complete" and "definite" are the same here, since the code is only + // intended to handle arrays, which are never sizeless. if (EVD->getType()->isIncompleteType() && !DVD->getType()->isIncompleteType()) { // Prefer the decl with a more complete type if visible. @@ -2556,6 +2558,9 @@ } // Only recurse into base classes for complete types. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (!Result.S.isCompleteType(Result.InstantiationLoc, Result.S.Context.getRecordType(Class))) return; Index: lib/Sema/SemaOverload.cpp =================================================================== --- lib/Sema/SemaOverload.cpp +++ lib/Sema/SemaOverload.cpp @@ -2000,6 +2000,9 @@ } // We have already pre-calculated the promotion type, so this is trivial. + // + // "Complete" and "definite" are the same here, since there's no concept + // of a sizeless enum. if (ToType->isIntegerType() && isCompleteType(From->getLocStart(), FromType)) return Context.hasSameUnqualifiedType( @@ -3279,6 +3282,8 @@ S.IsDerivedFrom(From->getLocStart(), From->getType(), ToType))) ConstructorsOnly = true; + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (!S.isCompleteType(From->getExprLoc(), ToType)) { // We're not going to find any constructors. } else if (CXXRecordDecl *ToRecordDecl @@ -3344,6 +3349,8 @@ // Enumerate conversion functions, if we're allowed to. if (ConstructorsOnly || isa(From)) { + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. } else if (!S.isCompleteType(From->getLocStart(), From->getType())) { // No conversion functions from incomplete types. } else if (const RecordType *FromRecordType @@ -4248,6 +4255,8 @@ QualType ConvertedT2; if (UnqualT1 == UnqualT2) { // Nothing to do. + // "Complete" and "definite" are the same here, since there is no derivation + // based on sizeless types. } else if (isCompleteType(Loc, OrigT2) && isTypeValid(UnqualT1) && isTypeValid(UnqualT2) && IsDerivedFrom(Loc, UnqualT2, UnqualT1)) @@ -4525,6 +4534,9 @@ // conversion is selected by enumerating the applicable // conversion functions (13.3.1.6) and choosing the best // one through overload resolution (13.3)), + // + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (!SuppressUserConversions && T2->isRecordType() && S.isCompleteType(DeclLoc, T2) && RefRelationship == Sema::Ref_Incompatible) { @@ -4588,6 +4600,9 @@ // expression in the first case and to the result of the conversion // in the second case (or, in either case, to an appropriate base // class subobject). + // + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (!SuppressUserConversions && RefRelationship == Sema::Ref_Incompatible && T2->isRecordType() && S.isCompleteType(DeclLoc, T2) && FindConversionForRefInit(S, ICS, DeclType, DeclLoc, @@ -5713,6 +5728,8 @@ } } IncompleteDiagnoser(Converter, From); + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (Converter.Suppress ? !isCompleteType(Loc, T) : RequireCompleteType(Loc, T, IncompleteDiagnoser)) return From; @@ -7212,6 +7229,9 @@ // the set of member candidates is empty. if (const RecordType *T1Rec = T1->getAs()) { // Complete the type if it can be completed. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (!isCompleteType(OpLoc, T1) && !T1Rec->isBeingDefined()) return; // If the type is neither complete nor being defined, bail out now. @@ -7559,6 +7579,9 @@ HasNullPtrType = true; } else if (AllowUserConversions && TyRec) { // No conversion functions in incomplete types. + // + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (!SemaRef.isCompleteType(Loc, Ty)) return; @@ -9664,6 +9687,8 @@ if (const PointerType *ToPtrTy = ToTy->getAs()) { if (ToPtrTy->getPointeeType().isAtLeastAsQualifiedAs( FromPtrTy->getPointeeType()) && + // "Complete" and "definite" are the same here, since there is + // no derivation based on sizeless types. !FromPtrTy->getPointeeType()->isIncompleteType() && !ToPtrTy->getPointeeType()->isIncompleteType() && S.IsDerivedFrom(SourceLocation(), ToPtrTy->getPointeeType(), @@ -9682,6 +9707,8 @@ BaseToDerivedConversion = 2; } else if (const ReferenceType *ToRefTy = ToTy->getAs()) { if (ToRefTy->getPointeeType().isAtLeastAsQualifiedAs(FromTy) && + // "Complete" and "definite" are the same here, since there is + // no derivation based on sizeless types. !FromTy->isIncompleteType() && !ToRefTy->getPointeeType()->isIncompleteType() && S.IsDerivedFrom(SourceLocation(), ToRefTy->getPointeeType(), FromTy)) { @@ -12433,6 +12460,8 @@ Diag(OpLoc, diag::err_ovl_no_viable_oper) << BinaryOperator::getOpcodeStr(Opc) << Args[0]->getSourceRange() << Args[1]->getSourceRange(); + // "Complete" and "definite" are the same here, since we don't + // yet support sizeless structures. if (Args[0]->getType()->isIncompleteType()) { Diag(OpLoc, diag::note_assign_lhs_incomplete) << Args[0]->getType() @@ -12982,6 +13011,8 @@ OverloadCandidateSet::CSK_Operator); DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(OO_Call); + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (RequireCompleteType(LParenLoc, Object.get()->getType(), diag::err_incomplete_object_call, Object.get())) return true; @@ -13258,6 +13289,8 @@ OverloadCandidateSet CandidateSet(Loc, OverloadCandidateSet::CSK_Operator); const RecordType *BaseRecord = Base->getType()->getAs(); + // "Complete" and "definite" are the same here, since we don't yet support + // sizeless structures. if (RequireCompleteType(Loc, Base->getType(), diag::err_typecheck_incomplete_tag, Base)) return ExprError(); Index: lib/Sema/SemaPseudoObject.cpp =================================================================== --- lib/Sema/SemaPseudoObject.cpp +++ lib/Sema/SemaPseudoObject.cpp @@ -1066,6 +1066,8 @@ // All other scalar cases are assumed to be dictionary indexing which // caller handles, with diagnostics if needed. return OS_Dictionary; + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (!getLangOpts().CPlusPlus || !RecordTy || RecordTy->isIncompleteType()) { // No indexing can be done. Issue diagnostics and quit. @@ -1080,6 +1082,9 @@ } // We must have a complete class type. + // + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (RequireCompleteType(FromE->getExprLoc(), T, diag::err_objc_index_incomplete_class_type, FromE)) return OS_Error; Index: lib/Sema/SemaStmt.cpp =================================================================== --- lib/Sema/SemaStmt.cpp +++ lib/Sema/SemaStmt.cpp @@ -2337,6 +2337,9 @@ return StmtError(); QualType RangeType = Range->getType(); + // "Complete" is the same as "definite" since we don't yet support + // sizeless structures, and since sizeless built-in types cannot + // be used in ranges. if (RequireCompleteType(RangeLoc, RangeType, diag::err_for_range_incomplete_type)) return StmtError(); Index: lib/Sema/SemaStmtAsm.cpp =================================================================== --- lib/Sema/SemaStmtAsm.cpp +++ lib/Sema/SemaStmtAsm.cpp @@ -732,6 +732,8 @@ if (!RT) return true; + // "Complete" and "definite" are the same here, since we don't yet + // support sizeless structures. if (RequireCompleteType(AsmLoc, QualType(RT, 0), diag::err_asm_incomplete_type)) return true; Index: lib/Sema/SemaTemplate.cpp =================================================================== --- lib/Sema/SemaTemplate.cpp +++ lib/Sema/SemaTemplate.cpp @@ -313,6 +313,8 @@ assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist"); LookupCtx = computeDeclContext(ObjectType); isDependent = ObjectType->isDependentType(); + // "Complete" and "definite" are the same here, since we don't support + // sizeless structures. assert((isDependent || !ObjectType->isIncompleteType() || ObjectType->castAs()->isBeingDefined()) && "Caller should have completed object type"); @@ -1917,6 +1919,8 @@ ConvertConstructorToDeductionGuideTransform Transform( *this, cast(Template)); + // "Complete" and "definite" are the same here, since DeducedType is a + // class template and we don't support sizeless structures. if (!isCompleteType(Loc, Transform.DeducedType)) return; @@ -5482,6 +5486,8 @@ if (Entity && Entity->hasAttr()) return NPV_NotNullPointer; + // No need to handle sizeless types here; the type is already known to be + // some form of pointer. if (!S.isCompleteType(Arg->getExprLoc(), ParamType)) llvm_unreachable( "Incomplete parameter type in isNullPointerValueTemplateArgument!"); @@ -9470,6 +9476,9 @@ const TemplateSpecializationType *EnableIfTST = EnableIfTSTLoc.getTypePtr(); // ... which names a complete class template declaration... + // + // "Complete" and "definite" are the same here, since std::enable_if + // is always sized rather than sizeless. const TemplateDecl *EnableIfDecl = EnableIfTST->getTemplateName().getAsTemplateDecl(); if (!EnableIfDecl || EnableIfTST->isIncompleteType()) Index: lib/Sema/SemaTemplateDeduction.cpp =================================================================== --- lib/Sema/SemaTemplateDeduction.cpp +++ lib/Sema/SemaTemplateDeduction.cpp @@ -1663,6 +1663,9 @@ // We cannot inspect base classes as part of deduction when the type // is incomplete, so either instantiate any templates necessary to // complete the type, or skip over it if it cannot be completed. + // + // "Complete" and "definite" are the same here, since no sizeless + // types have base classes. if (!S.isCompleteType(Info.getLocation(), Arg)) return Result; Index: lib/Sema/SemaTemplateInstantiateDecl.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiateDecl.cpp +++ lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -5093,6 +5093,8 @@ if (Tag->isBeingDefined()) IsBeingInstantiated = true; if (!Tag->isBeingDefined() && + // "Complete" and "definite" are the same here, since we + // don't yet support sizeless structures. RequireCompleteType(Loc, T, diag::err_incomplete_type)) return nullptr; Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -2076,6 +2076,9 @@ } else { // C99 6.7.5.2p1: If the element type is an incomplete or function type, // reject it (e.g. void ary[7], struct foo ary[7], void ary[7]()) + // + // This remains true with the sizeless type extension; arrays of + // sizeless types are not allowed. if (RequireCompleteType(Loc, T, diag::err_illegal_decl_array_incomplete_type)) return QualType(); @@ -2131,6 +2134,8 @@ T = Context.getIncompleteArrayType(T, ASM, Quals); } else if (ArraySize->isTypeDependent() || ArraySize->isValueDependent()) { T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals, Brackets); + // "Complete" and "definite" are equivalent at this point, since we + // rejected sizeless T above. } else if ((!T->isDependentType() && !T->isIncompleteType() && !T->isConstantSizeType()) || isArraySizeVLA(*this, ArraySize, ConstVal)) { @@ -2173,6 +2178,8 @@ << ArraySize->getSourceRange(); ASM = ArrayType::Normal; } + // "Complete" and "definite" are equivalent at this point, since we + // rejected sizeless T above. } else if (!T->isDependentType() && !T->isVariablyModifiedType() && !T->isIncompleteType() && !T->isUndeducedType()) { // Is the array too large? @@ -7796,6 +7803,8 @@ assert(!T->isDependentType() && "type should not be dependent"); QualType ElemType = Context.getBaseElementType(T); + // "Complete" is equivalent to "definite" here, since sizeless types are + // not (at present) treated as literal types. if ((isCompleteType(Loc, ElemType) || ElemType->isVoidType()) && T->isLiteralType(Context)) return false; @@ -7814,6 +7823,9 @@ // 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). + // + // As above, the condition is completeness rather than definiteness since + // sizeless types are not treated as literal types. if (RequireCompleteType(Loc, ElemType, diag::note_non_literal_incomplete, T)) return true; @@ -8030,7 +8042,10 @@ QualType Sema::BuildAtomicType(QualType T, SourceLocation Loc) { if (!T->isDependentType()) { - // FIXME: It isn't entirely clear whether incomplete atomic types + // "Complete" rather than "definite" because atomic sizeless types + // are not allowed. + // + // FIXME: It isn't entirely clear whether other incomplete atomic types // are allowed or not; for simplicity, ban them for the moment. if (RequireCompleteType(Loc, T, diag::err_atomic_specifier_bad_type, 0)) return QualType();