Lines Matching +full:fsi +full:- +full:attached

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