Lines Matching +full:local +full:- +full:bd +full:- +full:address +full:- +full:broken
1 //===------ SemaDeclCXX.cpp - Semantic Analysis for C++ Declarations ------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
64 //===----------------------------------------------------------------------===//
66 //===----------------------------------------------------------------------===//
69 /// CheckDefaultArgumentVisitor - C++ [dcl.fct.default] Traverses
71 /// contains any ill-formed subexpressions. For example, this will
72 /// diagnose the use of local variables or parameters within the
90 /// VisitExpr - Visit all of the children of this expression.
93 for (const Stmt *SubStmt : Node->children())
99 /// VisitDeclRefExpr - Visit a reference to a declaration, to
103 const ValueDecl *Decl = dyn_cast<ValueDecl>(DRE->getDecl());
114 // [...] A parameter shall not appear as a potentially-evaluated
117 if (DRE->isNonOdrUse() != NOUR_Unevaluated)
118 return S.Diag(DRE->getBeginLoc(),
120 << Param->getDeclName() << DefaultArg->getSourceRange();
121 } else if (auto *VD = Decl->getPotentiallyDecomposedVarDecl()) {
123 // Local variables shall not be used in default argument
127 // A local variable shall not appear as a potentially-evaluated
131 // Note: A local variable cannot be odr-used (6.3) in a default
134 if (VD->isLocalVarDecl() && !DRE->isNonOdrUse())
135 return S.Diag(DRE->getBeginLoc(),
137 << Decl << DefaultArg->getSourceRange();
142 /// VisitCXXThisExpr - Visit a C++ "this" expression.
147 return S.Diag(ThisE->getBeginLoc(),
149 << ThisE->getSourceRange();
155 for (const Expr *E : POE->semantics()) {
158 E = OVE->getSourceExpr();
159 assert(E && "pseudo-object binding without source expression?");
169 // a lambda-expression appearing in a default argument cannot implicitly or
170 // explicitly capture any local entity. Such a lambda-expression can still
171 // have an init-capture if any full-expression in its initializer satisfies
174 for (const LambdaCapture &LC : Lambda->captures()) {
175 if (!Lambda->isInitCapture(&LC))
179 Invalid |= Visit(D->getInit());
193 = Method->getType()->getAs<FunctionProtoType>();
194 Proto = Self->ResolveExceptionSpec(CallLoc, Proto);
198 ExceptionSpecificationType EST = Proto->getExceptionSpecType();
200 // If we have a throw-all spec at this point, ignore the function.
204 if (EST == EST_None && Method->hasAttr<NoThrowAttr>())
217 // We should make a consistent, order-independent choice here.
226 // need to search them for potentially-throwing calls.
246 "Shouldn't collect exceptions when throw-all is guaranteed.");
249 for (const auto &E : Proto->exceptions())
250 if (ExceptionsSeen.insert(Self->Context.getCanonicalType(E)).second)
261 // [An] implicit exception-specification specifies the type-id T if and
262 // only if T is allowed by the exception-specification of a function directly
267 // Note in particular that if an implicit exception-specification is generated
268 // for a function containing a throw-expression, that specification can still
272 // is no indication that we should only consider potentially-evaluated calls.
276 // implicit definition. For now, we assume that any non-nothrow expression can
279 if (Self->canThrow(S))
285 if (RequireCompleteType(Param->getLocation(), Param->getType(),
294 // copy-initialization semantics (8.5).
297 InitializationKind Kind = InitializationKind::CreateCopy(Param->getLocation(),
314 Param->setDefaultArg(Arg);
321 for (unsigned I = 0, N = InstPos->second.size(); I != N; ++I)
322 InstPos->second[I]->setUninstantiatedDefaultArg(Arg);
341 << DefaultArg->getSourceRange();
352 if (Param->isParameterPack()) {
354 << DefaultArg->getSourceRange();
356 Param->setDefaultArg(nullptr);
366 // Check that the default argument is well-formed
381 Param->setUnparsedDefaultArg();
391 Param->setInvalidDecl();
395 RE = CreateRecoveryExpr(EqualLoc, DefaultArg->getEndLoc(), {DefaultArg},
396 Param->getType().getNonReferenceType());
399 Param->getType().getNonReferenceType());
401 Param->setDefaultArg(RE.get());
407 // parameter-declaration-clause of a function declaration or in a
408 // template-parameter (14.1). It shall not be specified for a
410 // parameter-declaration-clause, it shall not occur within a
411 // declarator or abstract-declarator of a parameter-declaration.
426 if (Param->hasUnparsedDefaultArg()) {
430 if (Toks->size() > 1)
432 Toks->back().getLocation());
435 Diag(Param->getLocation(), diag::err_param_default_argument_nonfunc)
437 } else if (Param->getDefaultArg()) {
438 Diag(Param->getLocation(), diag::err_param_default_argument_nonfunc)
439 << Param->getDefaultArg()->getSourceRange();
440 Param->setDefaultArg(nullptr);
450 return llvm::any_of(FD->parameters(), [](ParmVarDecl *P) {
451 return P->hasDefaultArg() && !P->hasInheritedDefaultArg();
460 // parent, unless this is a local function declaration, in which case
462 DeclContext *ScopeDC = New->isLocalExternDecl()
463 ? New->getLexicalDeclContext()
464 : New->getDeclContext();
469 // Don't bother looking back past the latest decl if this is a local
471 PrevForDefaultArgs = New->isLocalExternDecl()
473 : PrevForDefaultArgs->getPreviousDecl()) {
479 !New->isCXXClassMember()) {
481 // the same scope and this is not an out-of-line definition of
486 if (PrevForDefaultArgs->isLocalExternDecl() != New->isLocalExternDecl()) {
487 // If only one of these is a local function declaration, then they are
489 // they're in the same scope. (If both are local, the scope check is
490 // sufficient, and if neither is local, then they are in the same scope.)
499 // For non-template functions, default arguments can be added in
517 ? PrevForDefaultArgs->getNumParams()
520 ParmVarDecl *OldParam = PrevForDefaultArgs->getParamDecl(p);
521 ParmVarDecl *NewParam = New->getParamDecl(p);
523 bool OldParamHasDfl = OldParam ? OldParam->hasDefaultArg() : false;
524 bool NewParamHasDfl = NewParam->hasDefaultArg();
535 if (MD && MD->getParent()->getDescribedClassTemplate()) {
537 NewParam->setHasInheritedDefaultArg();
538 if (OldParam->hasUninstantiatedDefaultArg())
539 NewParam->setUninstantiatedDefaultArg(
540 OldParam->getUninstantiatedDefaultArg());
542 NewParam->setDefaultArg(OldParam->getInit());
548 // FIXME: If we knew where the '=' was, we could easily provide a fix-it
549 // hint here. Alternatively, we could walk the type-source information
556 Diag(NewParam->getLocation(), DiagDefaultParamID)
557 << NewParam->getDefaultArgRange();
562 OldParam->hasInheritedDefaultArg(); /**/) {
563 Older = Older->getPreviousDecl();
564 OldParam = Older->getParamDecl(p);
567 Diag(OldParam->getLocation(), diag::note_previous_definition)
568 << OldParam->getDefaultArgRange();
574 if (New->getFriendObjectKind() == Decl::FOK_None ||
575 !New->getLexicalDeclContext()->isDependentContext()) {
577 // strips off any top-level ExprWithCleanups.
578 NewParam->setHasInheritedDefaultArg();
579 if (OldParam->hasUnparsedDefaultArg())
580 NewParam->setUnparsedDefaultArg();
581 else if (OldParam->hasUninstantiatedDefaultArg())
582 NewParam->setUninstantiatedDefaultArg(
583 OldParam->getUninstantiatedDefaultArg());
585 NewParam->setDefaultArg(OldParam->getInit());
588 if (New->getDescribedFunctionTemplate()) {
589 // Paragraph 4, quoted above, only applies to non-template functions.
590 Diag(NewParam->getLocation(),
592 << NewParam->getDefaultArgRange();
593 Diag(PrevForDefaultArgs->getLocation(),
596 } else if (New->getTemplateSpecializationKind()
598 New->getTemplateSpecializationKind() != TSK_Undeclared) {
602 // - the explicit specialization of a function template;
603 // - the explicit specialization of a member function template;
604 // - the explicit specialization of a member function of a class
608 Diag(NewParam->getLocation(), diag::err_template_spec_default_arg)
609 << (New->getTemplateSpecializationKind() ==TSK_ExplicitSpecialization)
610 << New->getDeclName()
611 << NewParam->getDefaultArgRange();
612 } else if (New->getDeclContext()->isDependentContext()) {
620 // arguments for an out-of-line definition of a member function of a
624 = dyn_cast<CXXRecordDecl>(New->getDeclContext())) {
625 if (Record->getDescribedClassTemplate())
633 Diag(NewParam->getLocation(),
636 << NewParam->getDefaultArgRange();
643 // is ill-formed. This can only happen for constructors.
645 New->getMinRequiredArguments() < Old->getMinRequiredArguments()) {
649 ParmVarDecl *NewParam = New->getParamDecl(New->getMinRequiredArguments());
650 assert(NewParam->hasDefaultArg());
651 Diag(NewParam->getLocation(), diag::err_default_arg_makes_ctor_special)
652 << NewParam->getDefaultArgRange() << llvm::to_underlying(NewSM);
653 Diag(Old->getLocation(), diag::note_previous_declaration);
661 if (New->getConstexprKind() != Old->getConstexprKind()) {
662 Diag(New->getLocation(), diag::err_constexpr_redecl_mismatch)
663 << New << static_cast<int>(New->getConstexprKind())
664 << static_cast<int>(Old->getConstexprKind());
665 Diag(Old->getLocation(), diag::note_previous_declaration);
667 } else if (!Old->getMostRecentDecl()->isInlined() && New->isInlined() &&
668 Old->isDefined(Def) &&
672 (New->isInlineSpecified() ||
673 New->getFriendObjectKind() == Decl::FOK_None)) {
676 // first declaration as inline, the program is ill-formed.
677 Diag(New->getLocation(), diag::err_inline_decl_follows_def) << New;
678 Diag(Def->getLocation(), diag::note_previous_definition);
685 // parameter-declaration-clauses.
687 !New->isFunctionTemplateSpecialization() && isVisible(Old)) {
688 Diag(New->getLocation(), diag::err_deduction_guide_redeclared);
689 Diag(Old->getLocation(), diag::note_previous_declaration);
696 if (Old->getFriendObjectKind() == Decl::FOK_Undeclared &&
698 Diag(New->getLocation(), diag::err_friend_decl_with_def_arg_redeclared);
699 Diag(Old->getLocation(), diag::note_previous_declaration);
705 // template, the function is instantiated when the function is odr-used.
707 // apply to non-template function declarations and definitions also apply
710 if (New->isThisDeclarationInstantiatedFromAFriendDefinition() &&
711 Old->isDefined(OldDefinition, true))
729 // The syntax only allows a decomposition declarator as a simple-declaration,
730 // a for-range-declaration, or a condition in Clang, but we parse it in more
741 Diag(TemplateParamLists.front()->getTemplateLoc(),
758 // The decl-specifier-seq shall contain only the type-specifier auto
759 // and cv-qualifiers.
761 // If decl-specifier-seq contains any decl-specifier other than static,
762 // thread_local, auto, or cv-qualifiers, the program is ill-formed.
764 // Each decl-specifier in the decl-specifier-seq shall be static,
765 // thread_local, auto (9.2.9.6 [dcl.spec.auto]), or a cv-qualifier.
768 // Note: While constrained-auto needs to be checked, we do so separately so
829 QualType R = TInfo->getType();
835 // The syntax only allows a single ref-qualifier prior to the decomposition
850 // In most cases, there's no actual problem with an explicitly-specified
853 if (R->isFunctionType())
860 assert(TemplRep->Kind == TNK_Concept_template &&
863 SourceRange TemplRange{TemplRep->TemplateNameLoc,
864 TemplRep->RAngleLoc.isValid()
865 ? TemplRep->RAngleLoc
866 : TemplRep->TemplateNameLoc};
867 Diag(TemplRep->TemplateNameLoc, diag::err_decomp_decl_constraint)
884 /*CreateBuiltins*/DC->getRedeclContext()->isTranslationUnit());
888 Previous.getFoundDecl()->isTemplateParameter()) {
894 auto *BD = BindingDecl::Create(Context, DC, B.NameLoc, VarName);
896 ProcessDeclAttributeList(S, BD, *B.Attrs);
900 ? getShadowedDeclaration(BD, Previous)
903 bool ConsiderLinkage = DC->isFunctionOrMethod() &&
909 DC->isFunctionOrMethod() && VarName->isPlaceholder();
912 bool sameDC = (Previous.end() - 1)
913 ->getDeclContext()
914 ->getRedeclContext()
915 ->Equals(DC->getRedeclContext());
917 isDeclInScope(*(Previous.end() - 1), CurContext, S, false)) {
924 Diag(Old->getLocation(), diag::note_previous_definition);
927 CheckShadow(BD, ShadowedDecl, Previous);
929 PushOnScopeChains(BD, S, true);
930 Bindings.push_back(BD);
931 ParsingInitForAutoVars.insert(BD);
941 // Build the variable that holds the non-decomposed object.
947 S->AddDecl(New);
948 CurContext->addHiddenDecl(New);
962 S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
971 SourceLocation Loc = B->getLocation();
978 B->setBinding(ElemType, E.get());
991 [&](SourceLocation Loc, Expr *Base, unsigned I) -> ExprResult {
1003 llvm::APSInt(CAT->getSize()),
1004 CAT->getElementType());
1011 S, Bindings, Src, DecompType, llvm::APSInt::get(VT->getNumElements()),
1012 S.Context.getQualifiedType(VT->getElementType(),
1022 S.Context.getQualifiedType(CT->getElementType(),
1024 [&](SourceLocation Loc, Expr *Base, unsigned I) -> ExprResult {
1081 S.Diag(Found->getLocation(), diag::note_declared_at);
1085 // Build the template-id.
1094 TraitTD->getTemplateParameters()));
1098 CXXRecordDecl *RD = TraitTy->getAsCXXRecordDecl();
1133 // it's not tuple-like.
1189 S.Diag(R.getRepresentativeDecl()->getLocation(), diag::note_declared_at);
1199 InitializingBinding(Sema &S, BindingDecl *BD) : S(S) {
1202 Ctx.PointOfInstantiation = BD->getLocation();
1203 Ctx.Entity = BD;
1217 S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
1230 // The unqualified-id get is looked up in the scope of E by class member
1232 LookupResult MemberGet(S, GetDN, Src->getLocation(), Sema::LookupMemberName);
1234 if (S.isCompleteType(Src->getLocation(), DecompType)) {
1235 if (auto *RD = DecompType->getAsCXXRecordDecl())
1240 // template whose first template parameter is a non-type parameter ...
1243 dyn_cast<FunctionTemplateDecl>(D->getUnderlyingDecl())) {
1244 TemplateParameterList *TPL = FTD->getTemplateParameters();
1245 if (TPL->size() != 0 &&
1246 isa<NonTypeTemplateParmDecl>(TPL->getParam(0))) {
1258 SourceLocation Loc = B->getLocation();
1266 if (!Src->getType()->isLValueReferenceType())
1267 E = ImplicitCastExpr::Create(S.Context, E.get()->getType(), CK_NoOp,
1277 // initializer is e.get<i-1>().
1286 // Otherwise, the initializer is get<i-1>(e), where get is looked up
1301 // Given the type T designated by std::tuple_element<i - 1, E>::type,
1310 S.BuildReferenceType(T, E.get()->isLValue(), Loc, B->getDeclName());
1314 S.Context, Src->getDeclContext(), Loc, Loc,
1315 B->getDeclName().getAsIdentifierInfo(), RefType,
1316 S.Context.getTrivialTypeSourceInfo(T, Loc), Src->getStorageClass());
1317 RefVD->setLexicalDeclContext(Src->getLexicalDeclContext());
1318 RefVD->setTSCSpec(Src->getTSCSpec());
1319 RefVD->setImplicit();
1320 if (Src->isInlineSpecified())
1321 RefVD->setInlineSpecified();
1322 RefVD->getLexicalDeclContext()->addHiddenDecl(RefVD);
1333 RefVD->setInit(E.get());
1337 DeclarationNameInfo(B->getDeclName(), Loc),
1342 B->setBinding(T, E.get());
1349 /// Find the base class to decompose in a built-in decomposition of a class type.
1357 return Specifier->getType()->getAsCXXRecordDecl()->hasDirectFields();
1362 if (RD->hasDirectFields())
1364 // Otherwise, all of E's non-static data members shall be public direct
1371 if (!RD->lookupInBases(BaseHasFields, Paths)) {
1381 else if (!S.Context.hasSameType(P.back().Base->getType(),
1382 BestPath->back().Base->getType())) {
1385 << false << RD << BestPath->back().Base->getType()
1386 << P.back().Base->getType();
1388 } else if (P.Access < BestPath->Access) {
1394 QualType BaseType = BestPath->back().Base->getType();
1404 AS = BestPath->Access;
1406 ClassWithFields = BaseType->getAsCXXRecordDecl();
1413 if (ClassWithFields->lookupInBases(BaseHasFields, Paths)) {
1416 << Paths.front().back().Base->getType();
1426 if (S.RequireCompleteType(Src->getLocation(), DecompType,
1432 findDecomposableBaseClass(S, Src->getLocation(), OrigRD, BasePath);
1439 auto DiagnoseBadNumberOfBindings = [&]() -> bool {
1441 RD->fields(), [](FieldDecl *FD) { return !FD->isUnnamedBitField(); });
1443 S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
1449 // all of E's non-static data members shall be [...] well-formed
1453 for (auto *FD : RD->fields()) {
1454 if (FD->isUnnamedBitField())
1457 // All the non-static data members are required to be nameable, so they
1459 if (!FD->getDeclName()) {
1460 if (RD->isLambda()) {
1461 S.Diag(Src->getLocation(), diag::err_decomp_decl_lambda);
1462 S.Diag(RD->getLocation(), diag::note_lambda_decl);
1466 if (FD->isAnonymousStructOrUnion()) {
1467 S.Diag(Src->getLocation(), diag::err_decomp_decl_anon_union_member)
1468 << DecompType << FD->getType()->isUnionType();
1469 S.Diag(FD->getLocation(), diag::note_declared_at);
1480 SourceLocation Loc = B->getLocation();
1489 BasePair.getAccess(), FD->getAccess())));
1501 DeclAccessPair::make(FD, FD->getAccess()),
1502 DeclarationNameInfo(FD->getDeclName(), Loc));
1507 // the cv-qualification of the decomposition expression.
1512 if (FD->isMutable())
1514 B->setBinding(S.BuildQualifiedType(FD->getType(), Loc, Q), E.get());
1524 QualType DecompType = DD->getType();
1528 if (DecompType->isDependentType()) {
1529 for (auto *B : DD->bindings())
1530 B->setType(Context.DependentTy);
1535 ArrayRef<BindingDecl*> Bindings = DD->bindings();
1539 // As an extension, we also support decomposition of built-in complex and
1543 DD->setInvalidDecl();
1546 if (auto *VT = DecompType->getAs<VectorType>()) {
1548 DD->setInvalidDecl();
1551 if (auto *CT = DecompType->getAs<ComplexType>()) {
1553 DD->setInvalidDecl();
1558 // if the expression std::tuple_size<E>::value is a well-formed integral
1561 switch (isTupleLike(*this, DD->getLocation(), DecompType, TupleSize)) {
1563 DD->setInvalidDecl();
1568 DD->setInvalidDecl();
1576 // [E shall be of array or non-union class type]
1577 CXXRecordDecl *RD = DecompType->getAsCXXRecordDecl();
1578 if (!RD || RD->isUnion()) {
1579 Diag(DD->getLocation(), diag::err_decomp_decl_unbindable_type)
1581 DD->setInvalidDecl();
1586 // all of E's non-static data members shall be [...] direct members of
1589 DD->setInvalidDecl();
1597 assert(Context.hasSameType(New->getType(), Old->getType()) &&
1600 QualType NewType = New->getType();
1601 QualType OldType = Old->getType();
1605 if (const ReferenceType *R = NewType->getAs<ReferenceType>()) {
1606 NewType = R->getPointeeType();
1607 OldType = OldType->castAs<ReferenceType>()->getPointeeType();
1608 } else if (const PointerType *P = NewType->getAs<PointerType>()) {
1609 NewType = P->getPointeeType();
1610 OldType = OldType->castAs<PointerType>()->getPointeeType();
1611 } else if (const MemberPointerType *M = NewType->getAs<MemberPointerType>()) {
1612 NewType = M->getPointeeType();
1613 OldType = OldType->castAs<MemberPointerType>()->getPointeeType();
1616 if (!NewType->isFunctionProtoType())
1620 // libraries are hopefully not as broken so that we don't need these
1623 OldType->getAs<FunctionProtoType>(), Old->getLocation(),
1624 NewType->getAs<FunctionProtoType>(), New->getLocation())) {
1625 New->setInvalidDecl();
1629 /// CheckCXXDefaultArguments - Verify that the default arguments for a
1630 /// function declaration are well-formed according to C++
1636 if (FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
1638 if (auto *FTD = FD->getDescribedFunctionTemplate())
1639 if (FTD->isMemberSpecialization())
1642 unsigned NumParams = FD->getNumParams();
1647 ParmVarDecl *Param = FD->getParamDecl(ParamIdx);
1648 if (Param->hasDefaultArg())
1658 ParmVarDecl *Param = FD->getParamDecl(ParamIdx);
1659 if (Param->hasDefaultArg() || Param->isParameterPack() ||
1661 CurrentInstantiationScope->isLocalPackExpansion(Param)))
1663 if (Param->isInvalidDecl())
1665 else if (Param->getIdentifier())
1666 Diag(Param->getLocation(), diag::err_param_default_argument_missing_name)
1667 << Param->getIdentifier();
1669 Diag(Param->getLocation(), diag::err_param_default_argument_missing);
1680 if (T->isDependentType())
1689 return !T->isLiteralType(SemaRef.Context);
1703 T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
1704 if (!RD || RD->hasConstexprDestructor())
1708 SemaRef.Diag(DD->getLocation(), diag::err_constexpr_dtor_subobject)
1709 << static_cast<int>(DD->getConstexprKind()) << !FD
1710 << (FD ? FD->getDeclName() : DeclarationName()) << T;
1712 << !FD << (FD ? FD->getDeclName() : DeclarationName()) << T;
1717 const CXXRecordDecl *RD = DD->getParent();
1718 for (const CXXBaseSpecifier &B : RD->bases())
1721 for (const FieldDecl *FD : RD->fields())
1722 if (!Check(FD->getLocation(), FD->getType(), FD))
1735 const auto *FT = FD->getType()->castAs<FunctionProtoType>();
1736 for (FunctionProtoType::param_type_iterator i = FT->param_type_begin(),
1737 e = FT->param_type_end();
1739 const ParmVarDecl *PD = FD->getParamDecl(ArgIndex);
1741 SourceLocation ParamLoc = PD->getLocation();
1744 PD->getSourceRange(), isa<CXXConstructorDecl>(FD),
1745 FD->isConsteval()))
1757 if (CheckLiteralType(SemaRef, Kind, FD->getLocation(), FD->getReturnType(),
1759 FD->isConsteval()))
1789 if (MD && MD->isInstance()) {
1793 // - the class shall not have any virtual base classes;
1797 const CXXRecordDecl *RD = MD->getParent();
1798 if (RD->getNumVBases()) {
1802 Diag(NewFD->getLocation(), diag::err_constexpr_virtual_base)
1804 << getRecordDiagFromTagKind(RD->getTagKind()) << RD->getNumVBases();
1805 for (const auto &I : RD->vbases())
1816 // - it shall not be virtual; (removed in C++20)
1818 if (Method && Method->isVirtual()) {
1821 Diag(Method->getLocation(), diag::warn_cxx17_compat_constexpr_virtual);
1826 Method = Method->getCanonicalDecl();
1827 Diag(Method->getLocation(), diag::err_constexpr_virtual);
1832 while (!WrittenVirtual->isVirtualAsWritten())
1833 WrittenVirtual = *WrittenVirtual->begin_overridden_methods();
1835 Diag(WrittenVirtual->getLocation(),
1841 // - its return type shall be a literal type; (removed in C++23)
1852 !Dtor->getParent()->defaultedDestructorIsConstexpr()) {
1860 // - each of its parameter types shall be a literal type; (removed in C++23)
1865 Stmt *Body = NewFD->getBody();
1882 for (const auto *DclIt : DS->decls()) {
1883 switch (DclIt->getKind()) {
1891 // - static_assert-declarations
1892 // - using-declarations,
1893 // - using-directives,
1894 // - using-enum-declaration
1899 // - typedef declarations and alias-declarations that do not define
1902 if (TN->getUnderlyingType()->isVariablyModifiedType()) {
1903 // Don't allow variably-modified types in constexpr functions.
1905 TypeLoc TL = TN->getTypeSourceInfo()->getTypeLoc();
1918 if (cast<TagDecl>(DclIt)->isThisDeclarationADefinition()) {
1920 SemaRef.Diag(DS->getBeginLoc(),
1941 // a definition of a variable of non-literal type or of static or
1945 if (VD->isThisDeclarationADefinition()) {
1946 if (VD->isStaticLocal()) {
1948 SemaRef.Diag(VD->getLocation(),
1953 << (VD->getTLSKind() == VarDecl::TLS_Dynamic);
1959 CheckLiteralType(SemaRef, Kind, VD->getLocation(), VD->getType(),
1962 /*variable of non-literal type*/ 2);
1964 SemaRef, Kind, VD->getLocation(), VD->getType(),
1969 if (!VD->getType()->isDependentType() &&
1970 !VD->hasInit() && !VD->isCXXForRangeDecl()) {
1973 VD->getLocation(),
1985 SemaRef.Diag(VD->getLocation(),
2001 Cxx1yLoc = DS->getBeginLoc();
2006 SemaRef.Diag(DS->getBeginLoc(), diag::err_constexpr_body_invalid_stmt)
2007 << isa<CXXConstructorDecl>(Dcl) << Dcl->isConsteval();
2040 if (Field->isInvalidDecl())
2043 if (Field->isUnnamedBitField())
2049 if (Field->isAnonymousStructOrUnion() &&
2050 (Field->getType()->isUnionType()
2051 ? !Field->getType()->getAsCXXRecordDecl()->hasVariantMembers()
2052 : Field->getType()->getAsCXXRecordDecl()->isEmpty()))
2058 SemaRef.Diag(Dcl->getLocation(),
2064 SemaRef.Diag(Field->getLocation(),
2069 } else if (Field->isAnonymousStructOrUnion()) {
2070 const RecordDecl *RD = Field->getType()->castAs<RecordType>()->getDecl();
2071 for (auto *I : RD->fields())
2074 if (!RD->isUnion() || Inits.count(I))
2090 // - its function-body shall be [...] a compound-statement that contains only
2091 switch (S->getStmtClass()) {
2093 // - null statements,
2097 // - static_assert-declarations
2098 // - using-declarations,
2099 // - using-directives,
2100 // - typedef declarations and alias-declarations that do not define
2107 // - and exactly one return statement;
2111 Cxx1yLoc = S->getBeginLoc();
2115 ReturnStmts.push_back(S->getBeginLoc());
2122 SemaRef, Dcl, cast<AttributedStmt>(S)->getSubStmt(), ReturnStmts,
2126 // C++1y allows compound-statements.
2128 Cxx1yLoc = S->getBeginLoc();
2131 for (auto *BodyIt : CompStmt->body()) {
2140 // C++1y allows if-statements.
2142 Cxx1yLoc = S->getBeginLoc();
2145 if (!CheckConstexprFunctionStmt(SemaRef, Dcl, If->getThen(), ReturnStmts,
2148 if (If->getElse() &&
2149 !CheckConstexprFunctionStmt(SemaRef, Dcl, If->getElse(), ReturnStmts,
2165 Cxx1yLoc = S->getBeginLoc();
2166 for (Stmt *SubStmt : S->children()) {
2178 // C++1y allows switch-statements, and since they don't need variable
2181 Cxx1yLoc = S->getBeginLoc();
2182 for (Stmt *SubStmt : S->children()) {
2193 Cxx2bLoc = S->getBeginLoc();
2194 for (Stmt *SubStmt : S->children()) {
2207 Cxx2aLoc = S->getBeginLoc();
2208 for (Stmt *SubStmt : S->children()) {
2220 SemaRef, Dcl, cast<CXXCatchStmt>(S)->getHandlerBlock(), ReturnStmts,
2229 // C++1y allows expression-statements.
2231 Cxx1yLoc = S->getBeginLoc();
2236 SemaRef.Diag(S->getBeginLoc(), diag::err_constexpr_body_invalid_stmt)
2237 << isa<CXXConstructorDecl>(Dcl) << Dcl->isConsteval();
2256 // - its function-body shall be = delete, = default, or a
2257 // compound-statement
2261 // - its function-body shall not be a function-try-block;
2272 SemaRef.Diag(Body->getBeginLoc(),
2281 // - its function-body shall be [...] a compound-statement that contains only
2287 for (Stmt *SubStmt : Body->children()) {
2323 const CXXRecordDecl *RD = Constructor->getParent();
2325 // - every non-variant non-static data member and base class sub-object
2328 // - if the class is a union having variant members, exactly one of them
2330 if (RD->isUnion()) {
2331 if (Constructor->getNumCtorInitializers() == 0 &&
2332 RD->hasVariantMembers()) {
2335 Dcl->getLocation(),
2343 } else if (!Constructor->isDependentContext() &&
2344 !Constructor->isDelegatingConstructor()) {
2345 assert(RD->getNumVBases() == 0 && "constexpr ctor with virtual bases");
2351 for (CXXRecordDecl::field_iterator I = RD->field_begin(),
2352 E = RD->field_end(); I != E; ++I, ++Fields) {
2353 if (I->isAnonymousStructOrUnion()) {
2359 // - if the class is a union-like class, but is not a union, for each of
2363 Constructor->getNumCtorInitializers() != RD->getNumBases() + Fields) {
2364 // Check initialization of non-static data members. Base classes are
2368 for (const auto *I: Constructor->inits()) {
2369 if (FieldDecl *FD = I->getMember())
2371 else if (IndirectFieldDecl *ID = I->getIndirectMember())
2372 Inits.insert(ID->chain_begin(), ID->chain_end());
2376 for (auto *I : RD->fields())
2406 for (unsigned I = 0; I < ReturnStmts.size() - 1; ++I)
2422 // ill-formed; no diagnostic required.
2424 // - every constructor call and implicit conversion used in initializing the
2427 // - every constructor involved in initializing non-static data members and
2428 // base class sub-objects shall be a constexpr constructor.
2437 SemaRef.getSourceManager().isInSystemHeader(Dcl->getLocation()) ||
2439 diag::ext_constexpr_function_never_constant_expr, Dcl->getLocation());
2443 SemaRef.Diag(Dcl->getLocation(),
2445 << isa<CXXConstructorDecl>(Dcl) << Dcl->isConsteval()
2446 << Dcl->getNameInfo().getSourceRange();
2458 bool IsVoidOrDependentType = Dcl->getReturnType()->isVoidType() ||
2459 Dcl->getReturnType()->isDependentType();
2460 // Skip emitting a missing return error diagnostic for non-void functions
2471 SemaRef.Diag(Dcl->getLocation(),
2474 << Dcl->isConsteval();
2480 if (!getLangOpts().CPlusPlus20 || !FD->isImmediateEscalating())
2482 FD->setBodyContainsImmediateEscalatingExpressions(
2483 FSI->FoundImmediateEscalatingExpression);
2484 if (FSI->FoundImmediateEscalatingExpression) {
2485 auto it = UndefinedButUsed.find(FD->getCanonicalDecl());
2487 Diag(it->second, diag::err_immediate_function_used_before_definition)
2488 << it->first;
2489 Diag(FD->getLocation(), diag::note_defined_here) << FD;
2490 if (FD->isImmediateFunction() && !FD->isConsteval())
2499 assert(FD->isImmediateEscalating() && !FD->isConsteval() &&
2501 assert(FD->hasBody() && "expected the function to have a body");
2521 SourceLocation Loc = E->getBeginLoc();
2522 SourceRange Range = E->getSourceRange();
2524 Loc = CurrentConstructor->getLocation();
2525 Range = CurrentInit->isWritten() ? CurrentInit->getSourceRange()
2529 FieldDecl* InitializedField = CurrentInit ? CurrentInit->getAnyMember() : nullptr;
2532 << ImmediateFn << Fn << Fn->isConsteval() << IsCall
2535 << (CurrentInit && !CurrentInit->isWritten())
2540 dyn_cast<DeclRefExpr>(E->getCallee()->IgnoreImplicit());
2541 DR && DR->isImmediateEscalating()) {
2542 Diag(E, E->getDirectCallee(), /*IsCall=*/true);
2546 for (Expr *A : E->arguments())
2554 if (const auto *ReferencedFn = dyn_cast<FunctionDecl>(E->getDecl());
2555 ReferencedFn && E->isImmediateEscalating()) {
2564 CXXConstructorDecl *D = E->getConstructor();
2565 if (E->isImmediateEscalating()) {
2592 if (SS && SS->isInvalid())
2595 if (SS && SS->isNotEmpty()) {
2606 return CurDecl && &II == CurDecl->getIdentifier();
2616 if (SS && SS->isSet() && !SS->isInvalid()) {
2622 if (CurDecl && CurDecl->getIdentifier() && II != CurDecl->getIdentifier() &&
2623 3 * II->getName().edit_distance(CurDecl->getIdentifier()->getName())
2624 < II->getLength()) {
2625 II = CurDecl->getIdentifier();
2637 QualType BaseType = TInfo->getType();
2638 SourceLocation BaseLoc = TInfo->getTypeLoc().getBeginLoc();
2639 if (BaseType->containsErrors()) {
2644 if (EllipsisLoc.isValid() && !BaseType->containsUnexpandedParameterPack()) {
2646 << TInfo->getTypeLoc().getSourceRange();
2653 // A class-or-decltype shall denote a (possibly cv-qualified) class type
2654 // that is not an incompletely defined class; any cv-qualifiers are
2659 if (BaseDecl->isUnion()) {
2678 Class->setInvalidDecl();
2682 BaseDecl = BaseDecl->getDefinition();
2686 // "If a base-class has a code_seg attribute, derived classes must have the
2688 const auto *BaseCSA = BaseDecl->getAttr<CodeSegAttr>();
2689 const auto *DerivedCSA = Class->getAttr<CodeSegAttr>();
2692 BaseCSA->getName() != DerivedCSA->getName())) {
2693 Diag(Class->getLocation(), diag::err_mismatched_code_seg_base);
2694 Diag(BaseDecl->getLocation(), diag::note_base_class_specified_here)
2701 // - If the layout determines that a base comes before another base,
2703 // - If the layout determines that base comes before the derived class,
2705 if (BaseDecl->hasFlexibleArrayMember()) {
2707 << BaseDecl->getDeclName();
2712 // If a class is marked final and it appears as a base-type-specifier in
2713 // base-clause, the program is ill-formed.
2714 if (FinalAttr *FA = BaseDecl->getAttr<FinalAttr>()) {
2716 << BaseDecl->getDeclName() << FA->isSpelledAsSealed();
2717 Diag(BaseDecl->getLocation(), diag::note_entity_declared_at)
2718 << BaseDecl->getDeclName() << FA->getRange();
2723 if (BaseDecl->isInvalidDecl())
2724 Class->setInvalidDecl();
2725 } else if (BaseType->isDependentType()) {
2726 // Make sure that we don't make an ill-formed AST where the type of the
2727 // Class is non-dependent and its attached base class specifier is an
2729 // constexpr evaluator). If this case happens (in errory-recovery mode), we
2732 if (!Class->isDependentContext())
2733 Class->setInvalidDecl();
2735 // The base class is some non-dependent non-class type.
2741 if (getLangOpts().HLSL && Class->getTagKind() == TagTypeKind::Class &&
2747 SpecifierRange, Virtual, Class->getTagKind() == TagTypeKind::Class,
2765 Class->setIsParsingBaseSpecifiers();
2767 // We do not support any C++11 attributes on base-specifiers yet.
2790 if (Class->isUnion()) {
2791 Diag(Class->getLocation(), diag::err_base_clause_on_union)
2801 Class->setInvalidDecl();
2815 // a class -- it could be a template parm, for instance.
2816 if (auto Rec = Type->getAs<RecordType>()) {
2817 auto Decl = Rec->getAsCXXRecordDecl();
2820 for (const auto &BaseSpec : Decl->bases()) {
2845 // Copy non-redundant base specifiers into permanent storage.
2850 = Context.getCanonicalType(Bases[idx]->getType());
2858 Diag(Bases[idx]->getBeginLoc(), diag::err_duplicate_base_class)
2859 << KnownBase->getType() << Bases[idx]->getSourceRange();
2871 if (NewBaseType->isDependentType())
2877 if (const RecordType *Record = NewBaseType->getAs<RecordType>()) {
2878 const CXXRecordDecl *RD = cast<CXXRecordDecl>(Record->getDecl());
2879 if (Class->isInterface() &&
2880 (!RD->isInterfaceLike() ||
2881 KnownBase->getAccessSpecifier() != AS_public)) {
2884 Diag(KnownBase->getBeginLoc(), diag::err_invalid_base_in_interface)
2885 << getRecordDiagFromTagKind(RD->getTagKind()) << RD
2886 << RD->getSourceRange();
2889 if (RD->hasAttr<WeakAttr>())
2890 Class->addAttr(WeakAttr::CreateImplicit(Context));
2896 Class->setBases(Bases.data(), NumGoodBases);
2901 QualType BaseType = Bases[idx]->getType();
2905 if (BaseType->isDependentType())
2915 = Class->isDerivedFrom(CanonicalBase->getAsCXXRecordDecl(), Paths);
2920 Diag(Bases[idx]->getBeginLoc(), diag::warn_inaccessible_base_class)
2922 << Bases[idx]->getSourceRange();
2924 assert(Bases[idx]->isVirtual());
2948 CXXRecordDecl *DerivedRD = Derived->getAsCXXRecordDecl();
2952 CXXRecordDecl *BaseRD = Base->getAsCXXRecordDecl();
2958 if (BaseRD->isInvalidDecl() || DerivedRD->isInvalidDecl())
2963 if (!isCompleteType(Loc, Derived) && !DerivedRD->isBeingDefined())
2966 return DerivedRD->isDerivedFrom(BaseRD);
2974 CXXRecordDecl *DerivedRD = Derived->getAsCXXRecordDecl();
2978 CXXRecordDecl *BaseRD = Base->getAsCXXRecordDecl();
2982 if (!isCompleteType(Loc, Derived) && !DerivedRD->isBeingDefined())
2985 return DerivedRD->isDerivedFrom(BaseRD, Paths);
2994 for (unsigned I = Path.size(); I != 0; --I) {
2995 if (Path[I - 1].Base->isVirtual()) {
2996 Start = I - 1;
3037 // warns about this hierarchy under -Winaccessible-base, but MSVC allows the
3072 // We know that the derived-to-base conversion is ambiguous, and
3073 // we're going to produce a diagnostic. Perform the derived-to-base
3076 // the previous derived-to-base checks we've done, but at this point
3081 assert(StillOkay && "Can only be used with a derived-to-base conversion");
3085 // D -> B -> A, that will be used to illustrate the ambiguous
3112 if (DisplayedPaths.insert(Path->back().SubobjectNumber).second) {
3117 for (CXXBasePath::const_iterator Element = Path->begin();
3118 Element != Path->end(); ++Element)
3119 PathDisplayStr += " -> " + Element->Base->getType().getAsString();
3126 //===----------------------------------------------------------------------===//
3128 //===----------------------------------------------------------------------===//
3136 CurContext->addHiddenDecl(ASDecl);
3141 if (D->isInvalidDecl())
3145 if (!D->hasAttr<OverrideAttr>() && !D->hasAttr<FinalAttr>())
3151 if (MD && MD->isInstance() &&
3152 (MD->getParent()->hasAnyDependentBases() ||
3153 MD->getType()->isDependentType()))
3156 if (MD && !MD->isVirtual()) {
3157 // If we have a non-virtual method, check if it hides a virtual method.
3163 if (OverrideAttr *OA = D->getAttr<OverrideAttr>()) {
3164 Diag(OA->getLocation(),
3167 } else if (FinalAttr *FA = D->getAttr<FinalAttr>()) {
3168 Diag(FA->getLocation(),
3170 << (FA->isSpelledAsSealed() ? "sealed" : "final")
3174 MD->setInvalidDecl();
3181 if (!MD || !MD->isVirtual()) {
3182 if (OverrideAttr *OA = D->getAttr<OverrideAttr>()) {
3183 Diag(OA->getLocation(),
3185 << "override" << FixItHint::CreateRemoval(OA->getLocation());
3186 D->dropAttr<OverrideAttr>();
3188 if (FinalAttr *FA = D->getAttr<FinalAttr>()) {
3189 Diag(FA->getLocation(),
3191 << (FA->isSpelledAsSealed() ? "sealed" : "final")
3192 << FixItHint::CreateRemoval(FA->getLocation());
3193 D->dropAttr<FinalAttr>();
3199 // If a function is marked with the virt-specifier override and
3201 // ill-formed.
3202 bool HasOverriddenMethods = MD->size_overridden_methods() != 0;
3203 if (MD->hasAttr<OverrideAttr>() && !HasOverriddenMethods)
3204 Diag(MD->getLocation(), diag::err_function_marked_override_not_overriding)
3205 << MD->getDeclName();
3209 if (D->isInvalidDecl() || D->hasAttr<OverrideAttr>())
3212 if (!MD || MD->isImplicit() || MD->hasAttr<FinalAttr>())
3215 SourceLocation Loc = MD->getLocation();
3223 if (MD->size_overridden_methods() > 0) {
3226 Inconsistent && !Diags.isIgnored(DiagInconsistent, MD->getLocation())
3229 Diag(MD->getLocation(), DiagID) << MD->getDeclName();
3230 const CXXMethodDecl *OMD = *MD->begin_overridden_methods();
3231 Diag(OMD->getLocation(), diag::note_overridden_virtual_function);
3245 FinalAttr *FA = Old->getAttr<FinalAttr>();
3249 Diag(New->getLocation(), diag::err_final_function_overridden)
3250 << New->getDeclName()
3251 << FA->isSpelledAsSealed();
3252 Diag(Old->getLocation(), diag::note_overridden_virtual_function);
3257 const Type *T = FD.getType()->getBaseElementTypeUnsafe();
3258 // FIXME: Destruction of ObjC lifetime types has side-effects.
3259 if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
3260 return !RD->isCompleteDefinition() ||
3261 !RD->hasTrivialDefaultConstructor() ||
3262 !RD->hasTrivialDestructor();
3277 const auto Base = Specifier->getType()->getAsCXXRecordDecl();
3281 for (const auto Field : Base->lookup(FieldName)) {
3283 Field->getAccess() != AS_private) {
3284 assert(Field->getAccess() != AS_none);
3295 if (!RD->lookupInBases(FieldShadowed, Paths))
3299 auto Base = P.back().Base->getType()->getAsCXXRecordDecl();
3304 auto BaseField = It->second;
3305 assert(BaseField->getAccess() != AS_private);
3307 CXXRecordDecl::MergeAccess(P.Access, BaseField->getAccess())) {
3310 Diag(BaseField->getLocation(), diag::note_shadow_field);
3339 if (cast<CXXRecordDecl>(CurContext)->isInterface()) {
3341 // and prohibits constructors, destructors, operators, non-public member
3378 << (InvalidDecl-1) << Name;
3381 << (InvalidDecl-1) << "";
3387 // duration (auto, register) or with the extern storage-class-specifier.
3401 // declarator. Otherwise we could get follow-up errors.
3466 << SourceRange(D.getName().TemplateId->LAngleLoc,
3467 D.getName().TemplateId->RAngleLoc)
3468 << D.getName().TemplateId->LAngleLoc;
3513 // Non-instance-fields can't have a bitfield.
3515 if (Member->isInvalidDecl()) {
3518 // C++ 9.6p3: A bit-field shall not be a static member.
3519 // "static member 'A' cannot be a bit-field"
3521 << Name << BitWidth->getSourceRange();
3523 // "typedef member 'x' cannot be a bit-field"
3525 << Name << BitWidth->getSourceRange();
3528 // C++ 9.6p3: A bit-field shall have integral or enumeration type.
3530 << Name << cast<ValueDecl>(Member)->getType()
3531 << BitWidth->getSourceRange();
3535 Member->setInvalidDecl();
3540 NonTemplateMember = FunTmpl->getTemplatedDecl();
3542 NonTemplateMember = VarTmpl->getTemplatedDecl();
3544 Member->setAccess(AS);
3549 NonTemplateMember->setAccess(AS);
3555 auto *TD = DG->getDeducedTemplate();
3558 if (AS != TD->getAccess() &&
3559 TD->getDeclContext()->getRedeclContext()->Equals(
3560 DG->getDeclContext()->getRedeclContext())) {
3561 Diag(DG->getBeginLoc(), diag::err_deduction_guide_wrong_access);
3562 Diag(TD->getBeginLoc(), diag::note_deduction_guide_template_access)
3563 << TD->getAccess();
3565 for (const auto *D : cast<CXXRecordDecl>(CurContext)->decls()) {
3570 Diag(LastAccessSpec->getBeginLoc(), diag::note_deduction_guide_access)
3577 Member->addAttr(OverrideAttr::Create(Context, VS.getOverrideLoc()));
3579 Member->addAttr(FinalAttr::Create(Context, VS.getFinalLoc(),
3585 // Update the end location of a method that has a virt-specifiers.
3587 MD->setRangeEnd(VS.getLastLocation());
3592 assert((Name || isInstField) && "No identifier for non-field ?");
3596 FieldCollector->Add(FD);
3598 if (!Diags.isIgnored(diag::warn_unused_private_field, FD->getLocation())) {
3603 if (const TagDecl *TD = T->getAsTagDecl())
3604 return TD->hasAttr<UnusedAttr>();
3605 if (const TypedefType *TDT = T->getAs<TypedefType>())
3606 return TDT->getDecl()->hasAttr<UnusedAttr>();
3610 if (!FD->isImplicit() && FD->getDeclName() &&
3611 FD->getAccess() == AS_private &&
3612 !FD->hasAttr<UnusedAttr>() &&
3613 !FD->getParent()->isDependentContext() &&
3614 !DeclHasUnusedAttr(FD->getType()) &&
3636 // If non-null, add a note to the warning pointing back to the constructor.
3659 FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
3663 if (FD->getType()->isReferenceType())
3665 ME = dyn_cast<MemberExpr>(ME->getBase()->IgnoreParenImpCasts());
3677 UsedFieldIndex.push_back(FD->getFieldIndex());
3695 if (isa<EnumConstantDecl>(ME->getMemberDecl()))
3698 // FieldME is the inner-most MemberExpr that is not an anonymous struct
3702 bool AllPODFields = FieldME->getType().isPODType(S.Context);
3706 dyn_cast<MemberExpr>(Base->IgnoreParenImpCasts())) {
3708 if (isa<VarDecl>(SubME->getMemberDecl()))
3711 if (FieldDecl *FD = dyn_cast<FieldDecl>(SubME->getMemberDecl()))
3712 if (!FD->isAnonymousStructOrUnion())
3715 if (!FieldME->getType().isPODType(S.Context))
3718 Base = SubME->getBase();
3721 if (!isa<CXXThisExpr>(Base->IgnoreParenImpCasts())) {
3729 ValueDecl* FoundVD = FieldME->getMemberDecl();
3732 while (isa<ImplicitCastExpr>(BaseCast->getSubExpr())) {
3733 BaseCast = cast<ImplicitCastExpr>(BaseCast->getSubExpr());
3736 if (BaseCast->getCastKind() == CK_UncheckedDerivedToBase) {
3737 QualType T = BaseCast->getType();
3738 if (T->isPointerType() &&
3739 BaseClasses.count(T->getPointeeType())) {
3740 S.Diag(FieldME->getExprLoc(), diag::warn_base_class_is_uninit)
3741 << T->getPointeeType() << FoundVD;
3749 const bool IsReference = FoundVD->getType()->isReferenceType();
3765 S.Diag(FieldME->getExprLoc(), diag) << FoundVD;
3767 S.Diag(Constructor->getLocation(),
3769 << (Constructor->isDefaultConstructor() && Constructor->isImplicit());
3774 E = E->IgnoreParens();
3783 Visit(CO->getCond());
3784 HandleValue(CO->getTrueExpr(), AddressOf);
3785 HandleValue(CO->getFalseExpr(), AddressOf);
3791 Visit(BCO->getCond());
3792 HandleValue(BCO->getFalseExpr(), AddressOf);
3797 HandleValue(OVE->getSourceExpr(), AddressOf);
3802 switch (BO->getOpcode()) {
3807 HandleValue(BO->getLHS(), AddressOf);
3808 Visit(BO->getRHS());
3811 Visit(BO->getLHS());
3812 HandleValue(BO->getRHS(), AddressOf);
3822 for (auto *Child : ILE->children()) {
3857 BaseClasses.erase(BaseClass->getCanonicalTypeInternal());
3866 if (E->getCastKind() == CK_LValueToRValue) {
3867 HandleValue(E->getSubExpr(), false /*AddressOf*/);
3875 if (E->getConstructor()->isCopyConstructor()) {
3876 Expr *ArgExpr = E->getArg(0);
3878 if (ILE->getNumInits() == 1)
3879 ArgExpr = ILE->getInit(0);
3881 if (ICE->getCastKind() == CK_NoOp)
3882 ArgExpr = ICE->getSubExpr();
3890 Expr *Callee = E->getCallee();
3893 for (auto *Arg : E->arguments())
3903 if (E->isCallToStdMove()) {
3904 HandleValue(E->getArg(0), /*AddressOf=*/false);
3912 Expr *Callee = E->getCallee();
3918 for (auto *Arg : E->arguments())
3919 HandleValue(Arg->IgnoreParenImpCasts(), false /*AddressOf*/);
3925 if (E->getOpcode() == BO_Assign)
3926 if (MemberExpr *ME = dyn_cast<MemberExpr>(E->getLHS()))
3927 if (FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl()))
3928 if (!FD->getType()->isReferenceType())
3931 if (E->isCompoundAssignmentOp()) {
3932 HandleValue(E->getLHS(), false /*AddressOf*/);
3933 Visit(E->getRHS());
3941 if (E->isIncrementDecrementOp()) {
3942 HandleValue(E->getSubExpr(), false /*AddressOf*/);
3945 if (E->getOpcode() == UO_AddrOf) {
3946 if (MemberExpr *ME = dyn_cast<MemberExpr>(E->getSubExpr())) {
3947 HandleValue(ME->getBase(), true /*AddressOf*/);
3956 // Diagnose value-uses of fields to initialize themselves, e.g.
3961 // TODO: implement -Wuninitialized and fold this into that framework.
3966 Constructor->getLocation())) {
3970 if (Constructor->isInvalidDecl())
3973 const CXXRecordDecl *RD = Constructor->getParent();
3975 if (RD->isDependentContext())
3982 for (auto *I : RD->decls()) {
3986 UninitializedFields.insert(IFD->getAnonField());
3991 for (const auto &I : RD->bases())
4001 for (const auto *FieldInit : Constructor->inits()) {
4005 Expr *InitExpr = FieldInit->getInit();
4011 InitExpr = Default->getExpr();
4016 FieldInit->getAnyMember(),
4017 FieldInit->getBaseClass());
4020 FieldInit->getAnyMember(),
4021 FieldInit->getBaseClass());
4042 if (ParamDecl->getDeclName())
4072 FD->getInClassInitStyle() == ICIS_ListInit
4073 ? InitializationKind::CreateDirectList(InitExpr->getBeginLoc(),
4074 InitExpr->getBeginLoc(),
4075 InitExpr->getEndLoc())
4076 : InitializationKind::CreateCopy(InitExpr->getBeginLoc(), InitLoc);
4088 assert((isa<MSPropertyDecl>(D) || FD->getInClassInitStyle() != ICIS_NoInit) &&
4092 D->setInvalidDecl();
4094 FD->removeInClassInitializer();
4099 FD->setInvalidDecl();
4100 FD->removeInClassInitializer();
4107 if (!FD->getType()->isDependentType() && !Init.get()->isTypeDependent()) {
4111 // full-expression.
4115 FD->setInvalidDecl();
4120 FD->setInClassInitializer(Init.get());
4133 for (const auto &Base : ClassDecl->bases()) {
4143 // FIXME: We might be able to short-circuit this if we know in advance that
4146 if (!DirectBaseSpec || !DirectBaseSpec->isVirtual()) {
4151 if (SemaRef.IsDerivedFrom(ClassDecl->getLocation(),
4156 if (Path->back().Base->isVirtual()) {
4157 VirtualBaseSpec = Path->back().Base;
4202 // initializer: either a non-static field member or a base class.
4211 return Member->getDeclContext()->getRedeclContext()->Equals(ClassDecl);
4230 DeclContextLookupResult Result = ClassDecl->lookup(Name);
4234 Elem->isPlaceholderVar(getLangOpts());
4242 if (ND->getDeclContext() != ND->getDeclContext())
4245 ND->isPlaceholderVar(getLangOpts()))
4246 Diag(ND->getLocation(), diag::note_reference_placeholder) << ND;
4255 for (auto *D : ClassDecl->lookup(MemberOrBase)) {
4257 bool IsPlaceholder = D->isPlaceholderVar(getLangOpts());
4259 if (IsPlaceholder && D->getDeclContext() == ND->getDeclContext())
4311 CXXRecordDecl *ClassDecl = Constructor->getParent();
4314 // Names in a mem-initializer-id are looked up in the scope of the
4319 // mem-initializer-id naming the member or base class and composed
4321 // mem-initializer-id for the hidden base class may be specified
4330 << SourceRange(IdLoc, Init->getSourceRange().getEnd());
4359 // We don't want access-control diagnostics here.
4366 NotUnknownSpecialization = !Record->hasAnyDependentBases();
4379 TInfo->getTypeLoc().castAs<DependentNameTypeLoc>();
4394 UnqualifiedBase->getInjectedClassNameSpecialization());
4395 TemplateName TN = TempSpec->getTemplateName();
4396 for (auto const &Base : ClassDecl->bases()) {
4398 Base.getType()->getAs<TemplateSpecializationType>();
4400 BaseTemplate->getTemplateName(), TN)) {
4402 << SourceRange(IdLoc, Init->getSourceRange().getEnd());
4417 // We have found a non-static data member with a similar
4440 Diag(BaseSpec->getBeginLoc(), diag::note_base_class_specified_here)
4441 << BaseSpec->getType() << BaseSpec->getSourceRange();
4450 << MemberOrBase << SourceRange(IdLoc,Init->getSourceRange().getEnd());
4458 MarkAnyDeclReferenced(TyD->getLocation(), TyD, /*OdrUse=*/false);
4460 ElaboratedTypeLoc TL = TInfo->getTypeLoc().castAs<ElaboratedTypeLoc>();
4484 if (Member->isInvalidDecl())
4489 Args = MultiExprArg(ParenList->getExprs(), ParenList->getNumExprs());
4491 Args = MultiExprArg(InitList->getInits(), InitList->getNumInits());
4497 SourceRange InitRange = Init->getSourceRange();
4499 if (Member->getType()->isDependentType() || Init->isTypeDependent()) {
4501 // any of the arguments are type-dependent expressions.
4517 IdLoc, Init->getBeginLoc(), Init->getEndLoc())
4527 // full-expression.
4536 Member->getType())
4559 SourceLocation NameLoc = TInfo->getTypeLoc().getSourceRange().getBegin();
4562 << TInfo->getTypeLoc().getSourceRange();
4569 Args = MultiExprArg(ParenList->getExprs(), ParenList->getNumExprs());
4572 SourceRange InitRange = Init->getSourceRange();
4575 QualType(ClassDecl->getTypeForDecl(), 0));
4578 NameLoc, Init->getBeginLoc(), Init->getEndLoc())
4585 assert((DelegationInit.get()->containsErrors() ||
4586 cast<CXXConstructExpr>(DelegationInit.get())->getConstructor()) &&
4591 // full-expression.
4599 QualType(ClassDecl->getTypeForDecl(), 0));
4604 // perform this type-checking again. Just save the arguments that we
4610 if (CurContext->isDependentContext())
4623 SourceLocation BaseLoc = BaseTInfo->getTypeLoc().getBeginLoc();
4625 if (!BaseType->isDependentType() && !BaseType->isRecordType())
4627 << BaseType << BaseTInfo->getTypeLoc().getSourceRange();
4630 // [...] Unless the mem-initializer-id names a nonstatic data
4632 // of that class, the mem-initializer is ill-formed. A
4633 // mem-initializer-list can initialize a base class using any
4636 // We can store the initializers in "as-written" form and delay analysis until
4638 // (broken) code in a non-template! SetCtorInitializers does not expect this.
4639 bool Dependent = CurContext->isDependentContext() &&
4640 (BaseType->isDependentType() || Init->isTypeDependent());
4642 SourceRange InitRange = Init->getSourceRange();
4645 if (!BaseType->containsUnexpandedParameterPack()) {
4664 if (Context.hasSameUnqualifiedType(QualType(ClassDecl->getTypeForDecl(),0),
4672 // Unless the mem-initializer-id names a nonstatic data member of the
4674 // mem-initializer is ill-formed.
4681 if (ClassDecl->hasAnyDependentBases())
4686 << BaseTInfo->getTypeLoc().getSourceRange();
4700 // If a mem-initializer-id is ambiguous because it designates both
4701 // a direct non-virtual base class and an inherited virtual base
4702 // class, the mem-initializer is ill-formed.
4705 << BaseType << BaseTInfo->getTypeLoc().getLocalSourceRange();
4716 Args = MultiExprArg(ParenList->getExprs(), ParenList->getNumExprs());
4730 // full-expression.
4742 // perform this type-checking again. Just save the arguments that we
4748 if (CurContext->isDependentContext())
4753 BaseSpec->isVirtual(),
4762 SemaRef.BuildReferenceType(E->getType(), /*SpelledAsLValue*/ false,
4764 SourceLocation ExprLoc = E->getBeginLoc();
4770 E->getSourceRange()).get();
4773 /// ImplicitInitializerKind - How an implicit base or member initializer should
4798 = InitializationKind::CreateDefault(Constructor->getLocation());
4807 ParmVarDecl *Param = Constructor->getParamDecl(0);
4808 QualType ParamType = Param->getType().getNonReferenceType();
4813 Constructor->getLocation(), ParamType,
4820 SemaRef.Context.getQualifiedType(BaseSpec->getType().getUnqualifiedType(),
4835 = InitializationKind::CreateDirect(Constructor->getLocation(),
4849 SemaRef.Context.getTrivialTypeSourceInfo(BaseSpec->getType(),
4851 BaseSpec->isVirtual(),
4861 ValueDecl *Referenced = cast<MemberExpr>(MemRef)->getMemberDecl();
4862 return Referenced->getType()->isRValueReferenceType();
4870 if (Field->isInvalidDecl())
4873 SourceLocation Loc = Constructor->getLocation();
4877 ParmVarDecl *Param = Constructor->getParamDecl(0);
4878 QualType ParamType = Param->getType().getNonReferenceType();
4880 // Suppress copying zero-width bitfields.
4881 if (Field->isZeroLengthBitField(SemaRef.Context))
4897 LookupResult MemberLookup(SemaRef, Field->getDeclName(), Loc,
4916 // - if a member m has rvalue reference type T&&, it is direct-initialized
4928 // Direct-initialize to use the copy constructor.
4953 SemaRef.Context.getBaseElementType(Field->getType());
4955 if (FieldBaseElementType->isRecordType()) {
4986 if (!Field->getParent()->isUnion()) {
4987 if (FieldBaseElementType->isReferenceType()) {
4988 SemaRef.Diag(Constructor->getLocation(),
4990 << (int)Constructor->isImplicit()
4991 << SemaRef.Context.getTagDeclType(Constructor->getParent())
4992 << 0 << Field->getDeclName();
4993 SemaRef.Diag(Field->getLocation(), diag::note_declared_at);
4998 SemaRef.Diag(Constructor->getLocation(),
5000 << (int)Constructor->isImplicit()
5001 << SemaRef.Context.getTagDeclType(Constructor->getParent())
5002 << 1 << Field->getDeclName();
5003 SemaRef.Diag(Field->getLocation(), diag::note_declared_at);
5010 // Default-initialize Objective-C pointers to NULL.
5014 new (SemaRef.Context) ImplicitValueInitExpr(Field->getType()),
5036 bool Generated = Ctor->isImplicit() || Ctor->isDefaulted();
5037 if (Ctor->getInheritedConstructor())
5039 else if (Generated && Ctor->isCopyConstructor())
5041 else if (Generated && Ctor->isMoveConstructor())
5065 if (Init->getInit()->HasSideEffects(S.Context))
5066 S.UnusedPrivateFields.remove(Init->getAnyMember());
5072 RecordDecl *Record = Field->getParent();
5073 if (!Record->isUnion())
5077 ActiveUnionMember.lookup(Record->getCanonicalDecl()))
5078 return Active != Field->getCanonicalDecl();
5080 // In an implicit copy or move constructor, ignore any in-class initializer.
5085 // has an in-class initializer...
5086 if (Field->hasInClassInitializer())
5088 // ... or it's an anonymous struct or union whose class has an in-class
5090 if (!Field->isAnonymousStructOrUnion())
5092 CXXRecordDecl *FieldRD = Field->getType()->getAsCXXRecordDecl();
5093 return !FieldRD->hasInClassInitializer();
5104 for (auto *C : Indirect->chain()) {
5114 /// Determine whether the given type is an incomplete or zero-lenfgth
5117 if (T->isIncompleteArrayType())
5121 if (ArrayT->isZeroSize())
5124 T = ArrayT->getElementType();
5133 if (Field->isInvalidDecl())
5138 Info.AllBaseFields.lookup(Field->getCanonicalDecl()))
5142 // if the entity is a non-static data member that has a
5143 // brace-or-equal-initializer and either
5144 // -- the constructor's class is a union and no other variant member of that
5145 // union is designated by a mem-initializer-id or
5146 // -- the constructor's class is not a union, and, if the entity is a member
5148 // a mem-initializer-id,
5156 if (Field->hasInClassInitializer() && !Info.isImplicitCopyOrMove()) {
5158 SemaRef.BuildCXXDefaultInitExpr(Info.Ctor->getLocation(), Field);
5177 // Don't initialize incomplete or zero-length arrays.
5178 if (isIncompleteOrZeroLengthArrayType(SemaRef.Context, Field->getType()))
5201 assert(Initializer->isDelegatingInitializer());
5202 Constructor->setNumCtorInitializers(1);
5206 Constructor->setCtorInitializers(initializer);
5208 if (CXXDestructorDecl *Dtor = LookupDestructor(Constructor->getParent())) {
5209 MarkFunctionReferenced(Initializer->getSourceLocation(), Dtor);
5210 DiagnoseUseOfDecl(Dtor, Initializer->getSourceLocation());
5222 if (Constructor->isDependentContext()) {
5226 Constructor->setNumCtorInitializers(Initializers.size());
5231 Constructor->setCtorInitializers(baseOrMemberInitializers);
5236 Constructor->setInvalidDecl();
5245 CXXRecordDecl *ClassDecl = Constructor->getParent()->getDefinition();
5254 if (Member->isBaseInitializer())
5255 Info.AllBaseFields[Member->getBaseClass()->getAs<RecordType>()] = Member;
5257 Info.AllBaseFields[Member->getAnyMember()->getCanonicalDecl()] = Member;
5259 if (IndirectFieldDecl *F = Member->getIndirectMember()) {
5260 for (auto *C : F->chain()) {
5262 if (FD && FD->getParent()->isUnion())
5264 FD->getParent()->getCanonicalDecl(), FD->getCanonicalDecl()));
5266 } else if (FieldDecl *FD = Member->getMember()) {
5267 if (FD->getParent()->isUnion())
5269 FD->getParent()->getCanonicalDecl(), FD->getCanonicalDecl()));
5276 for (auto &I : ClassDecl->bases()) {
5282 for (auto &VBase : ClassDecl->vbases()) {
5284 = Info.AllBaseFields.lookup(VBase.getType()->getAs<RecordType>())) {
5286 // A mem-initializer where the mem-initializer-id names a virtual base
5289 if (ClassDecl->isAbstract()) {
5292 Diag(Value->getSourceLocation(), diag::warn_abstract_vbase_init_ignored)
5298 } else if (!AnyErrors && !ClassDecl->isAbstract()) {
5300 // If a given [...] base class is not named by a mem-initializer-id
5302 // class, then [...] the entity is default-initialized.
5316 // Non-virtual bases.
5317 for (auto &Base : ClassDecl->bases()) {
5323 = Info.AllBaseFields.lookup(Base.getType()->getAs<RecordType>())) {
5339 for (auto *Mem : ClassDecl->decls()) {
5342 // A declaration for a bit-field that omits the identifier declares an
5343 // unnamed bit-field. Unnamed bit-fields are not members and cannot be
5345 if (F->isUnnamedBitField())
5351 if (F->isAnonymousStructOrUnion() && !Info.isImplicitCopyOrMove())
5364 if (F->getType()->isIncompleteArrayType()) {
5365 assert(ClassDecl->hasFlexibleArrayMember() &&
5371 if (CollectFieldInitializer(*this, Info, F->getAnonField(), F))
5380 Constructor->setNumCtorInitializers(NumInitializers);
5385 Constructor->setCtorInitializers(baseOrMemberInitializers);
5389 MarkBaseAndMemberDestructorsReferenced(Constructor->getLocation(),
5390 Constructor->getParent());
5397 if (const RecordType *RT = Field->getType()->getAs<RecordType>()) {
5398 const RecordDecl *RD = RT->getDecl();
5399 if (RD->isAnonymousStructOrUnion()) {
5400 for (auto *Field : RD->fields())
5405 IdealInits.push_back(Field->getCanonicalDecl());
5414 if (!Member->isAnyMemberInitializer())
5415 return GetKeyForBase(Context, QualType(Member->getBaseClass(), 0));
5417 return Member->getAnyMember()->getCanonicalDecl();
5423 if (Previous->isAnyMemberInitializer())
5424 Diag << 0 << Previous->getAnyMember();
5426 Diag << 1 << Previous->getTypeSourceInfo()->getType();
5428 if (Current->isAnyMemberInitializer())
5429 Diag << 0 << Current->getAnyMember();
5431 Diag << 1 << Current->getTypeSourceInfo()->getType();
5437 if (Constructor->getDeclContext()->isDependentContext())
5446 Init->getSourceLocation())) {
5459 const CXXRecordDecl *ClassDecl = Constructor->getParent();
5462 for (const auto &VBase : ClassDecl->vbases())
5465 // 2. Non-virtual bases.
5466 for (const auto &Base : ClassDecl->bases()) {
5473 for (auto *Field : ClassDecl->fields()) {
5474 if (Field->isUnnamedBitField())
5486 // Correlates the index of an initializer in the init-list to the index of
5526 Inits[WarnIndexes.front() - 1]->getSourceLocation(),
5535 // modified by another fix-it.
5537 Inits[I]->getSourceRange(),
5540 Inits[CorrelatedInitOrder[I].second]->getSourceRange()),
5547 AddInitializerToDiag(D, Inits[WarnIndexes.front() - 1],
5555 const clang::CXXCtorInitializer *PrevInit = Inits[WarnIndex - 1];
5556 auto D = SemaRef.Diag(PrevInit->getSourceLocation(),
5559 D << PrevInit->getSourceRange();
5572 if (FieldDecl *Field = Init->getAnyMember())
5573 S.Diag(Init->getSourceLocation(),
5575 << Field->getDeclName()
5576 << Init->getSourceRange();
5578 const Type *BaseClass = Init->getBaseClass();
5580 S.Diag(Init->getSourceLocation(),
5583 << Init->getSourceRange();
5585 S.Diag(PrevInit->getSourceLocation(), diag::note_previous_initializer)
5586 << 0 << PrevInit->getSourceRange();
5597 FieldDecl *Field = Init->getAnyMember();
5598 RecordDecl *Parent = Field->getParent();
5601 while (Parent->isAnonymousStructOrUnion() || Parent->isUnion()) {
5602 if (Parent->isUnion()) {
5605 S.Diag(Init->getSourceLocation(),
5607 << Field->getDeclName()
5608 << Init->getSourceRange();
5609 S.Diag(En.second->getSourceLocation(), diag::note_previous_initializer)
5610 << 0 << En.second->getSourceRange();
5617 if (!Parent->isAnonymousStructOrUnion())
5622 Parent = cast<RecordDecl>(Parent->getDeclContext());
5651 // Mapping for the inconsistent anonymous-union initializers check.
5659 Init->setSourceOrder(i);
5661 if (Init->isAnyMemberInitializer()) {
5666 } else if (Init->isBaseInitializer()) {
5671 assert(Init->isDelegatingInitializer());
5674 Diag(Init->getSourceLocation(),
5676 << Init->getSourceRange() << MemInits[i ? 0 : 1]->getSourceRange();
5700 if (ClassDecl->isDependentContext() || ClassDecl->isUnion())
5703 // FIXME: all the access-control diagnostics are positioned on the
5708 // Non-static data members.
5709 for (auto *Field : ClassDecl->fields()) {
5710 if (Field->isInvalidDecl())
5713 // Don't destroy incomplete or zero-length arrays.
5714 if (isIncompleteOrZeroLengthArrayType(Context, Field->getType()))
5717 QualType FieldType = Context.getBaseElementType(Field->getType());
5719 const RecordType* RT = FieldType->getAs<RecordType>();
5723 CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getDecl());
5724 if (FieldClassDecl->isInvalidDecl())
5726 if (FieldClassDecl->hasIrrelevantDestructor())
5729 if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
5736 CheckDestructorAccess(Field->getLocation(), Dtor,
5738 << Field->getDeclName()
5747 bool VisitVirtualBases = !ClassDecl->isAbstract();
5753 CXXDestructorDecl *Dtor = ClassDecl->getDestructor();
5754 if (Dtor && Dtor->isUsed())
5761 for (const auto &Base : ClassDecl->bases()) {
5762 const RecordType *RT = Base.getType()->getAs<RecordType>();
5773 CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(RT->getDecl());
5775 if (BaseClassDecl->isInvalidDecl())
5777 if (BaseClassDecl->hasIrrelevantDestructor())
5804 for (const auto &VBase : ClassDecl->vbases()) {
5805 // Bases are always records in a well-formed non-dependent class.
5806 const RecordType *RT = VBase.getType()->castAs<RecordType>();
5809 if (DirectVirtualBases && DirectVirtualBases->count(RT))
5812 CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(RT->getDecl());
5814 if (BaseClassDecl->isInvalidDecl())
5816 if (BaseClassDecl->hasIrrelevantDestructor())
5824 ClassDecl->getLocation(), Dtor,
5831 diag::err_access_dtor_vbase, 0, ClassDecl->getLocation(),
5846 if (CXXRecordDecl *ClassDecl = Constructor->getParent();
5847 !ClassDecl || ClassDecl->isInvalidDecl()) {
5859 const auto *RD = Context.getBaseElementType(T)->getAsCXXRecordDecl();
5869 const CXXRecordDecl *Def = RD->getDefinition();
5870 if (!Def || Def->isBeingDefined())
5873 return RD->isAbstract();
5883 DiagnoseAbstractType(T->getAsCXXRecordDecl());
5890 if (PureVirtualClassDiagSet && PureVirtualClassDiagSet->count(RD))
5900 RD->getFinalOverriders(FinalOverriders);
5910 for (OverridingMethods::iterator SO = M->second.begin(),
5911 SOEnd = M->second.end();
5919 if (SO->second.size() != 1)
5922 if (!SO->second.front().Method->isPureVirtual())
5925 if (!SeenPureMethods.insert(SO->second.front().Method).second)
5928 Diag(SO->second.front().Method->getLocation(),
5930 << SO->second.front().Method->getDeclName() << RD->getDeclName();
5936 PureVirtualClassDiagSet->insert(RD);
5983 TypeSourceInfo *TSI = TL.getParam(I)->getTypeSourceInfo();
5984 if (TSI) Visit(TSI->getTypeLoc(), Sema::AbstractParamType);
5998 Visit(TSI->getTypeLoc(), Sema::AbstractNone);
6029 if (T->isArrayType()) {
6033 CanQualType CT = T->getCanonicalTypeUnqualified().getUnqualifiedType();
6039 Info.S.Diag(Ctx->getLocation(), diag::err_array_of_abstract_type)
6042 Info.S.Diag(Ctx->getLocation(), diag::err_abstract_type_in_decl)
6060 // non-abstract types.
6061 if (!FD->doesThisDeclarationHaveABody())
6065 // information. This should never happen for non-implicit methods,
6067 if (TypeSourceInfo *TSI = FD->getTypeSourceInfo())
6068 Info.CheckType(FD, TSI->getTypeLoc(), Sema::AbstractNone);
6076 if (VD->isThisDeclarationADefinition())
6079 Info.CheckType(VD, VD->getTypeSourceInfo()->getTypeLoc(),
6086 for (auto *D : RD->decls()) {
6087 if (D->isImplicit()) continue;
6091 D = FD->getFriendDecl();
6099 CheckAbstractClassUsage(Info, FTD->getTemplatedDecl());
6103 if (TypeSourceInfo *TSI = FD->getTypeSourceInfo())
6104 Info.CheckType(FD, TSI->getTypeLoc(), Sema::AbstractFieldType);
6108 CheckAbstractClassUsage(Info, VTD->getTemplatedDecl());
6114 CheckAbstractClassUsage(Info, CTD->getTemplatedDecl());
6124 assert(ClassAttr->getKind() == attr::DLLExport);
6126 TemplateSpecializationKind TSK = Class->getTemplateSpecializationKind();
6148 } MarkingDllexportedContext(S, Class, ClassAttr->getLocation());
6151 S.MarkVTableUsed(Class->getLocation(), Class, true);
6153 for (Decl *Member : Class->decls()) {
6155 if (!Member->hasAttr<DLLExportAttr>())
6161 if (VD && VD->getStorageClass() == SC_Static &&
6163 S.MarkVariableReferenced(VD->getLocation(), VD);
6169 if (MD->isUserProvided()) {
6170 // Instantiate non-default class member functions ...
6173 if (TSK == TSK_ImplicitInstantiation && !ClassAttr->isInherited())
6180 if (CD && CD->isDefaultConstructor() && TSK == TSK_Undeclared) {
6185 S.MarkFunctionReferenced(Class->getLocation(), MD);
6189 } else if (MD->isExplicitlyDefaulted()) {
6191 S.MarkFunctionReferenced(Class->getLocation(), MD);
6198 } else if (!MD->isTrivial() ||
6199 MD->isCopyAssignmentOperator() ||
6200 MD->isMoveAssignmentOperator()) {
6201 // Synthesize and instantiate non-trivial implicit methods, and the copy
6203 // are trivial, because the address of an operator can be taken and
6205 S.MarkFunctionReferenced(Class->getLocation(), MD);
6222 for (Decl *Member : Class->decls()) {
6225 if (!CD || !CD->isDefaultConstructor())
6227 auto *Attr = CD->getAttr<DLLExportAttr>();
6231 // If the class is non-dependent, mark the default arguments as ODR-used so
6233 if (!Class->isDependentContext()) {
6234 for (ParmVarDecl *PD : CD->parameters()) {
6235 (void)S.CheckCXXDefaultArgExpr(Attr->getLocation(), CD, PD);
6241 S.Diag(LastExportedDefaultCtor->getLocation(),
6244 S.Diag(CD->getLocation(), diag::note_entity_declared_at)
6245 << CD->getDeclName();
6259 S.Diag(TD->getLocation(),
6265 ClassTemplateDecl *TD = Class->getDescribedClassTemplate();
6269 S.Diag(Class->getLocation(),
6272 S.Diag(Class->getLocation(),
6277 TD = SD->getSpecializedTemplate();
6280 TemplateParameterList *Params = TD->getTemplateParameters();
6281 unsigned N = Params->size();
6285 S.Diag(TD->getLocation(),
6289 if (N > 0 && !isa<TemplateTypeParmDecl>(Params->getParam(0))) {
6291 S.Diag(TD->getLocation(),
6296 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Params->getParam(1));
6297 if (!NTTP || !NTTP->getType()->isIntegralOrEnumerationType()) {
6299 S.Diag(TD->getLocation(),
6313 S.Diag(TD->getLocation(),
6319 ClassTemplateDecl *TD = Class->getDescribedClassTemplate();
6323 S.Diag(Class->getLocation(),
6326 S.Diag(Class->getLocation(),
6331 TD = SD->getSpecializedTemplate();
6334 TemplateParameterList *Params = TD->getTemplateParameters();
6335 unsigned N = Params->size();
6339 S.Diag(TD->getLocation(),
6343 if (N > 0 && !isa<TemplateTypeParmDecl>(Params->getParam(0))) {
6345 S.Diag(TD->getLocation(),
6350 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Params->getParam(1));
6351 if (!NTTP || !NTTP->getType()->isIntegralOrEnumerationType()) {
6353 S.Diag(TD->getLocation(),
6359 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Params->getParam(2));
6360 if (!NTTP || !NTTP->getType()->isIntegralOrEnumerationType()) {
6362 S.Diag(TD->getLocation(),
6370 // Mark any compiler-generated routines with the implicit code_seg attribute.
6371 for (auto *Method : Class->methods()) {
6372 if (Method->isUserProvided())
6375 Method->addAttr(A);
6386 getDLLAttr(Spec->getSpecializedTemplate()->getTemplatedDecl())) {
6387 auto *A = cast<InheritableAttr>(TemplateAttr->clone(getASTContext()));
6388 A->setInherited(true);
6403 (!Class->isExternallyVisible() && Class->hasExternalFormalLinkage())) {
6404 Class->dropAttrs<DLLExportAttr, DLLImportAttr>();
6408 if (!Class->isExternallyVisible()) {
6409 Diag(Class->getLocation(), diag::err_attribute_dll_not_extern)
6415 !ClassAttr->isInherited()) {
6417 for (Decl *Member : Class->decls()) {
6421 if (!MemberAttr || MemberAttr->isInherited() || Member->isInvalidDecl())
6424 Diag(MemberAttr->getLocation(),
6427 Diag(ClassAttr->getLocation(), diag::note_previous_attribute);
6428 Member->setInvalidDecl();
6432 if (Class->getDescribedClassTemplate())
6437 const bool ClassExported = ClassAttr->getKind() == attr::DLLExport;
6444 cast<DLLImportAttr>(ClassAttr)->wasPropagatedToBaseTemplate();
6446 TemplateSpecializationKind TSK = Class->getTemplateSpecializationKind();
6450 if (ClassExported && !ClassAttr->isInherited() &&
6453 Class->dropAttr<DLLExportAttr>();
6463 for (Decl *Member : Class->decls()) {
6473 if (MD->isDeleted())
6476 if (MD->isInlined()) {
6488 if ((MD->isMoveAssignmentOperator() ||
6489 (Ctor && Ctor->isMoveConstructor())) &&
6493 // MSVC2015 doesn't export trivial defaulted x-tor but copy assign
6496 (Ctor || isa<CXXDestructorDecl>(MD)) && MD->isTrivial())
6506 if (!cast<NamedDecl>(Member)->isExternallyVisible())
6512 // Do not export/import inline function when -fno-dllexport-inlines is
6513 // passed. But add attribute for later local static var check.
6514 if (!getLangOpts().DllExportInlines && MD && MD->isInlined() &&
6525 NewAttr = cast<InheritableAttr>(ClassAttr->clone(getASTContext()));
6528 NewAttr->setInherited(true);
6529 Member->addAttr(NewAttr);
6532 // Propagate DLLAttr to friend re-declarations of MD that have already
6534 for (FunctionDecl *FD = MD->getMostRecentDecl(); FD;
6535 FD = FD->getPreviousDecl()) {
6536 if (FD->getFriendObjectKind() == Decl::FOK_None)
6539 "friend re-decl should not already have a DLLAttr");
6540 NewAttr = cast<InheritableAttr>(ClassAttr->clone(getASTContext()));
6541 NewAttr->setInherited(true);
6542 FD->addAttr(NewAttr);
6556 BaseTemplateSpec->getSpecializedTemplate()->getTemplatedDecl())) {
6561 auto TSK = BaseTemplateSpec->getSpecializationKind();
6568 auto *NewAttr = cast<InheritableAttr>(ClassAttr->clone(getASTContext()));
6569 NewAttr->setInherited(true);
6570 BaseTemplateSpec->addAttr(NewAttr);
6575 ImportAttr->setPropagatedToBaseTemplate();
6597 << BaseTemplateSpec->isExplicitSpecialization();
6598 Diag(ClassAttr->getLocation(), diag::note_attribute);
6599 if (BaseTemplateSpec->isExplicitSpecialization()) {
6600 Diag(BaseTemplateSpec->getLocation(),
6604 Diag(BaseTemplateSpec->getPointOfInstantiation(),
6614 if (Ctor->isDefaultConstructor())
6617 if (Ctor->isCopyConstructor())
6620 if (Ctor->isMoveConstructor())
6624 if (MD->isCopyAssignmentOperator())
6627 if (MD->isMoveAssignmentOperator())
6634 switch (FD->getDeclName().getCXXOverloadedOperator()) {
6699 if (D->isDependentType() || D->isInvalidDecl())
6702 // Clang <= 4 used the pre-C++11 rule, which ignores move operations.
6705 return !D->hasNonTrivialDestructorForCall() &&
6706 !D->hasNonTrivialCopyConstructorForCall();
6715 // Note: This permits classes with non-trivial copy or move ctors to be
6717 // which is non-conforming.
6718 if (D->needsImplicitCopyConstructor()) {
6719 if (!D->defaultedCopyConstructorIsDeleted()) {
6720 if (D->hasTrivialCopyConstructor())
6722 if (D->hasTrivialCopyConstructorForCall())
6726 for (const CXXConstructorDecl *CD : D->ctors()) {
6727 if (CD->isCopyConstructor() && !CD->isDeleted() &&
6728 !CD->isIneligibleOrNotSelected()) {
6729 if (CD->isTrivial())
6731 if (CD->isTrivialForCall())
6737 if (D->needsImplicitDestructor()) {
6738 if (!D->defaultedDestructorIsDeleted() &&
6739 D->hasTrivialDestructorForCall())
6741 } else if (const auto *DD = D->getDestructor()) {
6742 if (!DD->isDeleted() && DD->isTrivialForCall())
6746 // If the copy ctor and dtor are both trivial-for-calls, pass direct.
6753 // stack slot. Most objects with dtors are large-ish, so handle that early.
6759 // passed in registers, which is non-conforming.
6764 S.getASTContext().getTypeSize(D->getTypeForDecl()) <= TypeSize)
6771 // either trivial or deleted, and X has at least one non-deleted copy
6775 if (D->needsImplicitCopyConstructor() &&
6776 !D->defaultedCopyConstructorIsDeleted()) {
6777 if (!D->hasTrivialCopyConstructorForCall())
6782 if (S.getLangOpts().CPlusPlus11 && D->needsImplicitMoveConstructor() &&
6783 !D->defaultedMoveConstructorIsDeleted()) {
6784 if (!D->hasTrivialMoveConstructorForCall())
6789 if (D->needsImplicitDestructor() && !D->defaultedDestructorIsDeleted() &&
6790 !D->hasTrivialDestructorForCall())
6793 for (const CXXMethodDecl *MD : D->methods()) {
6794 if (MD->isDeleted() || MD->isIneligibleOrNotSelected())
6798 if (CD && CD->isCopyOrMoveConstructor())
6803 if (!MD->isTrivialForCall())
6819 for (const CXXMethodDecl *O : MD->overridden_methods()) {
6822 S.Diag(MD->getLocation(), DiagID) << MD->getDeclName();
6825 S.Diag(O->getLocation(), diag::note_overridden_virtual_function);
6835 if (Record->isAbstract() && !Record->isInvalidDecl()) {
6840 // If this is not an aggregate type and has no user-declared constructor,
6841 // complain about any non-static data members of reference or const scalar
6843 if (!Record->isInvalidDecl() && !Record->isDependentType() &&
6844 !Record->isAggregate() && !Record->hasUserDeclaredConstructor() &&
6845 !Record->isLambda()) {
6847 for (const auto *F : Record->fields()) {
6848 if (F->hasInClassInitializer() || F->isUnnamedBitField())
6851 if (F->getType()->isReferenceType() ||
6852 (F->getType().isConstQualified() && F->getType()->isScalarType())) {
6854 Diag(Record->getLocation(), diag::warn_no_constructor_for_refconst)
6855 << llvm::to_underlying(Record->getTagKind()) << Record;
6859 Diag(F->getLocation(), diag::note_refconst_member_not_initialized)
6860 << F->getType()->isReferenceType()
6861 << F->getDeclName();
6866 if (Record->getIdentifier()) {
6870 // - every member of every anonymous union that is a member of class T.
6873 // In addition, if class T has a user-declared constructor (12.1), every
6874 // non-static data member of class T shall have a name different from T.
6875 DeclContext::lookup_result R = Record->lookup(Record->getDeclName());
6878 NamedDecl *D = (*I)->getUnderlyingDecl();
6880 Record->hasUserDeclaredConstructor()) ||
6882 Diag((*I)->getLocation(), diag::err_member_name_of_class)
6883 << D->getDeclName();
6889 // Warn if the class has virtual methods but non-virtual public destructor.
6890 if (Record->isPolymorphic() && !Record->isDependentType()) {
6891 CXXDestructorDecl *dtor = Record->getDestructor();
6892 if ((!dtor || (!dtor->isVirtual() && dtor->getAccess() == AS_public)) &&
6893 !Record->hasAttr<FinalAttr>())
6894 Diag(dtor ? dtor->getLocation() : Record->getLocation(),
6898 if (Record->isAbstract()) {
6899 if (FinalAttr *FA = Record->getAttr<FinalAttr>()) {
6900 Diag(Record->getLocation(), diag::warn_abstract_final_class)
6901 << FA->isSpelledAsSealed();
6907 if (!Record->hasAttr<FinalAttr>()) {
6908 if (const CXXDestructorDecl *dtor = Record->getDestructor()) {
6909 if (const FinalAttr *FA = dtor->getAttr<FinalAttr>()) {
6910 Diag(FA->getLocation(), diag::warn_final_dtor_non_final_class)
6911 << FA->isSpelledAsSealed()
6913 getLocForEndOfToken(Record->getLocation()),
6914 (FA->isSpelledAsSealed() ? " sealed" : " final"));
6915 Diag(Record->getLocation(),
6917 << Context.getRecordType(Record) << FA->isSpelledAsSealed();
6923 if (Record->hasAttr<TrivialABIAttr>())
6928 bool HasTrivialABI = Record->hasAttr<TrivialABIAttr>();
6931 Record->setHasTrivialSpecialMemberForCall();
6933 // Explicitly-defaulted secondary comparison functions (!=, <, <=, >, >=).
6943 if (MD->getStorageClass() == SC_Static) {
6949 // A deleted function cannot override a non-deleted function and vice
6952 MD->isDeleted() ? diag::err_deleted_override
6955 return MD->isDeleted() != V->isDeleted();
6957 if (MD->isDefaulted() && MD->isDeleted())
6963 // A consteval function cannot override a non-consteval function and vice
6966 MD->isConsteval() ? diag::err_consteval_override
6969 return MD->isConsteval() != V->isConsteval();
6971 if (MD->isDefaulted() && MD->isDeleted())
6978 auto CheckForDefaultedFunction = [&](FunctionDecl *FD) -> bool {
6979 if (!FD || FD->isInvalidDecl() || !FD->isExplicitlyDefaulted())
6993 if (!Record->isInvalidDecl() &&
6994 Record->hasAttr<VTablePointerAuthenticationAttr>())
6998 // Check whether the explicitly-defaulted members are valid.
7002 if (Record->isDependentType())
7008 if (!M->isImplicit() && !M->isUserProvided()) {
7010 M->setTrivial(SpecialMemberIsTrivial(M, CSM));
7012 Record->finishedDefaultedOrDeletedMember(M);
7013 M->setTrivialForCall(
7016 Record->setTrivialForCallFlags(M);
7020 // Set triviality for the purpose of calls if this is a user-provided
7025 M->isUserProvided()) {
7026 M->setTrivialForCall(HasTrivialABI);
7027 Record->setTrivialForCallFlags(M);
7030 if (!M->isInvalidDecl() && M->isExplicitlyDefaulted() &&
7031 M->hasAttr<DLLExportAttr>()) {
7033 M->isTrivial() &&
7037 M->dropAttr<DLLExportAttr>();
7039 if (M->hasAttr<DLLExportAttr>()) {
7040 // Define after any fields with in-class initializers have been parsed.
7048 // See https://github.com/llvm/llvm-project/issues/102293 for more info.
7050 auto Check = [](QualType T, auto &&Check) -> bool {
7052 T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
7053 if (!RD || !RD->isCompleteDefinition())
7056 if (!RD->hasConstexprDestructor())
7060 for (const CXXBaseSpecifier &B : RD->bases())
7065 for (const FieldDecl *FD : RD->fields())
7066 if (FD->getType().getCanonicalType().getUnqualifiedType() !=
7068 !Check(FD->getType(), Check))
7073 Check(QualType(Record->getTypeForDecl(), 0), Check);
7079 if (CSM != CXXSpecialMemberKind::Invalid && !M->isDeleted() &&
7080 M->isDefaulted() && M->isConstexpr() && M->size_overridden_methods() &&
7082 DefineDefaultedFunction(*this, M, M->getLocation());
7093 if (CXXDestructorDecl *Dtor = Record->getDestructor())
7098 for (auto *D : Record->decls()) {
7100 // FIXME: We could do this check for dependent types with non-dependent
7102 if (!Record->isDependentType()) {
7105 if (!M->isStatic())
7107 if (M->hasAttr<OverrideAttr>())
7109 else if (M->size_overridden_methods() > 0)
7117 dyn_cast_or_null<FunctionDecl>(F->getFriendDecl()));
7123 for (auto *M : Record->methods())
7141 // practice among users of the ms_struct pragma to mass-annotate
7143 // really rely on MSVC-compatible layout for. We must therefore
7147 // the option -mms-bitfields otherwise essentially makes it impossible
7149 if (Record->isMsStruct(Context) && !Context.getLangOpts().MSBitfields &&
7150 (Record->isPolymorphic() || Record->getNumBases())) {
7151 Diag(Record->getLocation(), diag::warn_cxx_ms_struct);
7165 if (Record->getArgPassingRestrictions() !=
7167 Record->setArgPassingRestrictions(
7171 // If canPassInRegisters returns true despite the record having a non-trivial
7176 Record->setParamDestroyedInCallee(true);
7177 else if (Record->hasNonTrivialDestructor())
7178 Record->setParamDestroyedInCallee(CanPass);
7183 MarkVTableUsed(Record->getInnerLocStart(), Record);
7187 if (Record->hasAttr<CUDADeviceBuiltinSurfaceTypeAttr>())
7189 else if (Record->hasAttr<CUDADeviceBuiltinTextureTypeAttr>())
7199 /// \param FieldQuals If the subobject is a field, its cv-qualifiers.
7247 for (auto *D : Shadow->redecls()) {
7249 auto *DNominatedBase = DShadow->getNominatedBaseClass();
7250 auto *DConstructedBase = DShadow->getConstructedBaseClass();
7253 std::make_pair(DNominatedBase->getCanonicalDecl(),
7254 DShadow->getNominatedBaseClassShadowDecl()));
7255 if (DShadow->constructsVirtualBase())
7257 std::make_pair(DConstructedBase->getCanonicalDecl(),
7258 DShadow->getConstructedBaseClassShadowDecl()));
7264 // of type B, the program is ill-formed.
7267 ConstructedBaseIntroducer = D->getIntroducer();
7269 !Shadow->isInvalidDecl()) {
7272 << Shadow->getTargetDecl();
7273 S.Diag(ConstructedBaseIntroducer->getLocation(),
7278 S.Diag(D->getIntroducer()->getLocation(),
7285 Shadow->setInvalidDecl();
7293 auto It = InheritedFromBases.find(Base->getCanonicalDecl());
7298 if (It->second)
7300 S.findInheritingConstructor(UseLoc, Ctor, It->second),
7301 It->second->constructsVirtualBase());
7324 Inherited->findConstructorForBase(ClassDecl, InheritedCtor).first;
7326 return BaseCtor->isConstexpr();
7330 return ClassDecl->hasConstexprDefaultConstructor();
7332 return ClassDecl->hasConstexprDestructor();
7340 return SMOR.getMethod()->isConstexpr();
7365 return ClassDecl->defaultedDefaultConstructorIsConstexpr();
7381 return ClassDecl->defaultedDestructorIsConstexpr();
7387 // -- if the class is a non-empty union, or for each non-empty anonymous
7388 // union member of a non-union class, exactly one non-static data member
7391 // If we squint, this is guaranteed, since exactly one non-static data member
7394 if (Ctor && ClassDecl->isUnion())
7396 ? ClassDecl->hasInClassInitializer() ||
7397 !ClassDecl->hasVariantMembers()
7400 // -- the class shall not have any virtual base classes;
7401 if (Ctor && ClassDecl->getNumVBases())
7405 // -- [the class] is a literal type, and
7406 if (!Ctor && !ClassDecl->isLiteral() && !S.getLangOpts().CPlusPlus23)
7409 // -- every constructor involved in initializing [...] base class
7410 // sub-objects shall be a constexpr constructor;
7411 // -- the assignment operator selected to copy/move each direct base
7414 for (const auto &B : ClassDecl->bases()) {
7415 const RecordType *BaseType = B.getType()->getAs<RecordType>();
7418 CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(BaseType->getDecl());
7425 // -- every constructor involved in initializing non-static data members
7427 // -- every non-static data member and base class sub-object shall be
7429 // -- for each non-static data member of X that is of class type (or array
7433 for (const auto *F : ClassDecl->fields()) {
7434 if (F->isInvalidDecl())
7437 F->hasInClassInitializer())
7439 QualType BaseType = S.Context.getBaseElementType(F->getType());
7440 if (const RecordType *RecordTy = BaseType->getAs<RecordType>()) {
7441 CXXRecordDecl *FieldRecDecl = cast<CXXRecordDecl>(RecordTy->getDecl());
7444 ConstArg && !F->isMutable()))
7498 assert(CD->getInheritedConstructor() &&
7502 S, Loc, CD->getInheritedConstructor().getShadowDecl());
7523 const FunctionProtoType *FPT = FD->getType()->castAs<FunctionProtoType>();
7524 if (FPT->getExceptionSpecType() != EST_Unevaluated)
7536 assert(FD->isExplicitlyDefaulted() && "not explicitly-defaulted");
7540 assert(FD->getDeclContext()->isDependentContext());
7550 FD->getDefaultLoc())
7552 FD->setInvalidDecl();
7558 CXXRecordDecl *RD = MD->getParent();
7560 assert(MD->isExplicitlyDefaulted() && CSM != CXXSpecialMemberKind::Invalid &&
7561 "not an explicitly-defaulted special member");
7564 if (RD->isDependentType())
7567 // Whether this was the first-declared instance of the constructor.
7569 bool First = MD == MD->getCanonicalDecl();
7575 // -- be a special member function [...] (checked elsewhere),
7576 // -- have the same type (except for ref-qualifiers, and except that a
7577 // copy operation can take a non-const reference) as an implicit
7579 // -- not have default arguments.
7589 if (MD->getNumExplicitParams() != ExpectedParams) {
7593 Diag(MD->getLocation(), diag::err_defaulted_special_member_params)
7594 << llvm::to_underlying(CSM) << MD->getSourceRange();
7596 } else if (MD->isVariadic()) {
7600 Diag(MD->getLocation(), diag::err_defaulted_special_member_variadic)
7601 << llvm::to_underlying(CSM) << MD->getSourceRange();
7606 const FunctionProtoType *Type = MD->getType()->castAs<FunctionProtoType>();
7610 CanHaveConstParam = RD->implicitCopyConstructorHasConstParam();
7612 CanHaveConstParam = RD->implicitCopyAssignmentHasConstParam();
7618 ReturnType = Type->getReturnType();
7619 QualType ThisType = MD->getFunctionObjectParameterType();
7629 Diag(MD->getLocation(), diag::err_defaulted_special_member_return_type)
7635 // A defaulted special member cannot have cv-qualifiers.
7640 Diag(MD->getLocation(), diag::err_defaulted_special_member_quals)
7658 Diag(MD->getLocation(),
7661 << MD->getSourceRange();
7670 ? Type->getParamType(MD->isExplicitObjectMemberFunction() ? 1 : 0)
7673 if (ExpectedParams && ArgType->isReferenceType()) {
7674 // Argument must be reference to possibly-const T.
7675 QualType ReferentType = ArgType->getPointeeType();
7682 Diag(MD->getLocation(),
7694 Diag(MD->getLocation(),
7700 Diag(MD->getLocation(),
7710 "unexpected non-ref argument");
7711 Diag(MD->getLocation(), diag::err_defaulted_copy_assign_not_ref);
7716 // An explicitly-defaulted function may be declared constexpr only if it
7720 // functions which cannot be constexpr (for non-constructors in C++11 and for
7734 if (MD->isTemplateInstantiation() && MD->isConstexpr())
7740 MD->isConstexpr() && !Constexpr &&
7741 MD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) {
7742 if (!MD->isConsteval() && RD->getNumVBases()) {
7743 Diag(MD->getBeginLoc(),
7746 for (const auto &I : RD->vbases())
7749 Diag(MD->getBeginLoc(), diag::err_incorrect_defaulted_constexpr)
7750 << llvm::to_underlying(CSM) << MD->isConsteval();
7761 MD->setConstexprKind(Constexpr ? (MD->isConsteval()
7766 if (!Type->hasExceptionSpec()) {
7768 // If a declaration of a function does not have a noexcept-specifier
7771 FunctionProtoType::ExtProtoInfo EPI = Type->getExtProtoInfo();
7774 MD->setType(
7775 Context.getFunctionType(ReturnType, Type->getParamTypes(), EPI));
7781 SetDeclDeleted(MD, MD->getLocation());
7783 Diag(MD->getLocation(), diag::warn_defaulted_method_deleted)
7786 Diag(MD->getLocation(), diag::note_deleted_type_mismatch)
7796 Diag(MD->getLocation(),
7802 // [For a] user-provided explicitly-defaulted function [...] if such a
7803 // function is implicitly defined as deleted, the program is ill-formed.
7804 Diag(MD->getLocation(), diag::err_out_of_line_default_deletes)
7806 assert(!ShouldDeleteForTypeMismatch && "deleted non-first decl");
7837 if (auto *Info = FD->getDefalutedOrDeletedInfo()) {
7840 Fns.assign(Info->getUnqualifiedLookups().begin(),
7841 Info->getUnqualifiedLookups().end());
7848 FD->getParamDecl(0)->getType().getNonReferenceType();
7881 for (CXXBaseSpecifier &Base : Record->bases())
7887 // followed by the non-static data members of C
7888 for (FieldDecl *Field : Record->fields()) {
7890 // Unnamed bit-fields are not members ...
7891 if (Field->isUnnamedBitField())
7894 if (Field->isAnonymousStructOrUnion()) {
7895 if (visitSubobjects(Results, Field->getType()->getAsCXXRecordDecl(),
7903 if (Field->isMutable())
7906 S.Context.getQualifiedType(Field->getType(), FieldQuals);
7921 return getDerived().visitSubobjectArray(CAT->getElementType(),
7922 CAT->getSize(), Subobj);
7996 RD->hasVariantMembers()) {
8001 S.Diag(FD->getLocation(), diag::note_defaulted_comparison_union)
8002 << FD << RD->isUnion() << RD;
8012 return Subobject{Subobject::CompleteObject, RD, FD->getLocation()};
8016 return Subobject{Subobject::Base, Base->getType()->getAsCXXRecordDecl(),
8017 Base->getBaseTypeLoc()};
8021 return Subobject{Subobject::Member, Field, Field->getLocation()};
8027 // deleted if any non-static data member of C is of reference type
8028 if (Type->isReferenceType()) {
8037 OpaqueValueExpr Xi(FD->getLocation(), Type, VK_LValue);
8041 OverloadedOperatorKind OO = FD->getOverloadedOperator();
8054 FD->getLocation(), OverloadCandidateSet::CSK_Operator,
8056 OO, FD->getLocation(),
8064 if (Args[0]->getType()->isOverloadableType())
8070 S.AddBuiltinOperatorCandidates(OO, FD->getLocation(), Args, CandidateSet);
8075 switch (CandidateSet.BestViableFunction(S, FD->getLocation(), Best)) {
8083 !Best->RewriteKind) {
8085 if (Best->Function) {
8086 S.Diag(Best->Function->getLocation(),
8090 assert(Best->Conversions.size() == 2 &&
8091 Best->Conversions[0].isUserDefined() &&
8092 "non-user-defined conversion from class to built-in "
8094 S.Diag(Best->Conversions[0]
8096 ->getLocation(),
8110 // derived-to-base conversion.
8111 CXXRecordDecl *ArgClass = Args[0]->getType()->getAsCXXRecordDecl();
8112 if (ArgClass && Best->FoundDecl.getDecl() &&
8113 Best->FoundDecl.getDecl()->isCXXClassMember()) {
8115 ? Args[0]->getType()
8118 ArgClass, Best->FoundDecl, ObjectType, Subobj.Loc,
8127 OO == OO_Spaceship && FD->getReturnType()->isUndeducedAutoType();
8129 if (FunctionDecl *BestFD = Best->Function) {
8131 // A defaulted comparison function is constexpr-compatible if
8133 // non-constexpr function.
8134 assert(!BestFD->isDeleted() && "wrong overload resolution result");
8136 if (Diagnose == ExplainConstexpr && !BestFD->isConstexpr()) {
8140 S.Diag(BestFD->getLocation(),
8145 R.Constexpr &= BestFD->isConstexpr();
8152 if (BestFD->getReturnType()->isUndeducedType() &&
8153 S.DeduceReturnType(BestFD, FD->getLocation(),
8160 FD->getLocation(),
8167 S.Diag(BestFD->getLocation(),
8174 BestFD->getCallResultType());
8179 << BestFD->getCallResultType().withoutLocalFastQualifiers();
8180 S.Diag(BestFD->getLocation(),
8186 R.Category = Info->Kind;
8189 QualType T = Best->BuiltinParamTypes[0];
8190 assert(T == Best->BuiltinParamTypes[1] &&
8192 assert(Best->BuiltinParamTypes[2].isNull() &&
8211 if (FD->getOverloadedOperator() == OO_Spaceship && OO != OO_Spaceship)
8226 !Best->RewriteKind) {
8227 S.Diag(Best->Function->getLocation(),
8234 S.NoteDeletedFunction(Best->Function);
8244 S.Context.CompCategories.lookupInfoForType(FD->getReturnType())) {
8258 // For a three-way comparison, list both the candidates for the
8261 SpaceshipCandidates->NoteCandidates(
8263 SpaceshipCandidates->CompleteCandidates(S, OCD_AllCandidates,
8264 Args, FD->getLocation()));
8273 FD->getLocation()));
8337 // fold (traversing the conditions right-to-left), because that
8338 // short-circuits more naturally.
8391 ->VD;
8419 CXXScopeSpec(), DeclarationNameInfo(VD->getDeclName(), Loc), VD);
8423 ParmVarDecl *PD = FD->getParamDecl(I);
8431 MD && MD->isImplicitObjectMemberFunction()) {
8440 assert(Param == FD->getNumParams());
8449 return {S.ImpCastExprToType(Obj.first.get(), Base->getType(),
8451 S.ImpCastExprToType(Obj.second.get(), Base->getType(),
8460 DeclAccessPair Found = DeclAccessPair::make(Field, Field->getAccess());
8461 DeclarationNameInfo NameInfo(Field->getDeclName(), Loc);
8508 IterationVar->setInit(
8542 --ArrayDepth;
8552 "should have non-expression statement");
8570 OverloadedOperatorKind OO = FD->getOverloadedOperator();
8573 if (Type->isOverloadableType())
8598 QualType R = FD->getReturnType();
8619 if (VDRef.get()->getType()->isOverloadableType())
8656 QualType R = FD->getReturnType();
8657 assert(!R->isUndeducedType() && "type should have been deduced already");
8659 // Don't bother forming a no-op cast in the common case.
8660 if (E->isPRValue() && S.Context.hasSameType(E->getType(), R))
8685 // synthesize a three-way comparison from '<' and '=='. In a dependent
8704 FD->getOverloadedOperator());
8705 FD->setDefaultedOrDeletedInfo(
8712 // non-template function declared in the member-specification of C that is
8713 // -- a non-static const non-volatile member of C having one parameter of
8714 // type const C& and either no ref-qualifier or the ref-qualifier &, or
8715 // -- a friend of C having two parameters of type const C& or two
8718 CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalDeclContext());
8722 assert(!MD->isStatic() && "comparison function cannot be a static member");
8724 if (MD->getRefQualifier() == RQ_RValue) {
8725 Diag(MD->getLocation(), diag::err_ref_qualifier_comparison_operator);
8728 const auto *FPT = MD->getType()->castAs<FunctionProtoType>();
8729 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
8731 MD->setType(Context.getFunctionType(FPT->getReturnType(),
8732 FPT->getParamTypes(), EPI));
8735 // If we're out-of-class, this is the class we're comparing.
8737 RD = MD->getParent();
8738 QualType T = MD->getFunctionObjectParameterType();
8741 if (MD->isExplicitObjectMemberFunction()) {
8742 Loc = MD->getParamDecl(0)->getBeginLoc();
8744 MD->getParamDecl(0)->getExplicitObjectParamThisLoc());
8746 Loc = MD->getLocation();
8747 if (FunctionTypeLoc Loc = MD->getFunctionTypeLoc())
8752 if (!MD->isImplicit()) {
8758 const auto *FPT = MD->getType()->castAs<FunctionProtoType>();
8759 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
8761 MD->setType(Context.getFunctionType(FPT->getReturnType(),
8762 FPT->getParamTypes(), EPI));
8765 if (MD->isVolatile()) {
8766 Diag(MD->getLocation(), diag::err_volatile_comparison_operator);
8769 const auto *FPT = MD->getType()->castAs<FunctionProtoType>();
8770 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
8772 MD->setType(Context.getFunctionType(FPT->getReturnType(),
8773 FPT->getParamTypes(), EPI));
8777 if ((FD->getNumParams() -
8778 (unsigned)FD->hasCXXExplicitFunctionObjectParameter()) !=
8780 // Let's not worry about using a variadic template pack here -- who would do
8782 Diag(FD->getLocation(), diag::err_defaulted_comparison_num_args)
8788 for (const ParmVarDecl *Param : FD->parameters()) {
8789 if (Param->isExplicitObjectParameter())
8791 QualType ParmTy = Param->getType();
8800 if (auto *Ref = CTy->getAs<ReferenceType>()) {
8801 CTy = Ref->getPointeeType();
8810 if (!RD->isDependentType() && !Context.hasSameType(CTy, ExpectedTy))
8812 } else if (auto *CRD = CTy->getAsRecordDecl()) {
8823 if (!FD->isImplicit()) {
8828 Diag(FD->getLocation(), diag::err_defaulted_comparison_param)
8830 << Param->getSourceRange();
8833 Diag(FD->getLocation(),
8835 << int(DCK) << ParmTy << Param->getSourceRange();
8840 } else if (!Context.hasSameType(KnownParm->getType(), ParmTy)) {
8841 Diag(FD->getLocation(), diag::err_defaulted_comparison_param_mismatch)
8842 << int(DCK) << KnownParm->getType() << KnownParm->getSourceRange()
8843 << ParmTy << Param->getSourceRange();
8850 } else if (isa<CXXRecordDecl>(FD->getLexicalDeclContext())) {
8851 // In-class, must be a friend decl.
8852 assert(FD->getFriendObjectKind() && "expected a friend declaration");
8856 if (RequireCompleteType(FD->getLocation(), Context.getRecordType(RD),
8861 if (llvm::none_of(RD->friends(), [&](const FriendDecl *F) {
8862 return FD->getCanonicalDecl() ==
8863 F->getFriendDecl()->getCanonicalDecl();
8865 Diag(FD->getLocation(), diag::err_defaulted_comparison_not_friend)
8867 Diag(RD->getCanonicalDecl()->getLocation(), diag::note_declared_at);
8876 !FD->getDeclaredReturnType()->isDependentType() &&
8877 !Context.hasSameType(FD->getDeclaredReturnType(), Context.BoolTy)) {
8878 Diag(FD->getLocation(), diag::err_defaulted_comparison_return_type_not_bool)
8879 << (int)DCK << FD->getDeclaredReturnType() << Context.BoolTy
8880 << FD->getReturnTypeSourceRange();
8886 if (QualType RT = FD->getDeclaredReturnType();
8888 RT->getContainedDeducedType() &&
8890 RT->getContainedAutoType()->isConstrained())) {
8891 Diag(FD->getLocation(),
8893 << (int)DCK << FD->getDeclaredReturnType() << Context.AutoDeductTy
8894 << FD->getReturnTypeSourceRange();
8900 if (RD->isDependentType())
8907 bool First = FD == FD->getCanonicalDecl();
8912 // [For a] user-provided explicitly-defaulted function [...] if such a
8913 // function is implicitly defined as deleted, the program is ill-formed.
8917 Diag(FD->getLocation(), diag::err_non_first_default_compare_deletes)
8918 << FD->isImplicit() << (int)DCK;
8924 if (isa<CXXRecordDecl>(FD->getLexicalDeclContext())) {
8928 Diag(FD->getLocation(), diag::err_non_first_default_compare_in_class)
8930 Diag(FD->getCanonicalDecl()->getLocation(),
8939 SetDeclDeleted(FD, FD->getLocation());
8940 if (!inTemplateInstantiation() && !FD->isImplicit()) {
8941 Diag(FD->getLocation(), diag::warn_defaulted_comparison_deleted)
8946 if (FD->getDefaultLoc().isValid())
8947 Diag(FD->getDefaultLoc(), diag::note_replace_equals_default_to_delete)
8948 << FixItHint::CreateReplacement(FD->getDefaultLoc(), "delete");
8956 FD->getDeclaredReturnType()->isUndeducedAutoType()) {
8957 SourceLocation RetLoc = FD->getReturnTypeSourceRange().getBegin();
8959 RetLoc = FD->getBeginLoc();
8967 FD, SubstAutoType(FD->getDeclaredReturnType(), Cat));
8971 // An explicitly-defaulted function that is not defined as deleted may be
8972 // declared constexpr or consteval only if it is constexpr-compatible.
8974 // A defaulted comparison function is constexpr-compatible if it satisfies
8980 // The concept of constexpr-compatible was removed.
8983 // inline, and is implicitly constexpr if it is constexpr-suitable.
8985 // A function is constexpr-suitable if
8986 // - it is not a coroutine, and
8987 // - if the function is a constructor or destructor, its class does not
8989 if (FD->isConstexpr()) {
8994 Diag(FD->getBeginLoc(), diag::err_defaulted_comparison_constexpr_mismatch)
8995 << FD->isImplicit() << (int)DCK << FD->isConsteval();
9003 // If a constexpr-compatible function is explicitly defaulted on its first
9007 if (First && !FD->isConstexpr() && Info.Constexpr)
9008 FD->setConstexprKind(ConstexprSpecKind::Constexpr);
9011 // If a declaration of a function does not have a noexcept-specifier
9014 if (FD->getExceptionSpecType() == EST_None) {
9015 auto *FPT = FD->getType()->castAs<FunctionProtoType>();
9016 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
9019 FD->setType(Context.getFunctionType(FPT->getReturnType(),
9020 FPT->getParamTypes(), EPI));
9030 Ctx.PointOfInstantiation = Spaceship->getEndLoc();
9035 EqualEqual->setImplicit();
9042 assert(FD->isDefaulted() && !FD->isDeleted() &&
9043 !FD->doesThisDeclarationHaveABody());
9044 if (FD->willHaveBody() || FD->isInvalidDecl())
9054 // The first parameter has type maybe-ref-to maybe-const T, use that to get
9056 auto PT = FD->getParamDecl(0)->getType();
9057 CXXRecordDecl *RD = PT.getNonReferenceType()->getAsCXXRecordDecl();
9059 FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation();
9063 FD->setInvalidDecl();
9066 FD->setBody(Body.get());
9067 FD->markUsed(Context);
9072 ResolveExceptionSpec(UseLoc, FD->getType()->castAs<FunctionProtoType>());
9075 L->CompletedImplicitDefinition(FD);
9085 if (FD->isInvalidDecl())
9090 if (FD->hasBody()) {
9091 ExceptSpec.CalledStmt(FD->getBody());
9106 cast<CXXRecordDecl>(FD->getFriendObjectKind() == Decl::FOK_None
9107 ? FD->getDeclContext()
9108 : FD->getLexicalDeclContext());
9110 FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation();
9175 if (MD->getNumExplicitParams()) {
9177 MD->getNonObjectParameter(0)->getType()->getAs<ReferenceType>())
9178 ConstArg = RT->getPointeeType().isConstQualified();
9204 cast<CXXConstructorDecl>(MD)->getInheritedConstructor().getConstructor();
9205 if (auto *MD = ICI->findConstructorForBase(Class, BaseCtor).first)
9218 return B->getBaseTypeLoc();
9220 return Subobj.get<FieldDecl*>()->getLocation();
9224 /// Visit all non-virtual (direct) bases.
9228 /// Visit all non-virtual bases, and all virtual bases if the class
9237 CXXRecordDecl *RD = MD->getParent();
9240 Bases = RD->isAbstract() ? VisitNonVirtualBases : VisitAllBases;
9242 for (auto &B : RD->bases())
9248 for (auto &B : RD->vbases())
9252 for (auto *F : RD->fields())
9253 if (!F->isInvalidDecl() && !F->isUnnamedBitField() &&
9275 Loc(MD->getLocation()), AllFieldsAreConst(true) {}
9277 bool inUnion() const { return MD->getParent()->isUnion(); }
9303 /// sub-object.
9309 AccessSpecifier access = target->getAccess();
9311 objectTy = S.Context.getTypeDeclType(MD->getParent());
9312 access = CXXRecordDecl::MergeAccess(base->getAccessSpecifier(), access);
9316 objectTy = S.Context.getTypeDeclType(target->getParent());
9320 target->getParent(), DeclAccessPair::make(target, access), objectTy);
9331 int DiagKind = -1;
9339 else if (!IsDtorCallInCtor && Field && Field->getParent()->isUnion() &&
9340 !Decl->isTrivial()) {
9343 // must be accessible and non-deleted, but need not be trivial. Such a
9349 // - X is a union that has a variant member with a non-trivial default
9352 const auto *RD = cast<CXXRecordDecl>(Field->getParent());
9353 if (!RD->hasInClassInitializer())
9360 if (DiagKind == -1)
9365 S.Diag(Field->getLocation(),
9367 << llvm::to_underlying(getEffectiveCSM()) << MD->getParent()
9372 S.Diag(Base->getBeginLoc(),
9374 << llvm::to_underlying(getEffectiveCSM()) << MD->getParent()
9375 << /*IsField*/ false << Base->getType() << DiagKind
9388 /// direct or virtual base class or non-static data member of class type M.
9392 bool IsMutable = Field && Field->isMutable();
9395 // -- any direct or virtual base class, or non-static data member with no
9396 // brace-or-equal-initializer, has class type M (or array thereof) and
9401 // -- a direct or virtual base class B that cannot be copied/moved because
9406 // -- any direct or virtual base class [...] has a type with a destructor
9409 Field->hasInClassInitializer()) &&
9415 // -- any direct or virtual base class or non-static data member has a
9431 // member with a non-trivial ownership type, e.g., ObjC __strong or __weak
9437 // member has an in-class initializer.
9439 FD->hasInClassInitializer())
9443 auto *ParentClass = cast<CXXRecordDecl>(FD->getParent());
9444 S.Diag(FD->getLocation(), diag::note_deleted_special_member_class_subobject)
9456 CXXRecordDecl *BaseClass = Base->getType()->getAsCXXRecordDecl();
9469 if (BaseCtor->isDeleted() && Diagnose) {
9470 S.Diag(Base->getBeginLoc(),
9472 << llvm::to_underlying(getEffectiveCSM()) << MD->getParent()
9473 << /*IsField*/ false << Base->getType() << /*Deleted*/ 1
9477 return BaseCtor->isDeleted();
9483 /// having a particular non-static data member.
9485 QualType FieldType = S.Context.getBaseElementType(FD->getType());
9486 CXXRecordDecl *FieldRecord = FieldType->getAsCXXRecordDecl();
9492 // For a default constructor, all references must be initialized in-class
9493 // and, if a union, it must have a non-const member.
9494 if (FieldType->isReferenceType() && !FD->hasInClassInitializer()) {
9496 S.Diag(FD->getLocation(), diag::note_deleted_default_ctor_uninit_field)
9497 << !!ICI << MD->getParent() << FD << FieldType << /*Reference*/0;
9500 // C++11 [class.ctor]p5 (modified by DR2394): any non-variant non-static
9501 // data member of const-qualified type (or array thereof) with no
9502 // brace-or-equal-initializer is not const-default-constructible.
9504 !FD->hasInClassInitializer() &&
9505 (!FieldRecord || !FieldRecord->allowConstDefaultInit())) {
9507 S.Diag(FD->getLocation(), diag::note_deleted_default_ctor_uninit_field)
9508 << !!ICI << MD->getParent() << FD << FD->getType() << /*Const*/1;
9517 if (FieldType->isRValueReferenceType()) {
9519 S.Diag(FD->getLocation(), diag::note_deleted_copy_ctor_rvalue_reference)
9520 << MD->getParent() << FD << FieldType;
9525 if (FieldType->isReferenceType()) {
9527 S.Diag(FD->getLocation(), diag::note_deleted_assign_field)
9528 << isMove() << MD->getParent() << FD << FieldType << /*Reference*/0;
9533 // -- a non-static data member of const non-class type (or array thereof)
9535 S.Diag(FD->getLocation(), diag::note_deleted_assign_field)
9536 << isMove() << MD->getParent() << FD << FD->getType() << /*Const*/1;
9543 if (!inUnion() && FieldRecord->isUnion() &&
9544 FieldRecord->isAnonymousStructOrUnion()) {
9548 for (auto *UI : FieldRecord->fields()) {
9549 QualType UnionFieldType = S.Context.getBaseElementType(UI->getType());
9557 CXXRecordDecl *UnionFieldRecord = UnionFieldType->getAsCXXRecordDecl();
9564 // At least one member in each anonymous union must be non-const
9566 AllVariantFieldsAreConst && !FieldRecord->field_empty()) {
9568 S.Diag(FieldRecord->getLocation(),
9570 << !!ICI << MD->getParent() << /*anonymous union*/1;
9575 // This is technically non-conformant but supported, and we have a
9590 /// X is a union and all of its variant members are of const-qualified type.
9597 for (auto *F : MD->getParent()->fields())
9598 if ((AnyFields = !F->isUnnamedBitField()))
9603 S.Diag(MD->getParent()->getLocation(),
9605 << !!ICI << MD->getParent() << /*not anonymous union*/0;
9618 if (MD->isInvalidDecl())
9620 CXXRecordDecl *RD = MD->getParent();
9621 assert(!RD->isDependentType() && "do deletion after instantiation");
9622 if (!LangOpts.CPlusPlus || (!LangOpts.CPlusPlus11 && !RD->isLambda()) ||
9623 RD->isInvalidDecl())
9627 // The closure type associated with a lambda-expression has a
9630 // C++2a adds back these operators if the lambda has no lambda-capture.
9631 if (RD->isLambda() && !RD->lambdaIsDefaultConstructibleAndAssignable() &&
9635 Diag(RD->getLocation(), diag::note_lambda_decl);
9643 CSM != CXXSpecialMemberKind::Destructor && RD->isAnonymousStructOrUnion())
9650 if (MD->isImplicit() && (CSM == CXXSpecialMemberKind::CopyConstructor ||
9654 // In Microsoft mode up to MSVC 2013, a user-declared move only causes the
9661 if (RD->hasUserDeclaredMoveConstructor() &&
9666 // Find any user-declared move constructor.
9667 for (auto *I : RD->ctors()) {
9668 if (I->isMoveConstructor()) {
9674 } else if (RD->hasUserDeclaredMoveAssignment() &&
9679 // Find any user-declared move assignment operator.
9680 for (auto *I : RD->methods()) {
9681 if (I->isMoveAssignmentOperator()) {
9690 Diag(UserDeclaredMove->getLocation(),
9693 << UserDeclaredMove->isMoveAssignmentOperator();
9702 // -- for a virtual destructor, lookup of the non-array deallocation function
9704 if (CSM == CXXSpecialMemberKind::Destructor && MD->isVirtual()) {
9708 if (FindDeallocationFunction(MD->getLocation(), MD->getParent(), Name,
9711 Diag(RD->getLocation(), diag::note_deleted_dtor_no_operator_delete);
9734 // For inherited constructors (non-null ICI), CSM may be passed so that MD
9753 assert(FD->isDefaulted() && FD->isDeleted() && "not defaulted and deleted");
9760 *this, cast<CXXRecordDecl>(FD->getLexicalDeclContext()), FD,
9792 // - all the [direct subobjects] have trivial default constructors
9795 if (RD->hasTrivialDefaultConstructor())
9800 // out. Otherwise, if there's any user-provided default constructor, point
9803 if (RD->needsImplicitDefaultConstructor())
9805 for (auto *CI : RD->ctors()) {
9806 if (!CI->isDefaultConstructor())
9809 if (!DefCtor->isUserProvided())
9821 // - all the direct [subobjects] have trivial destructors
9822 if (RD->hasTrivialDestructor() ||
9824 RD->hasTrivialDestructorForCall()))
9828 if (RD->needsImplicitDestructor())
9830 *Selected = RD->getDestructor();
9838 // - the constructor selected to copy each direct [subobject] is trivial
9839 if (RD->hasTrivialCopyConstructor() ||
9841 RD->hasTrivialCopyConstructorForCall())) {
9850 // treat that as a language defect, as suggested on cxx-abi-dev, to treat
9851 // cases like B as having a non-trivial copy constructor:
9859 // - the assignment operator selected to copy each direct [subobject] is
9861 if (RD->hasTrivialCopyAssignment()) {
9878 // We treat it as not making the member non-trivial, just like the standard
9898 return SMOR.getMethod()->isTrivialForCall();
9899 return SMOR.getMethod()->isTrivial();
9906 for (auto *CI : RD->ctors())
9907 if (!CI->isImplicit())
9912 for (tmpl_iter TI(RD->decls_begin()), TE(RD->decls_end()); TI != TE; ++TI) {
9914 dyn_cast<CXXConstructorDecl>(TI->getTemplatedDecl()))
9926 /// The subobject is a non-static data member.
9939 CXXRecordDecl *SubRD = SubType->getAsCXXRecordDecl();
9956 S.Diag(CD->getLocation(), diag::note_user_declared_ctor);
9961 else if (Selected->isUserProvided()) {
9963 S.Diag(Selected->getLocation(), diag::note_nontrivial_user_provided)
9968 S.Diag(Selected->getLocation(), diag::note_declared_at);
9990 for (const auto *FI : RD->fields()) {
9991 if (FI->isInvalidDecl() || FI->isUnnamedBitField())
9994 QualType FieldType = S.Context.getBaseElementType(FI->getType());
9997 if (FI->isAnonymousStructOrUnion()) {
9998 if (!checkTrivialClassMembers(S, FieldType->getAsCXXRecordDecl(),
10006 // -- no non-static data member of its class has a
10007 // brace-or-equal-initializer
10009 FI->hasInClassInitializer()) {
10011 S.Diag(FI->getLocation(), diag::note_nontrivial_default_member_init)
10017 // [...] nontrivally ownership-qualified types are [...] not trivially
10022 S.Diag(FI->getLocation(), diag::note_nontrivial_objc_ownership)
10027 bool ConstRHS = ConstArg && !FI->isMutable();
10028 if (!checkTrivialSubobjectCall(S, FI->getLocation(), FieldType, ConstRHS,
10042 checkTrivialSubobjectCall(*this, RD->getLocation(), Ty, ConstArg, CSM,
10049 assert(!MD->isUserProvided() && CSM != CXXSpecialMemberKind::Invalid &&
10052 CXXRecordDecl *RD = MD->getParent();
10057 // A [special member] is trivial if [...] its parameter-type-list is
10058 // equivalent to the parameter-type-list of an implicit declaration [...]
10067 const ParmVarDecl *Param0 = MD->getNonObjectParameter(0);
10068 const ReferenceType *RT = Param0->getType()->getAs<ReferenceType>();
10071 // if they are not user-provided and their parameter-type-list is equivalent
10072 // to the parameter-type-list of an implicit declaration. This maintains the
10076 // trivial, if they are not user-provided, regardless of the qualifiers on
10081 ((RT->getPointeeType().getCVRQualifiers() != Qualifiers::Const) &&
10084 Diag(Param0->getLocation(), diag::note_nontrivial_param_type)
10085 << Param0->getSourceRange() << Param0->getType()
10091 ConstArg = RT->getPointeeType().isConstQualified();
10097 // Trivial move operations always have non-cv-qualified parameters.
10098 const ParmVarDecl *Param0 = MD->getNonObjectParameter(0);
10100 Param0->getType()->getAs<RValueReferenceType>();
10101 if (!RT || RT->getPointeeType().getCVRQualifiers()) {
10103 Diag(Param0->getLocation(), diag::note_nontrivial_param_type)
10104 << Param0->getSourceRange() << Param0->getType()
10115 if (MD->getMinRequiredArguments() < MD->getNumParams()) {
10117 Diag(MD->getParamDecl(MD->getMinRequiredArguments())->getLocation(),
10119 << MD->getParamDecl(MD->getMinRequiredArguments())->getSourceRange();
10122 if (MD->isVariadic()) {
10124 Diag(MD->getLocation(), diag::note_nontrivial_variadic);
10130 // -- the [member] selected to copy/move each direct base class subobject
10135 // -- all the direct base classes have trivial [default constructors or
10137 for (const auto &BI : RD->bases())
10145 // -- for each non-static data member of X that is of class type (or array
10151 // -- for all of the non-static data members of its class that are of class
10159 // -- the destructor is not virtual
10160 if (CSM == CXXSpecialMemberKind::Destructor && MD->isVirtual()) {
10162 Diag(MD->getLocation(), diag::note_nontrivial_virtual_dtor) << RD;
10168 // -- class X has no virtual functions and no virtual base classes
10170 MD->getParent()->isDynamicClass()) {
10174 if (RD->getNumVBases()) {
10177 CXXBaseSpecifier &BS = *RD->vbases_begin();
10184 for (const auto *MI : RD->methods()) {
10185 if (MI->isVirtual()) {
10186 SourceLocation MLoc = MI->getBeginLoc();
10211 if (MD->size_overridden_methods() == 0)
10212 return Methods.count(MD->getCanonicalDecl());
10213 for (const CXXMethodDecl *O : MD->overridden_methods())
10225 Specifier->getType()->castAs<RecordType>()->getDecl();
10227 DeclarationName Name = Method->getDeclName();
10232 for (Path.Decls = BaseRecord->lookup(Name).begin();
10236 MD = MD->getCanonicalDecl();
10239 if (!MD->isVirtual())
10245 // -Woverloaded-virtual diagnoses any derived function hiding a virtual
10250 // See FIXME in test/SemaCXX/warn-overload-virtual.cpp for an example.
10251 if (!S->IsOverload(Method, MD, false))
10270 if (MD->size_overridden_methods() == 0)
10271 Methods.insert(MD->getCanonicalDecl());
10273 for (const CXXMethodDecl *O : MD->overridden_methods())
10279 if (!MD->getDeclName().isIdentifier())
10291 CXXRecordDecl *DC = MD->getParent();
10292 DeclContext::lookup_result R = DC->lookup(MD->getDeclName());
10296 ND = shad->getTargetDecl();
10301 if (DC->lookupInBases(FHVM, Paths))
10311 HandleFunctionTypeMismatch(PD, MD->getType(), overloadedMD->getType());
10312 Diag(overloadedMD->getLocation(), PD);
10317 if (MD->isInvalidDecl())
10320 if (Diags.isIgnored(diag::warn_overloaded_virtual, MD->getLocation()))
10326 Diag(MD->getLocation(), diag::warn_overloaded_virtual)
10337 Diag(RD.getAttr<TrivialABIAttr>()->getLocation(),
10339 Diag(RD.getAttr<TrivialABIAttr>()->getLocation(),
10345 // Ill-formed if the copy and move constructors are deleted.
10358 if (CD->isCopyOrMoveConstructor() && !CD->isDeleted())
10368 // Ill-formed if the struct has virtual functions.
10375 // Ill-formed if the base class is non-trivial for the purpose of calls or a
10377 if (!B.getType()->isDependentType() &&
10378 !B.getType()->getAsCXXRecordDecl()->canPassInRegisters()) {
10390 // Ill-formed if the field is an ObjectiveC pointer or of a type that is
10391 // non-trivial for the purpose of calls.
10392 QualType FT = FD->getType();
10398 if (const auto *RT = FT->getBaseElementTypeUnsafe()->getAs<RecordType>())
10399 if (!RT->isDependentType() &&
10400 !cast<CXXRecordDecl>(RT->getDecl())->canPassInRegisters()) {
10414 if (PrimaryBase->hasAnyDependentBases())
10420 for (auto BasePtr : PrimaryBase->bases()) {
10421 if (!BasePtr.getType()->getAsCXXRecordDecl()->isDynamicClass())
10423 Base = BasePtr.getType()->getAsCXXRecordDecl();
10426 if (!Base || Base == PrimaryBase || !Base->isPolymorphic())
10428 Diag(RD.getAttr<VTablePointerAuthenticationAttr>()->getLocation(),
10435 Diag(RD.getAttr<VTablePointerAuthenticationAttr>()->getLocation(),
10458 reinterpret_cast<Decl **>(FieldCollector->getCurFields()),
10459 FieldCollector->getCurNumFields()),
10471 if (!RD->lookup(EqEq).empty())
10476 for (FriendDecl *Friend : RD->friends()) {
10477 FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(Friend->getFriendDecl());
10480 if (FD->getOverloadedOperator() == OO_EqualEqual) {
10486 if (FD->getOverloadedOperator() == OO_Spaceship &&
10487 FD->isExplicitlyDefaulted())
10493 for (NamedDecl *ND : RD->lookup(Cmp)) {
10494 // Note that we could find a non-function here (either a function template
10495 // or a using-declaration). Neither case results in an implicit
10498 if (FD->isExplicitlyDefaulted())
10507 if (!ClassDecl->isDependentType()) {
10508 if (ClassDecl->needsImplicitDefaultConstructor()) {
10511 if (ClassDecl->hasInheritedConstructor())
10515 if (ClassDecl->needsImplicitCopyConstructor()) {
10521 if (ClassDecl->needsOverloadResolutionForCopyConstructor() ||
10522 ClassDecl->hasInheritedConstructor())
10526 // a move ctor or move assignment that is either user-declared or whose
10530 (ClassDecl->hasUserDeclaredMoveConstructor() ||
10531 ClassDecl->needsOverloadResolutionForMoveConstructor() ||
10532 ClassDecl->hasUserDeclaredMoveAssignment() ||
10533 ClassDecl->needsOverloadResolutionForMoveAssignment()))
10538 ClassDecl->needsImplicitMoveConstructor()) {
10541 if (ClassDecl->needsOverloadResolutionForMoveConstructor() ||
10542 ClassDecl->hasInheritedConstructor())
10546 if (ClassDecl->needsImplicitCopyAssignment()) {
10553 if (ClassDecl->isDynamicClass() ||
10554 ClassDecl->needsOverloadResolutionForCopyAssignment() ||
10555 ClassDecl->hasInheritedAssignment())
10559 if (getLangOpts().CPlusPlus11 && ClassDecl->needsImplicitMoveAssignment()) {
10563 if (ClassDecl->isDynamicClass() ||
10564 ClassDecl->needsOverloadResolutionForMoveAssignment() ||
10565 ClassDecl->hasInheritedAssignment())
10569 if (ClassDecl->needsImplicitDestructor()) {
10576 if (ClassDecl->isDynamicClass() ||
10577 ClassDecl->needsOverloadResolutionForDestructor())
10583 // If the member-specification does not explicitly declare any member or
10585 // for each defaulted three-way comparison operator function defined in
10586 // the member-specification
10613 for (unsigned i = 0; i < DD->getNumTemplateParameterLists(); ++i)
10614 ParameterLists.push_back(DD->getTemplateParameterList(i));
10617 if (FunctionTemplateDecl *FTD = FD->getDescribedFunctionTemplate())
10618 ParameterLists.push_back(FTD->getTemplateParameters());
10620 LookupDC = VD->getDeclContext();
10622 if (VarTemplateDecl *VTD = VD->getDescribedVarTemplate())
10623 ParameterLists.push_back(VTD->getTemplateParameters());
10625 ParameterLists.push_back(PSD->getTemplateParameters());
10628 for (unsigned i = 0; i < TD->getNumTemplateParameterLists(); ++i)
10629 ParameterLists.push_back(TD->getTemplateParameterList(i));
10632 if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())
10633 ParameterLists.push_back(CTD->getTemplateParameters());
10635 ParameterLists.push_back(PSD->getTemplateParameters());
10645 if (Params->size() == 0)
10650 if (Param->getDeclName()) {
10651 InnermostTemplateScope->AddDecl(Param);
10683 S->AddDecl(Param);
10684 if (Param->getDeclName())
10691 /// ActOnDelayedCXXMethodParameter - We've already started a delayed
10692 /// C++ method declaration. We're (re-)introducing the given
10702 S->AddDecl(Param);
10703 if (Param->getDeclName())
10717 // the class has implicitly-declared destructors, among other
10723 if (!Method->isInvalidDecl())
10727 // Emit the given diagnostic for each non-address-space qualifier.
10733 FTI.MethodQualifiers->forEachQualifier(
10785 // A constructor shall not be declared with a ref-qualifier.
10797 const FunctionProtoType *Proto = R->castAs<FunctionProtoType>();
10798 if (Proto->getReturnType() == Context.VoidTy && !D.isInvalidType())
10801 FunctionProtoType::ExtProtoInfo EPI = Proto->getExtProtoInfo();
10805 return Context.getFunctionType(Context.VoidTy, Proto->getParamTypes(), EPI);
10810 = dyn_cast<CXXRecordDecl>(Constructor->getDeclContext());
10812 return Constructor->setInvalidDecl();
10815 // A declaration of a constructor for a class X is ill-formed if
10816 // its first parameter is of type (optionally cv-qualified) X and
10819 if (!Constructor->isInvalidDecl() &&
10820 Constructor->hasOneParamOrDefaultArgs() &&
10821 Constructor->getTemplateSpecializationKind() !=
10823 QualType ParamType = Constructor->getParamDecl(0)->getType();
10826 SourceLocation ParamLoc = Constructor->getParamDecl(0)->getLocation();
10828 = Constructor->getParamDecl(0)->getIdentifier() ? "const &"
10835 Constructor->setInvalidDecl();
10841 CXXRecordDecl *RD = Destructor->getParent();
10843 if (!Destructor->getOperatorDelete() && Destructor->isVirtual()) {
10846 if (!Destructor->isImplicit())
10847 Loc = Destructor->getLocation();
10849 Loc = RD->getLocation();
10856 // If the notional 'delete this' expression requires a non-trivial
10859 if (OperatorDelete->isDestroyingOperatorDelete()) {
10860 QualType ParamType = OperatorDelete->getParamDecl(0)->getType();
10861 if (!declaresSameEntity(ParamType->getAsCXXRecordDecl(), RD)) {
10864 // non-virtual destructor of the destructor's class.
10867 ActOnCXXThis(OperatorDelete->getParamDecl(0)->getLocation());
10882 Destructor->setOperatorDelete(OperatorDelete, ThisArg);
10892 // [...] A typedef-name that names a class is a class-name
10893 // (7.1.3); however, a typedef-name that names a class shall not
10897 if (const TypedefType *TT = DeclaratorType->getAs<TypedefType>())
10899 << DeclaratorType << isa<TypeAliasDecl>(TT->getDecl());
10901 DeclaratorType->getAs<TemplateSpecializationType>())
10902 if (TST->isTypeAlias())
10909 // specified for it (not even void). The address of a destructor
10950 // A destructor shall not be declared with a ref-qualifier.
10981 const FunctionProtoType *Proto = R->castAs<FunctionProtoType>();
10982 FunctionProtoType::ExtProtoInfo EPI = Proto->getExtProtoInfo();
11010 // parameter returning conversion-type-id."
11048 const auto *Proto = R->castAs<FunctionProtoType>();
11051 unsigned NumParam = Proto->getNumParams();
11054 // A conversion function shall have no non-object parameters.
11059 First && First->isExplicitObjectParameter())
11060 NumParam--;
11068 } else if (Proto->isVariadic()) {
11075 if (Proto->getReturnType() != ConvType) {
11088 if (TRT) extendRight(After, TRT->getTypeLoc().getSourceRange());
11123 // If we can provide a correct fix-it hint, do so.
11126 getLocForEndOfToken(ConvTSI->getTypeLoc().getEndLoc());
11132 } else if (!Proto->getReturnType()->isDependentType()) {
11133 DB << /*typedef*/1 << Proto->getReturnType();
11135 DB << /*alias template*/2 << Proto->getReturnType();
11146 ConvType = Proto->getReturnType();
11150 // The conversion-type-id shall not represent a function type nor
11152 if (ConvType->isArrayType()) {
11156 } else if (ConvType->isFunctionType()) {
11167 Proto->getExtProtoInfo());
11181 CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Conversion->getDeclContext());
11184 QualType ConvType = Context.getCanonicalType(Conversion->getConversionType());
11187 // (possibly cv-qualified) object to the (possibly cv-qualified)
11189 // cv-qualified) base class of that type (or a reference to it),
11190 // or to (possibly cv-qualified) void.
11193 if (const ReferenceType *ConvTypeRef = ConvType->getAs<ReferenceType>())
11194 ConvType = ConvTypeRef->getPointeeType();
11195 if (Conversion->getTemplateSpecializationKind() != TSK_Undeclared &&
11196 Conversion->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)
11198 else if (Conversion->size_overridden_methods() != 0)
11200 else if (ConvType->isRecordType()) {
11203 Diag(Conversion->getLocation(), diag::warn_conv_to_self_not_used)
11205 else if (IsDerivedFrom(Conversion->getLocation(), ClassType, ConvType))
11206 Diag(Conversion->getLocation(), diag::warn_conv_to_base_not_used)
11208 } else if (ConvType->isVoidType()) {
11209 Diag(Conversion->getLocation(), diag::warn_conv_to_void_not_used)
11214 Conversion->getDescribedFunctionTemplate()) {
11215 if (const auto *ConvTypePtr = ConvType->getAs<PointerType>()) {
11216 ConvType = ConvTypePtr->getPointeeType();
11218 if (ConvType->isUndeducedAutoType()) {
11219 Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
11221 << llvm::to_underlying(ConvType->castAs<AutoType>()->getKeyword())
11255 if (!Param->isExplicitObjectParameter())
11261 Diag(Param->getLocation(),
11263 << IsLambda << Param->getSourceRange();
11269 if (ExplicitObjectParam->hasDefaultArg()) {
11270 Diag(ExplicitObjectParam->getLocation(),
11272 << ExplicitObjectParam->getSourceRange();
11278 Diag(ExplicitObjectParam->getBeginLoc(),
11285 Diag(ExplicitObjectParam->getBeginLoc(),
11313 Diag(ExplicitObjectParam->getBeginLoc(),
11315 << D.getSourceRange() << /*non-member=*/2 << IsLambda;
11320 Diag(ExplicitObjectParam->getBeginLoc(),
11328 if (!DC || !DC->isRecord()) {
11329 assert(D.isInvalidType() && "Explicit object parameter in non-member "
11337 Diag(ExplicitObjectParam->getBeginLoc(),
11382 // A deduction-gide shall be declared in the same scope as the
11384 if (!CurContext->getRedeclContext()->Equals(
11385 GuidedTemplateDecl->getDeclContext()->getRedeclContext())) {
11443 // the template specified as the deduction-guide's name.
11452 TSI->getTypeLoc().getAsAdjusted<TemplateSpecializationTypeLoc>()) {
11453 TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName();
11460 bool SimplyWritten = !Qualifiers->hasTemplateKeyword() &&
11461 Qualifiers->getQualifier() == nullptr;
11471 } else if (!RetTy.hasQualifiers() && RetTy->isDependentType()) {
11476 return Diag(TSI->getTypeLoc().getBeginLoc(),
11478 << GuidedTemplate << TSI->getType()
11480 << TSI->getTypeLoc().getSourceRange();
11493 //===----------------------------------------------------------------------===//
11495 //===----------------------------------------------------------------------===//
11503 assert(*IsInline != PrevNS->isInline());
11508 PrevNS = PrevNS->getFirstDecl();
11510 if (PrevNS->isInline())
11518 S.Diag(PrevNS->getLocation(), diag::note_previous_definition);
11519 *IsInline = PrevNS->isInline();
11522 /// ActOnStartNamespaceDef - This is called at the start of a namespace
11538 Scope *DeclRegionScope = NamespcScope->getParent();
11549 assert(IsInline && II->isStr("std") &&
11550 CurContext->getRedeclContext()->isTranslationUnit() &&
11557 // The identifier in an original-namespace-definition shall not
11559 // which the original-namespace-definition appears. The
11560 // identifier in an original-namespace-definition is the name of
11562 // treated as an original-namespace-name.
11569 LookupQualifiedName(R, CurContext->getRedeclContext());
11576 if (IsInline && II->isStr("std") &&
11577 CurContext->getRedeclContext()->isTranslationUnit())
11579 else if (IsInline != PrevNS->isInline())
11586 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
11589 } else if (II->isStr("std") &&
11590 CurContext->getRedeclContext()->isTranslationUnit()) {
11606 DeclContext *Parent = CurContext->getRedeclContext();
11608 PrevNS = TU->getAnonymousNamespace();
11611 PrevNS = ND->getAnonymousNamespace();
11614 if (PrevNS && IsInline != PrevNS->isInline())
11622 Namespc->setInvalidDecl();
11629 if (const VisibilityAttr *Attr = Namespc->getAttr<VisibilityAttr>())
11641 DeclContext *Parent = CurContext->getRedeclContext();
11643 TU->setAnonymousNamespace(Namespc);
11645 cast<NamespaceDecl>(Parent)->setAnonymousNamespace(Namespc);
11648 CurContext->addDecl(Namespc);
11650 // C++ [namespace.unnamed]p1. An unnamed-namespace-definition
11654 // namespace unique { namespace-body }
11674 UD->setImplicit();
11675 Parent->addDecl(UD);
11690 /// getNamespaceDecl - Returns the namespace a decl represents. If the decl
11694 return AD->getNamespace();
11701 Namespc->setRBraceLoc(RBrace);
11703 if (Namespc->hasAttr<VisibilityAttr>())
11705 // If this namespace contains an export-declaration, export it now.
11707 Dcl->setModuleOwnershipKind(Decl::ModuleOwnershipKind::VisibleWhenImported);
11748 S.Diag(VD->getLocation(), diag::note_var_declared_here)
11749 << VD << VD->getSourceRange();
11768 Info->getType());
11780 return Info->getType();
11792 assert(Info->Kind == Kind);
11793 assert(Info->Record);
11797 if (Info->Record->hasDefinition())
11798 Info->Record = Info->Record->getDefinition();
11805 if (!Info->Record->isTriviallyCopyable())
11808 for (const CXXBaseSpecifier &BaseSpec : Info->Record->bases()) {
11809 CXXRecordDecl *Base = BaseSpec.getType()->getAsCXXRecordDecl();
11811 if (Base->isEmpty())
11813 // Reject STL implementations which have at least one non-empty base.
11821 auto FIt = Info->Record->field_begin(), FEnd = Info->Record->field_end();
11823 !FIt->getType()->isIntegralOrEnumerationType()) {
11831 ComparisonCategoryInfo::ValueInfo *ValInfo = Info->lookupValueInfo(CCR);
11836 VarDecl *VD = ValInfo->VD;
11842 if (!VD->isStaticDataMember() ||
11843 !VD->isUsableInConstantExpressions(Context))
11849 if (!ValInfo->hasValidIntValue())
11858 return Info->getType();
11869 getStdNamespace()->setImplicit(true);
11872 Context.getTranslationUnitDecl()->addDecl(getStdNamespace());
11873 getStdNamespace()->clearIdentifierNamespace();
11892 if (const RecordType *RT = Ty->getAs<RecordType>()) {
11895 dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
11899 Template = Specialization->getSpecializedTemplate();
11900 Arguments = Specialization->getTemplateArgs().data();
11903 if (auto *ICN = Ty->getAs<InjectedClassNameType>())
11904 TST = ICN->getInjectedTST();
11906 TST = Ty->getAs<TemplateSpecializationType>();
11909 TST->getTemplateName().getAsTemplateDecl());
11910 Arguments = TST->template_arguments().begin();
11918 CXXRecordDecl *TemplateClass = Template->getTemplatedDecl();
11919 if (TemplateClass->getIdentifier() !=
11921 !getStdNamespace()->InEnclosingNamespaceSetOf(
11922 TemplateClass->getNonTransparentDeclContext()))
11926 TemplateParameterList *Params = Template->getTemplateParameters();
11927 if (Params->getMinRequiredArguments() != 1)
11929 if (!isa<TemplateTypeParmDecl>(Params->getParam(0)))
11936 if (Template->getCanonicalDecl() != StdInitializerList->getCanonicalDecl())
11963 S.Diag(Found->getLocation(), diag::err_malformed_std_initializer_list);
11969 TemplateParameterList *Params = Template->getTemplateParameters();
11970 if (Params->getMinRequiredArguments() != 1 ||
11971 !isa<TemplateTypeParmDecl>(Params->getParam(0))) {
11972 S.Diag(Template->getLocation(), diag::err_malformed_std_initializer_list);
11998 // A constructor is an initializer-list constructor if its first parameter
11999 // is of type std::initializer_list<E> or reference to possibly cv-qualified
12002 if (!Ctor->hasOneParamOrDefaultArgs())
12005 QualType ArgType = Ctor->getParamDecl(0)->getType();
12006 if (const ReferenceType *RT = ArgType->getAs<ReferenceType>())
12007 ArgType = RT->getPointeeType().getUnqualifiedType();
12015 switch (CurContext->getDeclKind()) {
12019 return IsUsingDirectiveInToplevelContext(CurContext->getParent());
12046 Module *M = ND->getOwningModule();
12049 if (M->isExplicitGlobalModule())
12058 << M->getTopLevelModuleName();
12072 // See https://github.com/llvm/llvm-project/issues/73893.
12082 Corrected.WillReplaceSpecifier() && Ident->getName() == CorrectedStr;
12108 S = S->getDeclParent();
12125 if ((!Qualifier || Qualifier->getKind() == NestedNameSpecifier::Global) &&
12126 NamespcName->isStr("std")) {
12144 // A using-directive specifies that the names in the nominated
12146 // using-directive appears after the using-directive. During
12149 // contains both the using-directive and the nominated
12153 // Find enclosing context containing both using-directive and
12156 while (CommonAncestor && !CommonAncestor->Encloses(CurContext))
12157 CommonAncestor = CommonAncestor->getParent();
12185 DeclContext *Ctx = S->getEntity();
12186 if (Ctx && !Ctx->isFunctionOrMethod())
12187 Ctx->addDecl(UDir);
12189 // Otherwise, it is at block scope. The using-directives will affect lookup
12191 S->PushUsingDirective(UDir);
12200 assert(S->getFlags() & Scope::DeclScope && "Invalid Scope.");
12234 << SourceRange(Name.TemplateId->LAngleLoc, Name.TemplateId->RAngleLoc);
12259 if (!SS.getScopeRep()->containsUnexpandedParameterPack() &&
12283 assert(!SS->isInvalid() && "ScopeSpec is invalid");
12292 << SourceRange(SS ? SS->getBeginLoc() : IdentLoc, TyLoc.getEnd());
12296 if (EnumTy->isDependentType()) {
12301 auto *Enum = dyn_cast_if_present<EnumDecl>(EnumTy->getAsTagDecl());
12307 if (auto *Def = Enum->getDefinition())
12327 if (D1->getCanonicalDecl() == D2->getCanonicalDecl())
12332 return Context.hasSameType(TD1->getUnderlyingType(),
12333 TD2->getUnderlyingType());
12335 // Two using_if_exists using-declarations are equivalent if both are
12350 // will pre-empt further diagnostics.
12359 // template <class T> struct D : C<T> { using B::foo; } // <---
12364 // to A::foo, which will look well-formed when we instantiate.
12365 // The right solution is to not collapse the shadow-decl chain.
12366 if (!getLangOpts().CPlusPlus11 && CurContext->isRecord())
12368 DeclContext *OrigDC = Orig->getDeclContext();
12372 OrigDC = OrigDC->getParent();
12374 while (OrigRec->isAnonymousStructOrUnion())
12375 OrigRec = cast<CXXRecordDecl>(OrigRec->getDeclContext());
12377 if (cast<CXXRecordDecl>(CurContext)->isProvablyNotDerivedFrom(OrigRec)) {
12379 Diag(Using->getLocation(),
12381 << Using->getQualifierLoc().getSourceRange();
12382 Diag(Orig->getLocation(), diag::note_using_decl_target);
12383 Using->setInvalidDecl();
12387 Diag(Using->getQualifierLoc().getBeginLoc(),
12389 << Using->getQualifier() << cast<CXXRecordDecl>(CurContext)
12390 << Using->getQualifierLoc().getSourceRange();
12391 Diag(Orig->getLocation(), diag::note_using_decl_target);
12392 Using->setInvalidDecl();
12401 Target = cast<UsingShadowDecl>(Target)->getTargetDecl();
12412 NamedDecl *D = (*I)->getUnderlyingDecl();
12422 // a non-static data member] shall have a name different from T
12423 if (RD->isInjectedClassName() && !isa<FieldDecl>(Target) &&
12428 DeclarationNameInfo(BUD->getDeclName(), BUD->getLocation())))
12455 Diag(BUD->getLocation(), diag::err_using_decl_conflict);
12456 Diag(Target->getLocation(), diag::note_using_decl_target);
12457 Diag((NonTag ? NonTag : Tag)->getLocation(),
12459 BUD->setInvalidDecl();
12463 if (FunctionDecl *FD = Target->getAsFunction()) {
12471 Diag(BUD->getLocation(), diag::err_using_decl_conflict);
12479 if (CurContext->isRecord())
12483 Diag(BUD->getLocation(), diag::err_using_decl_conflict);
12487 Diag(Target->getLocation(), diag::note_using_decl_target);
12488 Diag(OldDecl->getLocation(), diag::note_using_decl_conflict);
12489 BUD->setInvalidDecl();
12496 // No conflict between a tag and a non-tag.
12499 Diag(BUD->getLocation(), diag::err_using_decl_conflict);
12500 Diag(Target->getLocation(), diag::note_using_decl_target);
12501 Diag(Tag->getLocation(), diag::note_using_decl_conflict);
12502 BUD->setInvalidDecl();
12506 // No conflict between a tag and a non-tag.
12509 Diag(BUD->getLocation(), diag::err_using_decl_conflict);
12510 Diag(Target->getLocation(), diag::note_using_decl_target);
12511 Diag(NonTag->getLocation(), diag::note_using_decl_conflict);
12512 BUD->setInvalidDecl();
12518 if (!Derived->getNumVBases())
12520 for (auto &B : Derived->bases())
12521 if (B.getType()->getAsCXXRecordDecl() == Base)
12532 Target = cast<UsingShadowDecl>(Target)->getTargetDecl();
12538 NonTemplateTarget = TargetTD->getTemplatedDecl();
12545 Using->getQualifier()->getAsRecordDecl());
12547 Context, CurContext, Using->getLocation(), Using, Orig, IsVirtualBase);
12549 Shadow = UsingShadowDecl::Create(Context, CurContext, BUD->getLocation(),
12550 Target->getDeclName(), BUD, Target);
12552 BUD->addShadowDecl(Shadow);
12554 Shadow->setAccess(BUD->getAccess());
12555 if (Orig->isInvalidDecl() || BUD->isInvalidDecl())
12556 Shadow->setInvalidDecl();
12558 Shadow->setPreviousDecl(PrevDecl);
12563 CurContext->addDecl(Shadow);
12570 if (Shadow->getDeclName().getNameKind() ==
12572 cast<CXXRecordDecl>(Shadow->getDeclContext())->removeConversion(Shadow);
12575 Shadow->getDeclContext()->removeDecl(Shadow);
12579 S->RemoveDecl(Shadow);
12584 Shadow->getIntroducer()->removeShadowDecl(Shadow);
12595 CanQualType CanonicalDesiredBase = DesiredBase->getCanonicalTypeUnqualified()
12597 for (auto &Base : Derived->bases()) {
12598 CanQualType BaseType = Base.getType()->getCanonicalTypeUnqualified();
12601 if (BaseType->isDependentType())
12632 if (FoundRecord && FoundRecord->isInjectedClassName()) {
12633 // No-one ever wants a using-declaration to name an injected-class-name
12635 ASTContext &Ctx = ND->getASTContext();
12640 // Check that the injected-class-name is named as a member of its own
12647 if (!Specifier->getAsType() ||
12648 !Ctx.hasSameType(QualType(Specifier->getAsType(), 0), FoundType))
12660 auto *RD = dyn_cast<CXXRecordDecl>(ND->getDeclContext());
12661 if (!RD || RequireMemberOf->isProvablyNotDerivedFrom(RD))
12668 if (FoundRecord && FoundRecord->isInjectedClassName())
12697 // If we found a local extern declaration that's not ordinarily visible,
12698 // and this declaration is being added to a non-block scope, ignore it.
12701 else if (!CurContext->isFunctionOrMethod() && D->isLocalExternDecl() &&
12702 !(D->getIdentifierNamespace() & Decl::IDNS_Ordinary))
12738 assert(IsInstantiation && "no scope in non-instantiation");
12739 if (CurContext->isRecord())
12742 // No redeclaration check is needed here; in non-member contexts we
12743 // diagnosed all possible conflicts with other using-declarations when
12746 // For a dependent non-type using declaration, the only valid case is
12749 // definition for conflicts between a non-type using declaration and any
12790 D->setAccess(AS);
12791 CurContext->addDecl(D);
12800 UD->setAccess(AS);
12801 CurContext->addDecl(UD);
12803 UD->setInvalidDecl(Invalid);
12818 // where they may be used by two-phase lookup.
12824 if (CurContext->isRecord()) {
12847 // HACK 2017-01-08: Work around an issue with libstdc++'s detection of
12849 // it does not. The issue was fixed in libstdc++ 6.3 (2016-12-21) and later.
12851 if (getLangOpts().CPlusPlus14 && II && II->isStr("gets") &&
12852 CurContext->isStdNamespace() &&
12875 if (RD && RD->isInjectedClassName()) {
12877 RD = cast<CXXRecordDecl>(RD->getParent());
12899 UsingName.setName(ND->getDeclName());
12913 // If we asked for a typename and got a non-type decl, error out.
12918 Diag((*I)->getUnderlyingDecl()->getLocation(),
12923 // If we asked for a non-typename and we got a type, error out,
12928 Diag(R.getFoundDecl()->getLocation(), diag::note_using_decl_target);
12934 // A using-declaration shall not name a namespace.
12973 if (CurContext->getRedeclContext()->isRecord()) {
12975 DeclarationNameInfo UsingEnumName(ED->getDeclName(), NameLoc);
12983 if (UED->getEnumDecl() == ED) {
12986 Diag(D->getLocation(), diag::note_using_enum_decl) << 1;
12997 UD->setAccess(AS);
12998 CurContext->addDecl(UD);
13001 UD->setInvalidDecl();
13006 for (EnumConstantDecl *EC : ED->enumerators()) {
13008 DeclarationNameInfo DNI(EC->getDeclName(), EC->getLocation());
13029 UPD->setAccess(InstantiatedFrom->getAccess());
13030 CurContext->addDecl(UPD);
13035 assert(!UD->hasTypename() && "expecting a constructor name");
13037 const Type *SourceType = UD->getQualifier()->getAsType();
13047 Diag(UD->getUsingLoc(),
13049 << UD->getNameInfo().getSourceRange()
13051 UD->setInvalidDecl();
13056 Base->setInheritConstructors();
13070 // A using-declaration is a declaration and can therefore be used
13074 // That's in non-member contexts.
13075 if (!CurContext->getRedeclContext()->isRecord()) {
13077 // enumeration type. Therefore it conflicts with any other non-type
13079 // FIXME: How should we check for dependent type-type conflicts at block
13081 if (Qual->isDependent() && !HasTypenameKeyword) {
13090 Diag(D->getLocation(), diag::note_previous_definition);
13106 DTypename = UD->hasTypename();
13107 DQual = UD->getQualifier();
13111 DQual = UD->getQualifier();
13115 DQual = UD->getQualifier();
13119 // FIXME: non-dependent using decls?
13129 Diag(D->getLocation(), diag::note_using_decl) << 1;
13145 // C++ 20 permits using an enumerator that does not have a class-hierarchy
13151 EC = R->getAsSingle<EnumConstantDecl>();
13152 else if (UD && UD->shadow_size() == 1)
13153 EC = dyn_cast<EnumConstantDecl>(UD->shadow_begin()->getTargetDecl());
13159 // A using-declaration shall not name a scoped enumerator.
13161 if (EC && R && ED->isScoped())
13169 NamedContext = ED->getDeclContext();
13173 if (!CurContext->isRecord()) {
13176 // A using-declaration for a class member shall be a member-declaration.
13183 if (NamedContext ? !NamedContext->getRedeclContext()->isRecord()
13197 ? cast<CXXRecordDecl>(NamedContext->getRedeclContext())
13205 } else if (R->getAsSingle<TypeDecl>()) {
13222 } else if (R->getAsSingle<VarDecl>()) {
13235 } else if (R->getAsSingle<EnumConstantDecl>()) {
13259 // nested-name-specifier does not refer to a base class, which is
13268 if (!NamedContext->isRecord()) {
13283 if (!NamedContext->isDependentContext() &&
13289 // In a using-declaration used as a member-declaration, the
13290 // nested-name-specifier shall name a base class of the class
13293 if (cast<CXXRecordDecl>(CurContext)->isProvablyNotDerivedFrom(
13309 if (!cast<CXXRecordDecl>(NamedContext)->isInvalidDecl()) {
13322 // A using-declaration used as a member-declaration shall refer
13341 if (!cast<CXXRecordDecl>(CurContext)->forallBases(Collect))
13353 !cast<CXXRecordDecl>(NamedContext)->forallBases(IsNotBase))
13371 S = S->getDeclParent();
13388 TInfo->getTypeLoc().getBeginLoc());
13399 Previous.getFoundDecl()->isTemplateParameter()) {
13410 NewTD->setAccess(AS);
13413 NewTD->setInvalidDecl();
13420 Invalid |= NewTD->isInvalidDecl();
13431 << SourceRange(TemplateParamLists[1]->getTemplateLoc(),
13432 TemplateParamLists[TemplateParamLists.size()-1]->getRAngleLoc());
13453 if (OldD->getLocation().isValid())
13454 Diag(OldD->getLocation(), diag::note_previous_definition);
13459 if (!Invalid && OldDecl && !OldDecl->isInvalidDecl()) {
13461 OldDecl->getTemplateParameters(),
13465 OldDecl->getMostRecentDecl()->getTemplateParameters();
13469 TypeAliasDecl *OldTD = OldDecl->getTemplatedDecl();
13471 !Context.hasSameType(OldTD->getUnderlyingType(),
13472 NewTD->getUnderlyingType())) {
13473 // FIXME: The C++0x standard does not clearly say this is ill-formed,
13475 Diag(NewTD->getLocation(), diag::err_redefinition_different_typedef)
13476 << 2 << NewTD->getUnderlyingType() << OldTD->getUnderlyingType();
13477 if (OldTD->getLocation().isValid())
13478 Diag(OldTD->getLocation(), diag::note_previous_definition);
13494 NewTD->setDescribedAliasTemplate(NewDecl);
13496 NewDecl->setAccess(AS);
13499 NewDecl->setInvalidDecl();
13501 NewDecl->setPreviousDecl(OldDecl);
13548 if (PrevR.isSingleResult() && PrevR.getFoundDecl()->isTemplateParameter()) {
13564 if (AD->getNamespace()->Equals(getNamespaceDecl(ND))) {
13569 Diag(AD->getLocation(), diag::note_previous_namespace_alias)
13570 << AD->getNamespace();
13574 unsigned DiagID = isa<NamespaceDecl>(PrevDecl->getUnderlyingDecl())
13578 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
13591 AliasDecl->setPreviousDecl(Prev);
13621 auto *RT = Base->getType()->getAs<RecordType>();
13625 auto *BaseClass = cast<CXXRecordDecl>(RT->getDecl());
13638 FD->hasInClassInitializer()) {
13639 Expr *E = FD->getInClassInitializer();
13644 // this location should be MD->getLocation() instead, since that's
13649 } else if (auto *RT = S.Context.getBaseElementType(FD->getType())
13650 ->getAs<RecordType>()) {
13651 visitClassSubobject(cast<CXXRecordDecl>(RT->getDecl()), FD,
13652 FD->getType().getCVRQualifiers());
13661 bool IsMutable = Field && Field->isMutable();
13678 if (Converted.isUsable() && !Converted.get()->isValueDependent()) {
13690 if (!ExplicitExpr->isTypeDependent())
13701 CXXRecordDecl *ClassDecl = MD->getParent();
13705 // exception-specification. [...]
13706 SpecialMemberExceptionSpecInfo Info(S, MD, CSM, ICI, MD->getLocation());
13707 if (ClassDecl->isInvalidDecl())
13713 if (S.RequireCompleteType(MD->getLocation(),
13722 // The exception specification for an implicitly-declared destructor, or a
13723 // destructor without a noexcept-specifier, is potentially-throwing if and
13732 // ... due to giving B::~B() a non-throwing exception specification.
13765 Ctx.PointOfInstantiation = RD->getLocation();
13788 DeclarationName Name = FD->getDeclName();
13791 for (auto *D : FD->getParent()->lookup(Name))
13798 FD->isThisDeclarationADefinition());
13813 SpecialMem->setType(QT);
13819 cast<CXXRecordDecl>(SpecialMem->getParent())->isLambda()) {
13821 Context.getTrivialTypeSourceInfo(SpecialMem->getType());
13822 SpecialMem->setTypeSourceInfo(TSI);
13831 // user-declared constructor for class X, a default constructor is
13832 // implicitly declared. An implicitly-declared default constructor
13834 assert(ClassDecl->needsImplicitDefaultConstructor() &&
13848 SourceLocation ClassLoc = ClassDecl->getLocation();
13859 DefaultCon->setAccess(AS_public);
13860 DefaultCon->setDefaulted();
13872 DefaultCon->setTrivial(ClassDecl->hasTrivialDefaultConstructor());
13886 ClassDecl->addDecl(DefaultCon);
13893 assert((Constructor->isDefaulted() && Constructor->isDefaultConstructor() &&
13894 !Constructor->doesThisDeclarationHaveABody() &&
13895 !Constructor->isDeleted()) &&
13896 "DefineImplicitDefaultConstructor - call it for implicit default ctor");
13897 if (Constructor->willHaveBody() || Constructor->isInvalidDecl())
13900 CXXRecordDecl *ClassDecl = Constructor->getParent();
13901 assert(ClassDecl && "DefineImplicitDefaultConstructor - invalid constructor");
13902 if (ClassDecl->isInvalidDecl()) {
13911 Constructor->getType()->castAs<FunctionProtoType>());
13918 Constructor->setInvalidDecl();
13922 SourceLocation Loc = Constructor->getEndLoc().isValid()
13923 ? Constructor->getEndLoc()
13924 : Constructor->getLocation();
13925 Constructor->setBody(new (Context) CompoundStmt(Loc));
13926 Constructor->markUsed(Context);
13929 L->CompletedImplicitDefinition(Constructor);
13946 CXXRecordDecl *Derived = Shadow->getParent();
13947 SourceLocation UsingLoc = Shadow->getLocation();
13952 DeclarationName Name = BaseCtor->getDeclName();
13956 for (NamedDecl *Ctor : Derived->lookup(Name))
13958 ->getInheritedConstructor()
13965 Context.getTrivialTypeSourceInfo(BaseCtor->getType(), UsingLoc);
13967 TInfo->getTypeLoc().IgnoreParens().castAs<FunctionProtoTypeLoc>();
13973 bool Constexpr = BaseCtor->isConstexpr() &&
13979 Context, Derived, UsingLoc, NameInfo, TInfo->getType(), TInfo,
13980 BaseCtor->getExplicitSpecifier(), getCurFPFeatures().isFPConstrained(),
13983 Constexpr ? BaseCtor->getConstexprKind() : ConstexprSpecKind::Unspecified,
13985 BaseCtor->getTrailingRequiresClause());
13986 if (Shadow->isInvalidDecl())
13987 DerivedCtor->setInvalidDecl();
13990 const FunctionProtoType *FPT = TInfo->getType()->castAs<FunctionProtoType>();
13991 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
13994 DerivedCtor->setType(Context.getFunctionType(FPT->getReturnType(),
13995 FPT->getParamTypes(), EPI));
13999 for (unsigned I = 0, N = FPT->getNumParams(); I != N; ++I) {
14001 Context.getTrivialTypeSourceInfo(FPT->getParamType(I), UsingLoc);
14004 FPT->getParamType(I), TInfo, SC_None, /*DefArg=*/nullptr);
14005 PD->setScopeInfo(0, I);
14006 PD->setImplicit();
14009 mergeDeclAttributes(PD, BaseCtor->getParamDecl(I));
14015 assert(!BaseCtor->isDeleted() && "should not use deleted constructor");
14016 DerivedCtor->setAccess(BaseCtor->getAccess());
14017 DerivedCtor->setParams(ParamDecls);
14018 Derived->addDecl(DerivedCtor);
14028 InheritedConstructorInfo ICI(*this, Ctor->getLocation(),
14029 Ctor->getInheritedConstructor().getShadowDecl());
14037 CXXRecordDecl *ClassDecl = Constructor->getParent();
14038 assert(Constructor->getInheritedConstructor() &&
14039 !Constructor->doesThisDeclarationHaveABody() &&
14040 !Constructor->isDeleted());
14041 if (Constructor->willHaveBody() || Constructor->isInvalidDecl())
14051 Constructor->getType()->castAs<FunctionProtoType>());
14058 Constructor->getInheritedConstructor().getShadowDecl();
14060 Constructor->getInheritedConstructor().getConstructor();
14068 CXXRecordDecl *RD = Shadow->getParent();
14069 SourceLocation InitLoc = Shadow->getLocation();
14075 for (CXXBaseSpecifier &B : VBase ? RD->vbases() : RD->bases()) {
14079 auto *BaseRD = B.getType()->getAsCXXRecordDecl();
14102 Constructor->setInvalidDecl();
14106 Constructor->setBody(new (Context) CompoundStmt(InitLoc));
14107 Constructor->markUsed(Context);
14110 L->CompletedImplicitDefinition(Constructor);
14118 // If a class has no user-declared destructor, a destructor is
14119 // declared implicitly. An implicitly-declared destructor is an
14121 assert(ClassDecl->needsImplicitDestructor());
14134 SourceLocation ClassLoc = ClassDecl->getLocation();
14145 Destructor->setAccess(AS_public);
14146 Destructor->setDefaulted();
14158 Destructor->setTrivial(ClassDecl->hasTrivialDestructor());
14159 Destructor->setTrivialForCall(ClassDecl->hasAttr<TrivialABIAttr>() ||
14160 ClassDecl->hasTrivialDestructorForCall());
14171 if (ClassDecl->isCompleteDefinition() &&
14178 ClassDecl->addDecl(Destructor);
14185 assert((Destructor->isDefaulted() &&
14186 !Destructor->doesThisDeclarationHaveABody() &&
14187 !Destructor->isDeleted()) &&
14188 "DefineImplicitDestructor - call it for implicit default dtor");
14189 if (Destructor->willHaveBody() || Destructor->isInvalidDecl())
14192 CXXRecordDecl *ClassDecl = Destructor->getParent();
14193 assert(ClassDecl && "DefineImplicitDestructor - invalid destructor");
14200 Destructor->getType()->castAs<FunctionProtoType>());
14206 MarkBaseAndMemberDestructorsReferenced(Destructor->getLocation(),
14207 Destructor->getParent());
14210 Destructor->setInvalidDecl();
14214 SourceLocation Loc = Destructor->getEndLoc().isValid()
14215 ? Destructor->getEndLoc()
14216 : Destructor->getLocation();
14217 Destructor->setBody(new (Context) CompoundStmt(Loc));
14218 Destructor->markUsed(Context);
14221 L->CompletedImplicitDefinition(Destructor);
14227 if (Destructor->isInvalidDecl())
14230 CXXRecordDecl *ClassDecl = Destructor->getParent();
14233 assert(ClassDecl->getNumVBases() > 0 &&
14241 MarkVirtualBaseDestructorsReferenced(Destructor->getLocation(), ClassDecl);
14247 if (Record->isInvalidDecl()) {
14263 DefineDefaultedFunction(*this, M, M->getLocation());
14268 if (M->getParent()->getTemplateSpecializationKind() !=
14278 // be called again, so use a local copy of DelayedDllExportClasses.
14290 if (Destructor->isDependentContext())
14294 // A declaration of a destructor that does not have an exception-
14295 // specification is implicitly considered to have the same exception-
14297 const auto *DtorType = Destructor->getType()->castAs<FunctionProtoType>();
14298 if (DtorType->hasExceptionSpec())
14304 FunctionProtoType::ExtProtoInfo EPI = DtorType->getExtProtoInfo();
14307 Destructor->setType(
14450 /// of class type where the selected copy/move-assignment operator is trivial.
14459 // Take the address of the field references for "from" and "to". We
14461 // does not permit us to take the address of an xvalue.
14464 S.Context, From, UO_AddrOf, S.Context.getPointerType(From->getType()),
14468 S.Context, To, UO_AddrOf, S.Context.getPointerType(To->getType()),
14471 const Type *E = T->getBaseElementTypeUnsafe();
14473 E->isRecordType() &&
14474 E->castAs<RecordType>()->getDecl()->hasObjectMember();
14508 /// implicitly-declared copy/move assignment operator. When the entities being
14511 /// \param S The Sema object used for type-checking.
14523 /// Otherwise, it's a non-static member subobject.
14539 // - if the subobject is of class type, as if by a call to operator= with
14546 // - if the subobject is of class type, the copy assignment operator for
14550 if (const RecordType *RecordTy = T->getAs<RecordType>()) {
14551 CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(RecordTy->getDecl());
14559 // Prior to C++11, filter out any result that isn't a copy/move-assignment
14566 if (Method->isCopyAssignmentOperator() ||
14567 (!Copying && Method->isMoveAssignmentOperator()))
14577 // we're assigning via a base classes's copy-assignment operator. To
14594 // Create the nested-name-specifier that will be used to qualify the
14627 if (CE && CE->getMethodDecl()->isTrivial() && Depth)
14630 // Convert to an expression-statement, and clean up any produced
14635 // - if the subobject is of scalar type, the built-in assignment
14646 // - if the subobject is an array, each element is assigned, in the
14651 // for (__SIZE_TYPE__ i0 = 0; i0 != array-size; ++i0)
14671 IterationVar->setInit(IntegerLiteral::Create(S.Context, Zero, SizeType, Loc));
14693 buildSingleCopyAssignRecursively(S, Loc, ArrayTy->getElementType(),
14702 = ArrayTy->getSize().zextOrTrunc(S.Context.getTypeSize(SizeType));
14709 // Create the pre-increment of the iteration variable. We can determine
14728 if (T->isArrayType() && !T.isConstQualified() && !T.isVolatileQualified() &&
14737 // non-trivially-copyable class type, just emit a memcpy.
14749 assert(ClassDecl->needsImplicitCopyAssignment());
14763 bool Const = ClassDecl->implicitCopyAssignmentHasConstParam();
14772 // An implicitly-declared copy assignment operator is an inline public
14775 SourceLocation ClassLoc = ClassDecl->getLocation();
14784 CopyAssignment->setAccess(AS_public);
14785 CopyAssignment->setDefaulted();
14786 CopyAssignment->setImplicit();
14802 CopyAssignment->setParams(FromParam);
14804 CopyAssignment->setTrivial(
14805 ClassDecl->needsOverloadResolutionForCopyAssignment()
14808 : ClassDecl->hasTrivialCopyAssignment());
14810 // Note that we have added this copy-assignment operator.
14818 ClassDecl->setImplicitCopyAssignmentIsDeleted();
14824 ClassDecl->addDecl(CopyAssignment);
14829 /// Diagnose an implicit copy operation for a class which is odr-used, but
14830 /// which is deprecated because the class has a user-declared copy constructor,
14833 assert(CopyOp->isImplicit());
14835 CXXRecordDecl *RD = CopyOp->getParent();
14838 if (RD->hasUserDeclaredDestructor()) {
14839 UserDeclaredOperation = RD->getDestructor();
14841 RD->hasUserDeclaredCopyConstructor()) {
14842 // Find any user-declared copy constructor.
14843 for (auto *I : RD->ctors()) {
14844 if (I->isCopyConstructor()) {
14851 RD->hasUserDeclaredCopyAssignment()) {
14852 // Find any user-declared move assignment operator.
14853 for (auto *I : RD->methods()) {
14854 if (I->isCopyAssignmentOperator()) {
14863 bool UDOIsUserProvided = UserDeclaredOperation->isUserProvided();
14874 S.Diag(UserDeclaredOperation->getLocation(), DiagID)
14881 assert((CopyAssignOperator->isDefaulted() &&
14882 CopyAssignOperator->isOverloadedOperator() &&
14883 CopyAssignOperator->getOverloadedOperator() == OO_Equal &&
14884 !CopyAssignOperator->doesThisDeclarationHaveABody() &&
14885 !CopyAssignOperator->isDeleted()) &&
14887 if (CopyAssignOperator->willHaveBody() || CopyAssignOperator->isInvalidDecl())
14890 CXXRecordDecl *ClassDecl = CopyAssignOperator->getParent();
14891 if (ClassDecl->isInvalidDecl()) {
14892 CopyAssignOperator->setInvalidDecl();
14901 CopyAssignOperator->getType()->castAs<FunctionProtoType>());
14908 // deprecated if the class has a user-declared copy constructor or a
14909 // user-declared destructor.
14910 if (getLangOpts().CPlusPlus11 && CopyAssignOperator->isImplicit())
14914 // The implicitly-defined or explicitly-defaulted copy assignment operator
14915 // for a non-union class X performs memberwise copy assignment of its
14917 // order of their declaration in the base-specifier-list, and then the
14918 // immediate non-static data members of X are assigned, in the order in
14925 ParmVarDecl *Other = CopyAssignOperator->getNonObjectParameter(0);
14926 Qualifiers OtherQuals = Other->getType().getQualifiers();
14927 QualType OtherRefType = Other->getType();
14928 if (OtherRefType->isLValueReferenceType()) {
14929 OtherRefType = OtherRefType->getPointeeType();
14933 // Our location for everything implicitly-generated.
14934 SourceLocation Loc = CopyAssignOperator->getEndLoc().isValid()
14935 ? CopyAssignOperator->getEndLoc()
14936 : CopyAssignOperator->getLocation();
14947 if (CopyAssignOperator->isExplicitObjectMemberFunction()) {
14948 ObjectType = CopyAssignOperator->getParamDecl(0)->getType();
14949 if (ObjectType->isReferenceType())
14950 ObjectType = ObjectType->getPointeeType();
14951 ExplicitObject.emplace(CopyAssignOperator->getParamDecl(0), ObjectType);
14964 for (auto &Base : ClassDecl->bases()) {
14966 // static_cast<Base*>(this)->Base::operator=(static_cast<Base&>(other));
14968 if (!BaseType->isRecordType()) {
14977 // appropriately-qualified base type.
14994 CopyAssignOperator->setInvalidDecl();
15002 // Assign non-static members.
15003 for (auto *Field : ClassDecl->fields()) {
15006 if (Field->isUnnamedBitField() || Field->getParent()->isUnion())
15009 if (Field->isInvalidDecl()) {
15015 if (Field->getType()->isReferenceType()) {
15016 Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign)
15017 << Context.getTagDeclType(ClassDecl) << 0 << Field->getDeclName();
15018 Diag(Field->getLocation(), diag::note_declared_at);
15023 // Check for members of const-qualified, non-class type.
15024 QualType BaseType = Context.getBaseElementType(Field->getType());
15025 if (!BaseType->getAs<RecordType>() && BaseType.isConstQualified()) {
15026 Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign)
15027 << Context.getTagDeclType(ClassDecl) << 1 << Field->getDeclName();
15028 Diag(Field->getLocation(), diag::note_declared_at);
15033 // Suppress assigning zero-width bitfields.
15034 if (Field->isZeroLengthBitField(Context))
15037 QualType FieldType = Field->getType().getNonReferenceType();
15038 if (FieldType->isIncompleteArrayType()) {
15039 assert(ClassDecl->hasFlexibleArrayMember() &&
15046 LookupResult MemberLookup(*this, Field->getDeclName(), Loc,
15059 CopyAssignOperator->setInvalidDecl();
15082 CopyAssignOperator->setInvalidDecl();
15093 CopyAssignOperator->setBody(Body.getAs<Stmt>());
15094 CopyAssignOperator->markUsed(Context);
15097 L->CompletedImplicitDefinition(CopyAssignOperator);
15102 assert(ClassDecl->needsImplicitMoveAssignment());
15124 // An implicitly-declared move assignment operator is an inline public
15127 SourceLocation ClassLoc = ClassDecl->getLocation();
15136 MoveAssignment->setAccess(AS_public);
15137 MoveAssignment->setDefaulted();
15138 MoveAssignment->setImplicit();
15154 MoveAssignment->setParams(FromParam);
15156 MoveAssignment->setTrivial(
15157 ClassDecl->needsOverloadResolutionForMoveAssignment()
15160 : ClassDecl->hasTrivialMoveAssignment());
15162 // Note that we have added this copy-assignment operator.
15170 ClassDecl->setImplicitMoveAssignmentIsDeleted();
15176 ClassDecl->addDecl(MoveAssignment);
15182 /// with virtual bases. Such a move assignment might move-assign the virtual
15186 assert(!Class->isDependentContext() && "should not define dependent move");
15188 // Only a virtual base could get implicitly move-assigned multiple times.
15189 // Only a non-trivial move assignment can observe this. We only want to
15191 // two base classes, both of which move-assign the same virtual base.
15192 if (Class->getNumVBases() == 0 || Class->hasTrivialMoveAssignment() ||
15193 Class->getNumBases() < 2)
15200 for (auto &BI : Class->bases()) {
15204 CXXRecordDecl *Base = BaseSpec->getType()->getAsCXXRecordDecl();
15206 // If the base has no non-trivial move assignment operators,
15208 if (!Base->hasNonTrivialMoveAssignment())
15212 if (!BaseSpec->isVirtual() && !Base->getNumVBases())
15222 if (!SMOR.getMethod() || SMOR.getMethod()->isTrivial() ||
15223 !SMOR.getMethod()->isMoveAssignmentOperator())
15226 if (BaseSpec->isVirtual()) {
15227 // We're going to move-assign this virtual base, and its move
15233 VBases.insert(std::make_pair(Base->getCanonicalDecl(), &BI))
15234 .first->second;
15238 S.Diag(Existing->getBeginLoc(), diag::note_vbase_moved_here)
15239 << (Base->getCanonicalDecl() ==
15240 Existing->getType()->getAsCXXRecordDecl()->getCanonicalDecl())
15241 << Base << Existing->getType() << Existing->getSourceRange();
15243 << (Base->getCanonicalDecl() ==
15244 BI.getType()->getAsCXXRecordDecl()->getCanonicalDecl())
15245 << Base << BI.getType() << BaseSpec->getSourceRange();
15252 // We assume that any user-provided move assignment operator handles
15253 // the multiple-moves-of-vbase case itself somehow.
15254 if (!SMOR.getMethod()->isDefaulted())
15258 llvm::append_range(Worklist, llvm::make_pointer_range(Base->bases()));
15266 assert((MoveAssignOperator->isDefaulted() &&
15267 MoveAssignOperator->isOverloadedOperator() &&
15268 MoveAssignOperator->getOverloadedOperator() == OO_Equal &&
15269 !MoveAssignOperator->doesThisDeclarationHaveABody() &&
15270 !MoveAssignOperator->isDeleted()) &&
15272 if (MoveAssignOperator->willHaveBody() || MoveAssignOperator->isInvalidDecl())
15275 CXXRecordDecl *ClassDecl = MoveAssignOperator->getParent();
15276 if (ClassDecl->isInvalidDecl()) {
15277 MoveAssignOperator->setInvalidDecl();
15282 // The implicitly-defined or move assignment operator for a non-union class
15285 // base-specifier-list, and then the immediate non-static data members of X
15298 MoveAssignOperator->getType()->castAs<FunctionProtoType>());
15307 ParmVarDecl *Other = MoveAssignOperator->getNonObjectParameter(0);
15309 Other->getType()->castAs<RValueReferenceType>()->getPointeeType();
15311 // Our location for everything implicitly-generated.
15312 SourceLocation Loc = MoveAssignOperator->getEndLoc().isValid()
15313 ? MoveAssignOperator->getEndLoc()
15314 : MoveAssignOperator->getLocation();
15326 if (MoveAssignOperator->isExplicitObjectMemberFunction()) {
15327 ObjectType = MoveAssignOperator->getParamDecl(0)->getType();
15328 if (ObjectType->isReferenceType())
15329 ObjectType = ObjectType->getPointeeType();
15330 ExplicitObject.emplace(MoveAssignOperator->getParamDecl(0), ObjectType);
15341 for (auto &Base : ClassDecl->bases()) {
15344 // are assigned more than once by the implicitly-defined copy assignment
15347 // class. For a move-assignment, this can result in the vbase being moved
15351 // static_cast<Base*>(this)->Base::operator=(static_cast<Base&&>(other));
15353 if (!BaseType->isRecordType()) {
15362 // appropriately-qualified base type.
15365 // Implicitly cast "this" to the appropriately-qualified base type.
15379 MoveAssignOperator->setInvalidDecl();
15387 // Assign non-static members.
15388 for (auto *Field : ClassDecl->fields()) {
15391 if (Field->isUnnamedBitField() || Field->getParent()->isUnion())
15394 if (Field->isInvalidDecl()) {
15400 if (Field->getType()->isReferenceType()) {
15401 Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign)
15402 << Context.getTagDeclType(ClassDecl) << 0 << Field->getDeclName();
15403 Diag(Field->getLocation(), diag::note_declared_at);
15408 // Check for members of const-qualified, non-class type.
15409 QualType BaseType = Context.getBaseElementType(Field->getType());
15410 if (!BaseType->getAs<RecordType>() && BaseType.isConstQualified()) {
15411 Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign)
15412 << Context.getTagDeclType(ClassDecl) << 1 << Field->getDeclName();
15413 Diag(Field->getLocation(), diag::note_declared_at);
15418 // Suppress assigning zero-width bitfields.
15419 if (Field->isZeroLengthBitField(Context))
15422 QualType FieldType = Field->getType().getNonReferenceType();
15423 if (FieldType->isIncompleteArrayType()) {
15424 assert(ClassDecl->hasFlexibleArrayMember() &&
15430 LookupResult MemberLookup(*this, Field->getDeclName(), Loc,
15439 assert(!From.build(*this, Loc)->isLValue() && // could be xvalue or prvalue
15449 MoveAssignOperator->setInvalidDecl();
15472 MoveAssignOperator->setInvalidDecl();
15483 MoveAssignOperator->setBody(Body.getAs<Stmt>());
15484 MoveAssignOperator->markUsed(Context);
15487 L->CompletedImplicitDefinition(MoveAssignOperator);
15496 assert(ClassDecl->needsImplicitCopyConstructor());
15507 bool Const = ClassDecl->implicitCopyConstructorHasConstParam();
15523 SourceLocation ClassLoc = ClassDecl->getLocation();
15526 // An implicitly-declared copy constructor is an inline public
15535 CopyConstructor->setAccess(AS_public);
15536 CopyConstructor->setDefaulted();
15550 if (inTemplateInstantiation() && ClassDecl->isLambda())
15558 CopyConstructor->setParams(FromParam);
15560 CopyConstructor->setTrivial(
15561 ClassDecl->needsOverloadResolutionForCopyConstructor()
15564 : ClassDecl->hasTrivialCopyConstructor());
15566 CopyConstructor->setTrivialForCall(
15567 ClassDecl->hasAttr<TrivialABIAttr>() ||
15568 (ClassDecl->needsOverloadResolutionForCopyConstructor()
15572 : ClassDecl->hasTrivialCopyConstructorForCall()));
15582 ClassDecl->setImplicitCopyConstructorIsDeleted();
15588 ClassDecl->addDecl(CopyConstructor);
15595 assert((CopyConstructor->isDefaulted() &&
15596 CopyConstructor->isCopyConstructor() &&
15597 !CopyConstructor->doesThisDeclarationHaveABody() &&
15598 !CopyConstructor->isDeleted()) &&
15599 "DefineImplicitCopyConstructor - call it for implicit copy ctor");
15600 if (CopyConstructor->willHaveBody() || CopyConstructor->isInvalidDecl())
15603 CXXRecordDecl *ClassDecl = CopyConstructor->getParent();
15604 assert(ClassDecl && "DefineImplicitCopyConstructor - invalid constructor");
15611 CopyConstructor->getType()->castAs<FunctionProtoType>());
15619 // deprecated if the class has a user-declared copy assignment operator
15620 // or a user-declared destructor.
15621 if (getLangOpts().CPlusPlus11 && CopyConstructor->isImplicit())
15625 CopyConstructor->setInvalidDecl();
15627 SourceLocation Loc = CopyConstructor->getEndLoc().isValid()
15628 ? CopyConstructor->getEndLoc()
15629 : CopyConstructor->getLocation();
15631 CopyConstructor->setBody(
15634 CopyConstructor->markUsed(Context);
15638 L->CompletedImplicitDefinition(CopyConstructor);
15644 assert(ClassDecl->needsImplicitMoveConstructor());
15667 SourceLocation ClassLoc = ClassDecl->getLocation();
15671 // An implicitly-declared copy/move constructor is an inline public
15680 MoveConstructor->setAccess(AS_public);
15681 MoveConstructor->setDefaulted();
15697 MoveConstructor->setParams(FromParam);
15699 MoveConstructor->setTrivial(
15700 ClassDecl->needsOverloadResolutionForMoveConstructor()
15703 : ClassDecl->hasTrivialMoveConstructor());
15705 MoveConstructor->setTrivialForCall(
15706 ClassDecl->hasAttr<TrivialABIAttr>() ||
15707 (ClassDecl->needsOverloadResolutionForMoveConstructor()
15711 : ClassDecl->hasTrivialMoveConstructorForCall()));
15721 ClassDecl->setImplicitMoveConstructorIsDeleted();
15727 ClassDecl->addDecl(MoveConstructor);
15734 assert((MoveConstructor->isDefaulted() &&
15735 MoveConstructor->isMoveConstructor() &&
15736 !MoveConstructor->doesThisDeclarationHaveABody() &&
15737 !MoveConstructor->isDeleted()) &&
15738 "DefineImplicitMoveConstructor - call it for implicit move ctor");
15739 if (MoveConstructor->willHaveBody() || MoveConstructor->isInvalidDecl())
15742 CXXRecordDecl *ClassDecl = MoveConstructor->getParent();
15743 assert(ClassDecl && "DefineImplicitMoveConstructor - invalid constructor");
15750 MoveConstructor->getType()->castAs<FunctionProtoType>());
15757 MoveConstructor->setInvalidDecl();
15759 SourceLocation Loc = MoveConstructor->getEndLoc().isValid()
15760 ? MoveConstructor->getEndLoc()
15761 : MoveConstructor->getLocation();
15763 MoveConstructor->setBody(
15766 MoveConstructor->markUsed(Context);
15770 L->CompletedImplicitDefinition(MoveConstructor);
15775 return FD->isDeleted() && FD->isDefaulted() && isa<CXXMethodDecl>(FD);
15782 assert(!Conv->getReturnType()->isUndeducedType());
15784 QualType ConvRT = Conv->getType()->castAs<FunctionType>()->getReturnType();
15786 ConvRT->getPointeeType()->castAs<FunctionType>()->getCallConv();
15788 CXXRecordDecl *Lambda = Conv->getParent();
15789 FunctionDecl *CallOp = Lambda->getLambdaCallOperator();
15791 CallOp->hasCXXExplicitFunctionObjectParameter() || CallOp->isStatic()
15793 : Lambda->getLambdaStaticInvoker(CC);
15795 if (auto *TemplateArgs = Conv->getTemplateSpecializationArgs()) {
15797 CallOp->getDescribedFunctionTemplate(), TemplateArgs, CurrentLocation);
15803 Invoker->getDescribedFunctionTemplate(), TemplateArgs,
15810 if (CallOp->isInvalidDecl())
15815 // For both the conversion and static-invoker template specializations
15824 Invoker->markUsed(Context);
15825 Invoker->setReferenced();
15826 Invoker->setType(Conv->getReturnType()->getPointeeType());
15827 Invoker->setBody(new (Context) CompoundStmt(Conv->getLocation()));
15831 Expr *FunctionRef = BuildDeclRefExpr(Invoker, Invoker->getType(), VK_LValue,
15832 Conv->getLocation());
15834 Stmt *Return = BuildReturnStmt(Conv->getLocation(), FunctionRef).get();
15835 Conv->setBody(CompoundStmt::Create(Context, Return, FPOptionsOverride(),
15836 Conv->getLocation(), Conv->getLocation()));
15837 Conv->markUsed(Context);
15838 Conv->setReferenced();
15841 L->CompletedImplicitDefinition(Conv);
15843 L->CompletedImplicitDefinition(Invoker);
15849 assert(!Conv->getParent()->isGenericLambda());
15853 // Copy-initialize the lambda object as needed to capture it.
15858 Conv->getLocation(),
15867 Context, BuildBlock.get()->getType(), CK_CopyAndAutoreleaseBlockObject,
15872 Conv->setInvalidDecl();
15878 StmtResult Return = BuildReturnStmt(Conv->getLocation(), BuildBlock.get());
15881 Conv->setInvalidDecl();
15887 Conv->setBody(CompoundStmt::Create(Context, ReturnS, FPOptionsOverride(),
15888 Conv->getLocation(), Conv->getLocation()));
15889 Conv->markUsed(Context);
15893 L->CompletedImplicitDefinition(Conv);
15898 /// "real" (non-default) argument.
15905 if (!Args[1]->isDefaultArgument())
15910 return !Args[0]->isDefaultArgument();
15929 // - when a temporary class object that has not been bound to a
15931 // with the same cv-unqualified type, the copy/move operation
15940 Constructor->isCopyOrMoveConstructor() && hasOneRealArgument(ExprArgs)) {
15946 Elidable = SubExpr->isTemporaryObject(
15947 Context, cast<CXXRecordDecl>(FoundDecl->getDeclContext()));
15967 // shadow decl, so we don't need to worry about re-checking the trailing
15979 /// BuildCXXConstructExpr - Creates a complete call to a constructor,
15988 Constructor->getParent(),
15989 DeclInitType->getBaseElementTypeUnsafe()->getAsCXXRecordDecl()) &&
16005 if (VD->isInvalidDecl()) return;
16008 if (VD->getInit() && VD->getInit()->containsErrors())
16011 CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Record->getDecl());
16012 if (ClassDecl->isInvalidDecl()) return;
16013 if (ClassDecl->hasIrrelevantDestructor()) return;
16014 if (ClassDecl->isDependentContext()) return;
16016 if (VD->isNoDestroy(getASTContext()))
16026 // we can skip over this. We still want to emit exit-time destructor warnings
16028 if (!VD->getType()->isArrayType()) {
16029 MarkFunctionReferenced(VD->getLocation(), Destructor);
16030 CheckDestructorAccess(VD->getLocation(), Destructor,
16032 << VD->getDeclName() << VD->getType());
16033 DiagnoseUseOfDecl(Destructor, VD->getLocation());
16036 if (Destructor->isTrivial()) return;
16040 if (Destructor->isConstexpr()) {
16042 if (VD->getInit() && !VD->getInit()->isValueDependent())
16043 HasConstantInit = VD->evaluateValue();
16045 if (!VD->evaluateDestruction(Notes) && VD->isConstexpr() &&
16047 Diag(VD->getLocation(),
16054 if (!VD->hasGlobalStorage() || !VD->needsDestruction(Context))
16057 // Emit warning for non-trivial dtor in global scope (a real global,
16058 // class-static, function-static).
16059 if (!VD->hasAttr<AlwaysDestroyAttr>())
16060 Diag(VD->getLocation(), diag::warn_exit_time_destructor);
16062 // TODO: this should be re-enabled for static locals by !CXAAtExit
16063 if (!VD->isStaticLocal())
16064 Diag(VD->getLocation(), diag::warn_global_destructor);
16077 const auto *Proto = Constructor->getType()->castAs<FunctionProtoType>();
16078 unsigned NumParams = Proto->getNumParams();
16087 Proto->isVariadic() ? VariadicConstructor : VariadicDoesNotApply;
16106 const DeclContext *DC = FnDecl->getDeclContext()->getRedeclContext();
16108 return SemaRef.Diag(FnDecl->getLocation(),
16110 << FnDecl->getDeclName();
16114 FnDecl->getStorageClass() == SC_Static) {
16115 return SemaRef.Diag(FnDecl->getLocation(),
16117 << FnDecl->getDeclName();
16126 Qualifiers PtrQuals = PtrTy->getPointeeType().getQualifiers();
16129 PtrTy->getPointeeType().getUnqualifiedType(), PtrQuals)));
16139 FnDecl->getType()->castAs<FunctionType>()->getReturnType();
16142 // The operator is valid on any address space for OpenCL.
16143 // Drop address space from actual and expected result types.
16144 if (const auto *PtrTy = ResultType->getAs<PointerType>())
16147 if (auto ExpectedPtrTy = ExpectedResultType->getAs<PointerType>())
16154 // required to have a non-dependent result type.
16156 FnDecl->getLocation(),
16157 ResultType->isDependentType()
16160 << FnDecl->getDeclName() << ExpectedResultType;
16164 if (FnDecl->getDescribedFunctionTemplate() && FnDecl->getNumParams() < 2)
16165 return SemaRef.Diag(FnDecl->getLocation(),
16167 << FnDecl->getDeclName();
16170 if (FnDecl->getNumParams() == 0)
16171 return SemaRef.Diag(FnDecl->getLocation(),
16173 << FnDecl->getDeclName();
16175 QualType FirstParamType = FnDecl->getParamDecl(0)->getType();
16177 // The operator is valid on any address space for OpenCL.
16178 // Drop address space from actual and expected first parameter types.
16180 FnDecl->getParamDecl(0)->getType()->getAs<PointerType>())
16183 if (auto ExpectedPtrTy = ExpectedFirstParamType->getAs<PointerType>())
16194 return SemaRef.Diag(FnDecl->getLocation(), FirstParamType->isDependentType()
16197 << FnDecl->getDeclName() << ExpectedFirstParamType;
16206 // A program is ill-formed if an allocation function is declared in a
16226 if (FnDecl->getParamDecl(0)->hasDefaultArg())
16227 return SemaRef.Diag(FnDecl->getLocation(),
16229 << FnDecl->getDeclName() << FnDecl->getParamDecl(0)->getDefaultArgRange();
16237 // A program is ill-formed if deallocation functions are declared in a
16250 MD && MD->isDestroyingOperatorDelete()
16252 SemaRef.Context.getRecordType(MD->getParent())))
16265 if (MD && !MD->getParent()->isDependentContext() &&
16266 MD->isDestroyingOperatorDelete() &&
16268 SemaRef.Diag(MD->getLocation(),
16277 assert(FnDecl && FnDecl->isOverloadedOperator() &&
16280 OverloadedOperatorKind Op = FnDecl->getOverloadedOperator();
16296 // be a non-member function and have at least one parameter
16302 if (MethodDecl->isStatic()) {
16304 Diag(FnDecl->getLocation(),
16310 return Diag(FnDecl->getLocation(), diag::err_operator_overload_static)
16315 for (auto *Param : FnDecl->parameters()) {
16316 QualType ParamType = Param->getType().getNonReferenceType();
16317 if (ParamType->isDependentType() || ParamType->isRecordType() ||
16318 ParamType->isEnumeralType()) {
16325 return Diag(FnDecl->getLocation(),
16327 << FnDecl->getDeclName();
16334 // Only the function-call operator (C++ [over.call]p1) and the subscript
16338 for (auto *Param : FnDecl->parameters()) {
16339 if (Param->hasDefaultArg()) {
16346 Diag(FnDecl->getLocation(), LangOpts.CPlusPlus23
16349 << FnDecl->getDeclName() << 1
16350 << FirstDefaultedParam->getDefaultArgRange();
16352 return Diag(FirstDefaultedParam->getLocation(),
16354 << FnDecl->getDeclName()
16355 << FirstDefaultedParam->getDefaultArgRange();
16375 unsigned NumParams = FnDecl->getNumParams() +
16377 !FnDecl->hasCXXExplicitFunctionObjectParameter()
16387 ErrorKind = 2; // 2 -> unary or binary.
16389 ErrorKind = 0; // 0 -> unary
16392 "All non-call overloaded operators are unary or binary!");
16393 ErrorKind = 1; // 1 -> binary
16395 return Diag(FnDecl->getLocation(), diag::err_operator_overload_must_be)
16396 << FnDecl->getDeclName() << NumParams << ErrorKind;
16400 Diag(FnDecl->getLocation(), LangOpts.CPlusPlus23
16403 << FnDecl->getDeclName() << (NumParams == 1 ? 0 : 2);
16409 FnDecl->getType()->castAs<FunctionProtoType>()->isVariadic()) {
16410 return Diag(FnDecl->getLocation(), diag::err_operator_overload_variadic)
16411 << FnDecl->getDeclName();
16416 return Diag(FnDecl->getLocation(),
16418 << FnDecl->getDeclName();
16422 // The user-defined function called operator++ implements the
16424 // function with no parameters, or a non-member function with one
16428 // int) or a non-member function with two parameters (the second
16432 ParmVarDecl *LastParam = FnDecl->getParamDecl(FnDecl->getNumParams() - 1);
16433 QualType ParamType = LastParam->getType();
16435 if (!ParamType->isSpecificBuiltinType(BuiltinType::Int) &&
16436 !ParamType->isDependentType())
16437 return Diag(LastParam->getLocation(),
16439 << LastParam->getType() << (Op == OO_MinusMinus);
16448 TemplateParameterList *TemplateParams = TpDecl->getTemplateParameters();
16451 if (TemplateParams->size() == 1) {
16453 dyn_cast<NonTypeTemplateParmDecl>(TemplateParams->getParam(0));
16456 if (PmDecl && PmDecl->isTemplateParameterPack() &&
16457 SemaRef.Context.hasSameType(PmDecl->getType(), SemaRef.Context.CharTy))
16462 // whose template-parameter-list comprises a single non-type
16463 // template-parameter of class type.
16468 !PmDecl->isTemplateParameterPack() &&
16469 (PmDecl->getType()->isRecordType() ||
16470 PmDecl->getType()->getAs<DeducedTemplateSpecializationType>()))
16472 } else if (TemplateParams->size() == 2) {
16474 dyn_cast<TemplateTypeParmDecl>(TemplateParams->getParam(0));
16476 dyn_cast<NonTypeTemplateParmDecl>(TemplateParams->getParam(1));
16480 if (PmType && PmArgs && !PmType->isTemplateParameterPack() &&
16481 PmArgs->isTemplateParameterPack()) {
16483 PmArgs->getType()->getAs<TemplateTypeParmType>();
16484 if (TArgs && TArgs->getDepth() == PmType->getDepth() &&
16485 TArgs->getIndex() == PmType->getIndex()) {
16487 SemaRef.Diag(TpDecl->getLocation(),
16494 SemaRef.Diag(TpDecl->getTemplateParameters()->getSourceRange().getBegin(),
16496 << TpDecl->getTemplateParameters()->getSourceRange();
16502 Diag(FnDecl->getLocation(), diag::err_literal_operator_outside_namespace)
16503 << FnDecl->getDeclName();
16507 if (FnDecl->isExternC()) {
16508 Diag(FnDecl->getLocation(), diag::err_literal_operator_extern_c);
16510 FnDecl->getDeclContext()->getExternCContext())
16511 Diag(LSD->getExternLoc(), diag::note_extern_c_begins_here);
16516 FunctionTemplateDecl *TpDecl = FnDecl->getDescribedFunctionTemplate();
16520 TpDecl = FnDecl->getPrimaryTemplate();
16528 if (FnDecl->param_size() != 0) {
16529 Diag(FnDecl->getLocation(),
16537 } else if (FnDecl->param_size() == 1) {
16538 const ParmVarDecl *Param = FnDecl->getParamDecl(0);
16540 QualType ParamType = Param->getType().getUnqualifiedType();
16544 if (ParamType->isSpecificBuiltinType(BuiltinType::ULongLong) ||
16545 ParamType->isSpecificBuiltinType(BuiltinType::LongDouble) ||
16551 } else if (const PointerType *Ptr = ParamType->getAs<PointerType>()) {
16552 QualType InnerType = Ptr->getPointeeType();
16558 Diag(Param->getSourceRange().getBegin(),
16560 << ParamType << "'const char *'" << Param->getSourceRange();
16564 } else if (ParamType->isRealFloatingType()) {
16565 Diag(Param->getSourceRange().getBegin(), diag::err_literal_operator_param)
16566 << ParamType << Context.LongDoubleTy << Param->getSourceRange();
16569 } else if (ParamType->isIntegerType()) {
16570 Diag(Param->getSourceRange().getBegin(), diag::err_literal_operator_param)
16571 << ParamType << Context.UnsignedLongLongTy << Param->getSourceRange();
16575 Diag(Param->getSourceRange().getBegin(),
16577 << ParamType << Param->getSourceRange();
16581 } else if (FnDecl->param_size() == 2) {
16582 FunctionDecl::param_iterator Param = FnDecl->param_begin();
16586 QualType FirstParamType = (*Param)->getType().getUnqualifiedType();
16590 const PointerType *PT = FirstParamType->getAs<PointerType>();
16593 Diag((*Param)->getSourceRange().getBegin(),
16595 << FirstParamType << "'const char *'" << (*Param)->getSourceRange();
16599 QualType PointeeType = PT->getPointeeType();
16602 Diag((*Param)->getSourceRange().getBegin(),
16604 << FirstParamType << "'const char *'" << (*Param)->getSourceRange();
16610 // const char32_t* are allowed as the first parameter to a two-parameter
16617 Diag((*Param)->getSourceRange().getBegin(),
16619 << FirstParamType << "'const char *'" << (*Param)->getSourceRange();
16627 QualType SecondParamType = (*Param)->getType().getUnqualifiedType();
16629 Diag((*Param)->getSourceRange().getBegin(),
16632 << (*Param)->getSourceRange();
16636 Diag(FnDecl->getLocation(), diag::err_literal_operator_bad_param_count);
16642 // A parameter-declaration-clause containing a default argument is not
16644 for (auto *Param : FnDecl->parameters()) {
16645 if (Param->hasDefaultArg()) {
16646 Diag(Param->getDefaultArgRange().getBegin(),
16648 << Param->getDefaultArgRange();
16653 const IdentifierInfo *II = FnDecl->getDeclName().getCXXLiteralIdentifier();
16654 ReservedLiteralSuffixIdStatus Status = II->isReservedLiteralSuffixId();
16656 !getSourceManager().isInSystemHeader(FnDecl->getLocation())) {
16662 Diag(FnDecl->getLocation(), diag::warn_user_literal_reserved)
16664 << StringLiteralParser::isValidUDSuffix(getLangOpts(), II->getName());
16674 assert(Lit->isUnevaluated() && "Unexpected string literal kind");
16676 StringRef Lang = Lit->getString();
16683 Diag(LangStr->getExprLoc(), diag::err_language_linkage_spec_unknown)
16684 << LangStr->getSourceRange();
16691 LangStr->getExprLoc(), Language,
16695 /// - Otherwise, if the declaration
16696 /// - ...
16697 /// - ...
16698 /// - appears within a linkage-specification,
16705 D->setLocalOwningModule(GlobalModule);
16708 CurContext->addDecl(D);
16718 LSDecl->setRBraceLoc(RBraceLoc);
16725 getCurrentModule()->isImplicitGlobalModule() &&
16726 getCurrentModule()->Parent)
16741 CurContext->addDecl(ED);
16750 QualType ExDeclType = TInfo->getType();
16753 if (ExDeclType->isArrayType())
16755 else if (ExDeclType->isFunctionType())
16758 // C++ 15.3p1: The exception-declaration shall not denote an incomplete type.
16759 // The exception-declaration shall not denote a pointer or reference to an
16762 if (!ExDeclType->isDependentType() && ExDeclType->isRValueReferenceType()) {
16767 if (ExDeclType->isVariablyModifiedType()) {
16775 if (const PointerType *Ptr = BaseType->getAs<PointerType>()) {
16776 BaseType = Ptr->getPointeeType();
16779 } else if (const ReferenceType *Ref = BaseType->getAs<ReferenceType>()) {
16781 BaseType = Ref->getPointeeType();
16785 if (!Invalid && (Mode == 0 || !BaseType->isVoidType()) &&
16786 !BaseType->isDependentType() && RequireCompleteType(Loc, BaseType, DK))
16794 if (!Invalid && Mode != 1 && BaseType->isSizelessType()) {
16799 if (!Invalid && !ExDeclType->isDependentType() &&
16805 // Only the non-fragile NeXT runtime currently supports C++ catches
16809 if (const ReferenceType *RT = T->getAs<ReferenceType>())
16810 T = RT->getPointeeType();
16812 if (T->isObjCObjectType()) {
16815 } else if (T->isObjCObjectPointerType()) {
16816 // FIXME: should this be a test for macosx-fragile specifically?
16824 ExDecl->setExceptionVariable(true);
16830 if (!Invalid && !ExDeclType->isDependentType()) {
16831 if (const RecordType *recordType = ExDeclType->getAs<RecordType>()) {
16837 // The object declared in an exception-declaration or, if the
16838 // exception-declaration does not specify a name, a temporary (12.2) is
16839 // copy-initialized (8.5) from the exception object. [...]
16859 // If the constructor used was non-trivial, set this as the
16862 if (!construct->getConstructor()->isTrivial()) {
16864 ExDecl->setInit(init);
16874 ExDecl->setInvalidDecl();
16897 // a function-try-block's catch statement.
16898 assert(!S->isDeclScope(PrevDecl));
16902 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
16904 } else if (PrevDecl->isTemplateParameter())
16918 ExDecl->setInvalidDecl();
16924 CurContext->addDecl(ExDecl);
16960 llvm_unreachable("Non-character type");
16965 /// The value needs to be zero-extended to 32-bits.
16972 BuiltinType::Kind K = BTy->getKind();
16993 EscapeStringForDiagnostic(StringRef(Arr, Ptr - Arr), Str);
17000 llvm_unreachable("Non-character type is passed");
17014 if (T->isBooleanType()) {
17027 const auto *BTy = T->getAs<BuiltinType>();
17029 switch (BTy->getKind()) {
17040 WriteCharTypePrefix(BTy->getKind(), OS);
17097 /// before such as int-valued template parameters.
17099 E = E->IgnoreParenImpCasts();
17110 // -5 is also simple to understand.
17112 return UsefulToPrintExpr(UnaryOp->getSubExpr());
17116 return (BO->isShiftOp() || BO->isAdditiveOp() || BO->isMultiplicativeOp() ||
17117 BO->isBitwiseOp());
17124 Op && Op->getOpcode() != BO_LOr) {
17125 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
17126 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
17129 if ((isa<CXXBoolLiteralExpr>(LHS) && RHS->getType()->isBooleanType()) ||
17130 (isa<CXXBoolLiteralExpr>(RHS) && LHS->getType()->isBooleanType()))
17147 Side->EvaluateAsRValue(DiagSide[I].Result, Context, true);
17150 ConvertAPValueToString(DiagSide[I].Result.Val, Side->getType(),
17154 Diag(Op->getExprLoc(), diag::note_expr_evaluates_to)
17155 << DiagSide[0].ValueString << Op->getOpcodeStr()
17156 << DiagSide[1].ValueString << Op->getSourceRange();
17166 assert(!Message->isTypeDependent() && !Message->isValueDependent() &&
17170 assert(SL->isUnevaluated() && "expected an unevaluated string");
17171 Result.assign(SL->getString().begin(), SL->getString().end());
17175 SourceLocation Loc = Message->getBeginLoc();
17176 QualType T = Message->getType().getNonReferenceType();
17177 auto *RD = T->getAsCXXRecordDecl();
17184 bool Diag = false) -> std::optional<LookupResult> {
17217 Message, Message->getType(), Message->getBeginLoc(), false,
17225 if (Res.get()->isTypeDependent() || Res.get()->isValueDependent())
17263 if (!Message->EvaluateCharRangeAsString(Result, EvaluatedSize.get(),
17266 Diag(Message->getBeginLoc(),
17280 assert(AssertExpr != nullptr && "Expected non-null condition");
17281 if (!AssertExpr->isTypeDependent() && !AssertExpr->isValueDependent() &&
17282 (!AssertMessage || (!AssertMessage->isTypeDependent() &&
17283 !AssertMessage->isValueDependent())) &&
17285 // In a static_assert-declaration, the constant-expression shall be a
17329 getLangOpts().CPlusPlus && CurContext->isDependentContext();
17350 Diag(AssertExpr->getBeginLoc(), diag::err_static_assert_failed)
17351 << !HasMessage << Msg.str() << AssertExpr->getSourceRange();
17357 Diag(InnerCond->getBeginLoc(),
17360 << InnerCond->getSourceRange();
17363 Diag(AssertExpr->getBeginLoc(), diag::err_static_assert_failed)
17364 << !HasMessage << Msg.str() << AssertExpr->getSourceRange();
17383 CurContext->addDecl(Decl);
17400 if (TemplateParams->size() > 0) {
17408 FriendLoc, TempParamLists.size() - 1,
17413 Diag(TemplateParams->getTemplateLoc(), diag::err_template_tag_noparams)
17422 for (unsigned I = TempParamLists.size(); I-- > 0; ) {
17423 if (TempParamLists[I]->size()) {
17432 // about the template header and build an appropriate non-templated
17460 TSI->getTypeLoc().castAs<DependentNameTypeLoc>();
17465 ElaboratedTypeLoc TL = TSI->getTypeLoc().castAs<ElaboratedTypeLoc>();
17473 Friend->setAccess(AS_public);
17474 CurContext->addDecl(Friend);
17482 // Handle the case of a templated-scope friend class. e.g.
17490 DependentNameTypeLoc TL = TSI->getTypeLoc().castAs<DependentNameTypeLoc>();
17497 Friend->setAccess(AS_public);
17498 Friend->setUnsupportedFriend(true);
17499 CurContext->addDecl(Friend);
17514 // friend elaborated-type-specifier ;
17515 // friend simple-type-specifier ;
17516 // friend typename-specifier ;
17541 QualType T = TSI->getType();
17548 if (!T->isElaboratedTypeSpecifier()) {
17551 // In a simple-declaration, the optional init-declarator-list can be
17553 // the decl-specifier-seq contains either a class-specifier, an
17554 // elaborated-type-specifier with a class-key, or an enum-specifier.
17556 // The declaration of a template-declaration or explicit-specialization
17557 // is never a member-declaration, so this must be a simple-declaration
17558 // with no init-declarator-list. Therefore, this is ill-formed.
17561 } else if (const RecordDecl *RD = T->getAsRecordDecl()) {
17563 InsertionText += RD->getKindName();
17568 << (unsigned)RD->getTagKind() << T
17584 // thus we never diagnose it, not even in -pedantic.
17595 D = FriendDecl::Create(Context, CurContext, TSI->getTypeLoc().getBeginLoc(),
17601 D->setAccess(AS_public);
17602 CurContext->addDecl(D);
17623 // type dependent on a template-parameter and this causes
17626 // is ill-formed.
17627 if (!TInfo->getType()->isFunctionType()) {
17636 // - If a friend declaration in a non-local class first declares a
17639 // - The name of the friend is not found by simple name lookup
17643 // - If a friend function is called, its name may be found by the
17646 // - When looking for a prior declaration of a class or a function
17670 // - There's no scope specifier and we're in a local class. Only look
17671 // for functions declared in the immediately-enclosing block scope.
17676 cast<CXXRecordDecl>(CurContext)->isLocalClass())) {
17678 // If a friend declaration appears in a local class and the name
17681 // innermost enclosing non-class scope. For a friend function
17683 // ill-formed.
17685 // Find the innermost enclosing non-class scope. This is the block
17686 // scope containing the local class definition (or for a nested class,
17687 // the outer local class).
17688 DCScope = S->getFnParent();
17697 // one of the enclosing local classes.
17698 DC = Previous.getRepresentativeDecl()->getDeclContext();
17700 // This is ill-formed, but provide the context that we would have
17706 // - There's no scope specifier, in which case we just go to the
17712 // a template-id and the declaration is a function or an
17713 // elaborated-type-specifier, the lookup to determine whether
17721 // for this behavior, that would be nice --- it's what GCC and
17727 while (DC->isRecord())
17728 DC = DC->getParent();
17730 DeclContext *LookupDC = DC->getNonTransparentContext();
17742 if (LookupDC->isFileContext()) break;
17744 LookupDC = LookupDC->getParent();
17749 // - There's a non-dependent scope specifier, in which case we
17752 } else if (!SS.getScopeRep()->isDependent()) {
17762 if (DC->Equals(CurContext))
17768 // - There's a scope specifier that does not match any template
17771 // - There's a scope specifier that does match some template
17778 if (!DC->isRecord()) {
17779 int DiagArg = -1;
17809 // does not contain the declaration context, i.e., in an out-of-line
17822 assert(ND->getLexicalDeclContext() == CurContext);
17826 DC = ND->getDeclContext();
17832 // Also update the scope-based lookup if the target context's
17834 if (!CurContext->isDependentContext()) {
17835 DC = DC->getRedeclContext();
17836 DC->makeDeclVisibleInContext(ND);
17844 FrD->setAccess(AS_public);
17845 CurContext->addDecl(FrD);
17847 if (ND->isInvalidDecl()) {
17848 FrD->setInvalidDecl();
17850 if (DC->isRecord()) CheckFriendAccess(ND);
17854 FD = FTD->getTemplatedDecl();
17860 // only if the class is a non-local class, and the function name is
17872 if (DC->isFileContext())
17875 // Friend function defined in a local class.
17879 // Per [basic.pre]p4, a template-id is not a name. Therefore, if we have
17880 // a template-id, the function name is not unqualified because these is
17881 // no name. While the wording requires some reading in-between the
17895 // We can't look at FD->getPreviousDecl() because it may not have been set
17899 Diag(FD->getLocation(), diag::err_friend_decl_with_def_arg_redeclared);
17900 Diag(Previous.getRepresentativeDecl()->getLocation(),
17903 Diag(FD->getLocation(), diag::err_friend_decl_with_def_arg_must_be_def);
17906 // Mark templated-scope function declarations as unsupported.
17907 if (FD->getNumTemplateParameterLists() && SS.isValid()) {
17908 Diag(FD->getLocation(), diag::warn_template_qualified_friend_unsupported)
17911 FrD->setUnsupportedFriend(true);
17931 Fn->setWillHaveBody(false);
17933 if (const FunctionDecl *Prev = Fn->getPreviousDecl()) {
17936 if ((Prev->getTemplateSpecializationKind() != TSK_ExplicitSpecialization ||
17937 Prev->getPreviousDecl()) &&
17938 !Prev->isDefined()) {
17940 Diag(Prev->getLocation().isInvalid() ? DelLoc : Prev->getLocation(),
17941 Prev->isImplicit() ? diag::note_previous_implicit_declaration
17945 Fn->setInvalidDecl();
17950 // declaration, mark the implicitly-instantiated declaration of the
17951 // explicitly-specialized function as deleted instead of marking the
17953 Fn = Fn->getCanonicalDecl();
17958 Diag(Fn->getLocation(), diag::err_attribute_dll_deleted) << DLLAttr;
17959 Fn->setInvalidDecl();
17963 // A program that defines main as deleted [...] is ill-formed.
17964 if (Fn->isMain())
17969 Fn->setImplicitlyInline();
17970 Fn->setDeletedAsWritten(true, Message);
17974 if (!Dcl || Dcl->isInvalidDecl())
17980 if (getDefaultedFunctionKind(FTD->getTemplatedDecl()).isComparison()) {
17997 (!FD->isDependentContext() ||
17999 FD->getDeclName().getCXXOverloadedOperator() != OO_Equal))) {
18014 FD->setDefaulted();
18015 FD->setExplicitlyDefaulted();
18016 FD->setDefaultLoc(DefaultLoc);
18019 if (FD->isDependentContext())
18025 FD->setWillHaveBody(false);
18030 if (auto const *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalDeclContext()))
18031 if (!RD->isCompleteDefinition())
18040 if (const FunctionDecl *Pattern = FD->getTemplateInstantiationPattern())
18044 if (Primary->getCanonicalDecl()->isDefaulted())
18050 FD->setInvalidDecl();
18058 MD->setInvalidDecl();
18065 for (Stmt *SubStmt : S->children()) {
18069 Self.Diag(SubStmt->getBeginLoc(),
18077 for (unsigned I = 0, E = TryBlock->getNumHandlers(); I != E; ++I) {
18078 CXXCatchStmt *Handler = TryBlock->getHandler(I);
18100 const auto *NewFT = New->getType()->castAs<FunctionProtoType>();
18101 const auto *OldFT = Old->getType()->castAs<FunctionProtoType>();
18103 if (OldFT->hasExtParameterInfos()) {
18104 for (unsigned I = 0, E = OldFT->getNumParams(); I != E; ++I)
18107 if (OldFT->getExtParameterInfo(I).isNoEscape() &&
18108 !NewFT->getExtParameterInfo(I).isNoEscape()) {
18109 Diag(New->getParamDecl(I)->getLocation(),
18111 Diag(Old->getParamDecl(I)->getLocation(),
18117 if (IsInvalidSMECallConversion(Old->getType(), New->getType())) {
18118 Diag(New->getLocation(), diag::err_conflicting_overriding_attributes)
18119 << New << New->getType() << Old->getType();
18120 Diag(Old->getLocation(), diag::note_overridden_virtual_function);
18125 const auto *OldCSA = Old->getAttr<CodeSegAttr>();
18126 const auto *NewCSA = New->getAttr<CodeSegAttr>();
18128 (!OldCSA || !NewCSA || NewCSA->getName() != OldCSA->getName())) {
18129 Diag(New->getLocation(), diag::err_mismatched_code_seg_override);
18130 Diag(Old->getLocation(), diag::note_previous_declaration);
18136 const auto OldFX = Old->getFunctionEffects();
18137 const auto NewFXOrig = New->getFunctionEffects();
18148 Diag(New->getLocation(), diag::warn_mismatched_func_effect_override)
18150 Diag(Old->getLocation(), diag::note_overridden_virtual_function)
18151 << Old->getReturnTypeSourceRange();
18155 const auto *NewFT = New->getType()->castAs<FunctionProtoType>();
18156 FunctionProtoType::ExtProtoInfo EPI = NewFT->getExtProtoInfo();
18158 QualType ModQT = Context.getFunctionType(NewFT->getReturnType(),
18159 NewFT->getParamTypes(), EPI);
18160 New->setType(ModQT);
18166 diagnoseFunctionEffectMergeConflicts(Errs, New->getLocation(),
18167 Old->getLocation());
18171 CallingConv NewCC = NewFT->getCallConv(), OldCC = OldFT->getCallConv();
18181 if (New->getStorageClass() == SC_Static)
18184 Diag(New->getLocation(),
18186 << New->getDeclName() << New->getType() << Old->getType();
18187 Diag(Old->getLocation(), diag::note_overridden_virtual_function);
18195 if (!New->isExplicitObjectMemberFunction())
18197 Diag(New->getParamDecl(0)->getBeginLoc(),
18199 << New->getSourceRange() << /*virtual*/ 1 << /*IsLambda*/ false;
18200 Diag(Old->getLocation(), diag::note_overridden_virtual_function);
18201 New->setInvalidDecl();
18207 QualType NewTy = New->getType()->castAs<FunctionType>()->getReturnType();
18208 QualType OldTy = Old->getType()->castAs<FunctionType>()->getReturnType();
18211 NewTy->isDependentType() || OldTy->isDependentType())
18218 if (const PointerType *NewPT = NewTy->getAs<PointerType>()) {
18219 if (const PointerType *OldPT = OldTy->getAs<PointerType>()) {
18220 NewClassTy = NewPT->getPointeeType();
18221 OldClassTy = OldPT->getPointeeType();
18223 } else if (const ReferenceType *NewRT = NewTy->getAs<ReferenceType>()) {
18224 if (const ReferenceType *OldRT = OldTy->getAs<ReferenceType>()) {
18225 if (NewRT->getTypeClass() == OldRT->getTypeClass()) {
18226 NewClassTy = NewRT->getPointeeType();
18227 OldClassTy = OldRT->getPointeeType();
18234 Diag(New->getLocation(),
18236 << New->getDeclName() << NewTy << OldTy
18237 << New->getReturnTypeSourceRange();
18238 Diag(Old->getLocation(), diag::note_overridden_virtual_function)
18239 << Old->getReturnTypeSourceRange();
18250 if (const RecordType *RT = NewClassTy->getAs<RecordType>()) {
18251 if (!RT->isBeingDefined() &&
18252 RequireCompleteType(New->getLocation(), NewClassTy,
18254 New->getDeclName()))
18259 if (!IsDerivedFrom(New->getLocation(), NewClassTy, OldClassTy)) {
18260 Diag(New->getLocation(), diag::err_covariant_return_not_derived)
18261 << New->getDeclName() << NewTy << OldTy
18262 << New->getReturnTypeSourceRange();
18263 Diag(Old->getLocation(), diag::note_overridden_virtual_function)
18264 << Old->getReturnTypeSourceRange();
18273 New->getLocation(), New->getReturnTypeSourceRange(),
18274 New->getDeclName(), nullptr)) {
18279 Diag(Old->getLocation(), diag::note_overridden_virtual_function)
18280 << Old->getReturnTypeSourceRange();
18287 Diag(New->getLocation(),
18289 << New->getDeclName() << NewTy << OldTy
18290 << New->getReturnTypeSourceRange();
18291 Diag(Old->getLocation(), diag::note_overridden_virtual_function)
18292 << Old->getReturnTypeSourceRange();
18299 Diag(New->getLocation(),
18301 << New->getDeclName() << NewTy << OldTy
18302 << New->getReturnTypeSourceRange();
18303 Diag(Old->getLocation(), diag::note_overridden_virtual_function)
18304 << Old->getReturnTypeSourceRange();
18314 Method->setRangeEnd(EndLoc);
18316 if (Method->isVirtual() || Method->getParent()->isDependentContext()) {
18317 Method->setIsPureVirtual();
18321 if (!Method->isInvalidDecl())
18322 Diag(Method->getLocation(), diag::err_non_virtual_pure)
18323 << Method->getDeclName() << InitRange;
18328 if (D->getFriendObjectKind())
18329 Diag(D->getLocation(), diag::err_pure_friend);
18333 Diag(D->getLocation(), diag::err_illegal_initializer);
18344 assert(D && !D->isInvalidDecl());
18350 if (S && D->isOutOfLine())
18351 EnterDeclaratorContext(S, D->getDeclContext());
18360 if (S && D->isOutOfLine())
18364 // An expression or conversion is 'manifestly constant-evaluated' if it is:
18366 // - the initializer of a variable that is usable in constant expressions or
18369 VD && (VD->isUsableInConstantExpressions(Context) ||
18370 VD->hasConstantInitialization())) {
18374 // - it is a subexpression of a manifestly constant-evaluated expression
18392 // The type-specifier-seq shall not contain typedef and shall not declare a
18402 Diag(Dcl->getLocation(), diag::err_invalid_use_of_function_type)
18408 VD->setCXXCondDecl();
18418 ExternalSource->ReadUsedVTables(VTables);
18425 if (!Pos->second && VTables[I].DefinitionRequired)
18426 Pos->second = true;
18441 if (!Class->isDynamicClass() || Class->isDependentContext() ||
18442 CurContext->isDependentContext() || isUnevaluatedContext())
18456 Class = Class->getCanonicalDecl();
18463 if (DefinitionRequired && !Pos.first->second) {
18464 Pos.first->second = true;
18475 CXXDestructorDecl *DD = Class->getDestructor();
18476 if (DD && DD->isVirtual() && !DD->isDeleted()) {
18477 if (Class->hasUserDeclaredDestructor() && !DD->isDefined()) {
18478 // If this is an out-of-line declaration, marking it referenced will
18484 MarkFunctionReferenced(Loc, Class->getDestructor());
18490 // Local classes need to have their virtual members marked
18493 if (Class->isLocalClass())
18494 MarkVirtualMembersReferenced(Loc, Class->getDefinition());
18510 CXXRecordDecl *Class = VTableUses[I].first->getDefinition();
18514 Class->getTemplateSpecializationKind();
18521 // V-tables for non-template classes with an owning module are always
18523 if (Class->isInCurrentModuleUnit()) {
18525 } else if (KeyFunction && !KeyFunction->hasBody()) {
18532 KeyFunction->getTemplateSpecializationKind();
18544 for (auto *R : Class->redecls()) {
18546 = cast<CXXRecordDecl>(R)->getTemplateSpecializationKind();
18572 CXXRecordDecl *Canonical = Class->getCanonicalDecl();
18573 if (VTablesUsed[Canonical] && !Class->shouldEmitInExternalSource())
18580 Class->isExternallyVisible() && ClassTSK != TSK_ImplicitInstantiation &&
18583 if (!KeyFunction || (KeyFunction->hasBody(KeyFunctionDef) &&
18584 KeyFunctionDef->isInlined()))
18585 Diag(Class->getLocation(), diag::warn_weak_vtable) << Class;
18595 for (const auto *I : RD->methods())
18596 if (I->isVirtual() && !I->isPureVirtual())
18597 ResolveExceptionSpec(Loc, I->getType()->castAs<FunctionProtoType>());
18605 RD->getFinalOverriders(FinalOverriders);
18609 for (OverridingMethods::const_iterator OI = I->second.begin(),
18610 OE = I->second.end();
18612 assert(OI->second.size() > 0 && "no final overrider");
18613 CXXMethodDecl *Overrider = OI->second.front().Method;
18617 if (!Overrider->isPureVirtual() &&
18618 (!ConstexprOnly || Overrider->isConstexpr()))
18624 if (RD->getNumVBases() == 0)
18627 for (const auto &I : RD->bases()) {
18629 cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl());
18630 if (Base->getNumVBases() == 0)
18642 if (Ctor->isInvalidDecl())
18645 CXXConstructorDecl *Target = Ctor->getTargetConstructor();
18651 (void)Target->hasBody(FNTarget);
18656 CXXConstructorDecl *Canonical = Ctor->getCanonicalDecl(),
18658 *TCanonical = Target? Target->getCanonicalDecl() : nullptr;
18664 if (!Target || !Target->isDelegatingConstructor() ||
18665 Target->isInvalidDecl() || Valid.count(TCanonical)) {
18673 S.Diag((*Ctor->init_begin())->getSourceLocation(),
18679 S.Diag(Target->getLocation(), diag::note_it_delegates_to);
18682 while (C->getCanonicalDecl() != Canonical) {
18684 (void)C->getTargetConstructor()->hasBody(FNTarget);
18689 S.Diag(C->getLocation(), diag::note_which_delegates_to);
18711 (*CI)->setInvalidDecl();
18723 S.Diag(E->getLocation(), diag::err_this_static_member_func)
18724 << E->isImplicit();
18731 TypeSourceInfo *TSInfo = Method->getTypeSourceInfo();
18735 TypeLoc TL = TSInfo->getTypeLoc();
18742 // cv-qualifier-seq and it shall not appear within the declaration of a
18744 // within a static member function as they are within a non-static member
18746 // until the complete declarator is known. - end note ]
18750 // If the return type came after the cv-qualifier-seq, check it now.
18751 if (Proto->hasTrailingReturn() &&
18760 if (Expr *E = Method->getTrailingRequiresClause())
18768 TypeSourceInfo *TSInfo = Method->getTypeSourceInfo();
18772 TypeLoc TL = TSInfo->getTypeLoc();
18780 switch (Proto->getExceptionSpecType()) {
18794 if (!Finder.TraverseStmt(Proto->getNoexceptExpr()))
18799 for (const auto &E : Proto->exceptions()) {
18813 for (const auto *A : Method->attrs()) {
18818 Arg = G->getArg();
18820 Arg = G->getArg();
18822 Args = llvm::ArrayRef(AA->args_begin(), AA->args_size());
18824 Args = llvm::ArrayRef(AB->args_begin(), AB->args_size());
18826 Arg = ETLF->getSuccessValue();
18827 Args = llvm::ArrayRef(ETLF->args_begin(), ETLF->args_size());
18829 Arg = STLF->getSuccessValue();
18830 Args = llvm::ArrayRef(STLF->args_begin(), STLF->args_size());
18832 Arg = LR->getArg();
18834 Args = llvm::ArrayRef(LE->args_begin(), LE->args_size());
18836 Args = llvm::ArrayRef(RC->args_begin(), RC->args_size());
18838 Args = llvm::ArrayRef(AC->args_begin(), AC->args_size());
18840 Args = llvm::ArrayRef(AC->args_begin(), AC->args_size());
18842 Args = llvm::ArrayRef(RC->args_begin(), RC->args_size());
18891 assert((NoexceptExpr->isTypeDependent() ||
18892 NoexceptExpr->getType()->getCanonicalTypeUnqualified() ==
18914 D = FTD->getTemplatedDecl();
18931 if (MD->isStatic())
18934 if (MD->isVirtual()) {
18936 for (const CXXMethodDecl *O : MD->overridden_methods())
18942 /// HandleMSProperty - Analyze a __delcspec(property) field of a C++ class.
18958 QualType T = TInfo->getType();
19001 if (PrevDecl && PrevDecl->isTemplateParameter()) {
19017 NewPD->setAccess(AS);
19019 if (NewPD->isInvalidDecl())
19020 Record->setInvalidDecl();
19023 NewPD->setModulePrivate();
19025 if (NewPD->isInvalidDecl() && PrevDecl) {
19031 Record->addDecl(NewPD);
19051 // An abbreviated function template can have a template-head. The invented
19052 // template-parameters are appended to the template-parameter-list after
19053 // the explicitly declared template-parameters.
19055 // A template-head must have one or more template-parameters (read:
19056 // 'template<>' is *not* a template-head). Only append the invented
19057 // template parameters if we matched the nested-name-specifier to a non-empty
19059 if (ExplicitParams && !ExplicitParams->empty()) {
19060 Info.AutoTemplateParameterDepth = ExplicitParams->getDepth();
19062 Info.NumExplicitTemplateParams = ExplicitParams->size();
19077 Context, ExplicitParams->getTemplateLoc(),
19078 ExplicitParams->getLAngleLoc(), FSI.TemplateParams,
19079 ExplicitParams->getRAngleLoc(),
19080 ExplicitParams->getRequiresClause()));