• Home
  • Raw
  • Download

Lines Matching +full:exempt +full:- +full:issue +full:- +full:label

1 //===--- SemaDecl.cpp - Semantic Analysis for Declarations ----------------===//
8 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
81 (AllowInvalidDecl || !ND->isInvalidDecl()); in ValidateCandidate()
94 /// \brief Determine whether the token kind starts a simple-type-specifier.
149 if (!RD->hasDefinition()) in lookupUnqualifiedTypeNameInBase()
154 for (const auto &Base : RD->bases()) { in lookupUnqualifiedTypeNameInBase()
156 if (auto *BaseTT = Base.getType()->getAs<TagType>()) in lookupUnqualifiedTypeNameInBase()
157 BaseRD = BaseTT->getAsCXXRecordDecl(); in lookupUnqualifiedTypeNameInBase()
158 else if (auto *TST = Base.getType()->getAs<TemplateSpecializationType>()) { in lookupUnqualifiedTypeNameInBase()
161 if (!TST || !TST->isDependentType()) in lookupUnqualifiedTypeNameInBase()
163 auto *TD = TST->getTemplateName().getAsTemplateDecl(); in lookupUnqualifiedTypeNameInBase()
167 dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl())) { in lookupUnqualifiedTypeNameInBase()
168 if (BasePrimaryTemplate->getCanonicalDecl() != RD->getCanonicalDecl()) in lookupUnqualifiedTypeNameInBase()
172 CTD->findPartialSpecialization(Base.getType())) in lookupUnqualifiedTypeNameInBase()
173 if (PS->getCanonicalDecl() != RD->getCanonicalDecl()) in lookupUnqualifiedTypeNameInBase()
179 for (NamedDecl *ND : BaseRD->lookup(&II)) { in lookupUnqualifiedTypeNameInBase()
210 DC = DC->getParent()) { in recoverFromTypeInKnownDependentBase()
214 if (RD && RD->getDescribedClassTemplate()) in recoverFromTypeInKnownDependentBase()
260 if (ObjectType->isRecordType()) in getTypeName()
262 } else if (SS && SS->isNotEmpty()) { in getTypeName()
268 // A qualified-id that refers to a type and in which the in getTypeName()
269 // nested-name-specifier depends on a template-parameter (14.6.2) in getTypeName()
271 // qualified-id denotes a type, forming an in getTypeName()
272 // elaborated-type-specifier (7.1.5.3). in getTypeName()
284 NestedNameSpecifierLoc QualifierLoc = SS->getWithLocInContext(Context); in getTypeName()
293 if (!LookupCtx->isDependentContext() && in getTypeName()
299 // lookup for class-names. in getTypeName()
307 // nested-name-specifier. in getTypeName()
312 // If the unqualified-id is ~type-name, the type-name is looked up in getTypeName()
313 // in the context of the entire postfix-expression. If the type T of in getTypeName()
314 // the object expression is of a class type C, the type-name is also in getTypeName()
316 // find a name that refers to (possibly cv-qualified) T. in getTypeName()
325 if (Result.empty() && getLangOpts().MSVCCompat && (!SS || SS->isEmpty())) { in getTypeName()
353 // Ignore a correction to a template type as the to-be-corrected in getTypeName()
368 SS->MakeTrivial(Context, NNS, SourceRange(NameLoc)); in getTypeName()
381 // Recover from type-hiding ambiguities by hiding the type. We'll in getTypeName()
396 (*Res)->getLocation().getRawEncoding() < in getTypeName()
397 IIDecl->getLocation().getRawEncoding()) in getTypeName()
431 MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false); in getTypeName()
436 if (SS && SS->isNotEmpty() && !IsCtorOrDtorName) { in getTypeName()
438 // Construct a type with type-source information. in getTypeName()
445 ElabTL.setQualifierLoc(SS->getWithLocInContext(Context)); in getTypeName()
468 for (;; DC = DC->getLookupParent()) { in synthesizeCurrentNestedNameSpecifier()
469 DC = DC->getPrimaryContext(); in synthesizeCurrentNestedNameSpecifier()
471 if (ND && !ND->isInline() && !ND->isAnonymousNamespace()) in synthesizeCurrentNestedNameSpecifier()
474 return NestedNameSpecifier::Create(Context, nullptr, RD->isTemplateDecl(), in synthesizeCurrentNestedNameSpecifier()
475 RD->getTypeForDecl()); in synthesizeCurrentNestedNameSpecifier()
484 /// up allowing unqualified dependent type names at class-level, which MSVC
488 for (; DC && DC->isDependentContext(); DC = DC->getLookupParent()) { in findRecordWithDependentBasesOfEnclosingMethod()
489 DC = DC->getPrimaryContext(); in findRecordWithDependentBasesOfEnclosingMethod()
491 if (MD->getParent()->hasAnyDependentBases()) in findRecordWithDependentBasesOfEnclosingMethod()
492 return MD->getParent(); in findRecordWithDependentBasesOfEnclosingMethod()
500 assert(getLangOpts().MSVCCompat && "shouldn't be called in non-MSVC mode"); in ActOnMSVCUnknownTypeName()
503 if (IsTemplateTypeArg && getCurScope()->isTemplateParamScope()) { in ActOnMSVCUnknownTypeName()
505 // until instantiation time by making a non-dependent DependentTypeName. We in ActOnMSVCUnknownTypeName()
517 NNS = NestedNameSpecifier::Create(Context, nullptr, RD->isTemplateDecl(), in ActOnMSVCUnknownTypeName()
518 RD->getTypeForDecl()); in ActOnMSVCUnknownTypeName()
545 /// isTagName() - This method is called *for error recovery purposes only*
557 switch (TD->getTagKind()) { in isTagName()
569 /// isMicrosoftMissingTypename - In Microsoft mode, within class scope,
584 if (CurContext->isRecord()) { in isMicrosoftMissingTypename()
585 if (SS->getScopeRep()->getKind() == NestedNameSpecifier::Super) in isMicrosoftMissingTypename()
588 const Type *Ty = SS->getScopeRep()->getAsType(); in isMicrosoftMissingTypename()
591 for (const auto &Base : RD->bases()) in isMicrosoftMissingTypename()
594 return S->isFunctionPrototypeScope(); in isMicrosoftMissingTypename()
596 return CurContext->isFunctionOrMethod() || S->isFunctionPrototypeScope(); in isMicrosoftMissingTypename()
620 // We found a similarly-named type or interface; suggest that. in DiagnoseUnknownTypeName()
621 if (!SS || !SS->isSet()) { in DiagnoseUnknownTypeName()
627 II->getName().equals(CorrectedStr); in DiagnoseUnknownTypeName()
630 << II << DC << DroppedSpecifier << SS->getRange()); in DiagnoseUnknownTypeName()
661 Diag(TplDecl->getLocation(), diag::note_template_decl_here) in DiagnoseUnknownTypeName()
662 << TplDecl->getTemplateParameters()->getSourceRange(); in DiagnoseUnknownTypeName()
671 if (!SS || (!SS->isSet() && !SS->isInvalid())) in DiagnoseUnknownTypeName()
675 << II << DC << SS->getRange(); in DiagnoseUnknownTypeName()
681 Diag(SS->getRange().getBegin(), DiagID) in DiagnoseUnknownTypeName()
682 << SS->getScopeRep() << II->getName() in DiagnoseUnknownTypeName()
683 << SourceRange(SS->getRange().getBegin(), IILoc) in DiagnoseUnknownTypeName()
684 << FixItHint::CreateInsertion(SS->getRange().getBegin(), "typename "); in DiagnoseUnknownTypeName()
688 assert(SS && SS->isInvalid() && in DiagnoseUnknownTypeName()
718 switch (Tag->getTagKind()) { in isTagTypeWithMissingTag()
747 SemaRef.Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type) in isTagTypeWithMissingTag()
759 /// Build a ParsedType for a simple-type-specifier with a nested-name-specifier.
798 // Perform lookup for Objective-C instance variables (including automatically in ClassifyName()
799 // synthesized instance variables), if we're in an Objective-C method. in ClassifyName()
814 // If an unqualified-id is followed by a '(', then we have a function in ClassifyName()
817 // In C++, this is an ADL-only call. in ClassifyName()
879 Name->getName().equals(CorrectedStr); in ClassifyName()
899 // If we found an Objective-C instance variable, let in ClassifyName()
905 ExprResult E(LookupInObjCMethod(Result, S, Ivar->getIdentifier())); in ClassifyName()
920 // dependent nested-name-specifier. in ClassifyName()
924 // dependent on a template-parameter is assumed not to name a type in ClassifyName()
930 // template-argument-list, which would indicate a missing 'template' in ClassifyName()
946 // A lookup that finds an injected-class-name (10.2) can result in an in ClassifyName()
948 // one base class). If all of the injected-class-names that are found in ClassifyName()
950 // is followed by a template-argument-list, the reference refers to the in ClassifyName()
970 // After name lookup (3.4) finds that a name is a template-name or that in ClassifyName()
971 // an operator-function-id or a literal- operator-id refers to a set of in ClassifyName()
974 // template-argument-list and never as the less-than operator. in ClassifyName()
982 if (Result.end() - Result.begin() > 1) { in ClassifyName()
988 = cast<TemplateDecl>((*Result.begin())->getUnderlyingDecl()); in ClassifyName()
1014 NamedDecl *FirstDecl = (*Result.begin())->getUnderlyingDecl(); in ClassifyName()
1017 MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false); in ClassifyName()
1029 Class = Alias->getClassInterface(); in ClassifyName()
1037 // Just return "unknown" as a fall-through for now. in ClassifyName()
1051 // Check for a tag type hidden by a non-type decl in a few cases where it in ClassifyName()
1052 // seems likely a type is wanted instead of the non-type that was found. in ClassifyName()
1056 FirstDecl->getUnderlyingDecl()->isFunctionOrFunctionTemplate())) && in ClassifyName()
1066 if (FirstDecl->isCXXClassMember()) in ClassifyName()
1080 // finished parsing the top-level class, so the top-level class is in getContainingDC()
1084 // either as an in-class member initializer or a default argument. These in getContainingDC()
1088 // ill-formed fashion (such as to specify the width of a bit-field, or in getContainingDC()
1089 // in an array-bound) - in which case we still want to return the in getContainingDC()
1092 DC = DC->getLexicalParent(); in getContainingDC()
1102 while (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC->getLexicalParent())) in getContainingDC()
1110 return DC->getLexicalParent(); in getContainingDC()
1117 S->setEntity(DC); in PushDeclContext()
1130 // the containing DC of TD, because the new context will be some pre-existing in ActOnTagStartSkippedDefinition()
1133 CurContext = cast<TagDecl>(D)->getDefinition(); in ActOnTagStartSkippedDefinition()
1136 // into the pre-existing complete definition. in ActOnTagStartSkippedDefinition()
1137 S->setEntity(CurContext->getLookupParent()); in ActOnTagStartSkippedDefinition()
1145 /// EnterDeclaratorContext - Used when we must lookup names in the context
1151 // X (after the qualified-id of the static member) is looked up as in EnterDeclaratorContext()
1156 // the variable member (after the declarator-id) is looked up as in EnterDeclaratorContext()
1165 assert(!S->getEntity() && "scope already has entity"); in EnterDeclaratorContext()
1168 Scope *Ancestor = S->getParent(); in EnterDeclaratorContext()
1169 while (!Ancestor->getEntity()) Ancestor = Ancestor->getParent(); in EnterDeclaratorContext()
1170 assert(Ancestor->getEntity() == CurContext && "ancestor context mismatch"); in EnterDeclaratorContext()
1174 S->setEntity(DC); in EnterDeclaratorContext()
1178 assert(S->getEntity() == CurContext && "Context imbalance!"); in ExitDeclaratorContext()
1182 Scope *Ancestor = S->getParent(); in ExitDeclaratorContext()
1183 while (!Ancestor->getEntity()) Ancestor = Ancestor->getParent(); in ExitDeclaratorContext()
1184 CurContext = Ancestor->getEntity(); in ExitDeclaratorContext()
1193 FunctionDecl *FD = D->getAsFunction(); in ActOnReenterFunctionContext()
1198 // from the lexical parent, rather than the top-level class. in ActOnReenterFunctionContext()
1199 assert(CurContext == FD->getLexicalParent() && in ActOnReenterFunctionContext()
1202 S->setEntity(CurContext); in ActOnReenterFunctionContext()
1204 for (unsigned P = 0, NumParams = FD->getNumParams(); P < NumParams; ++P) { in ActOnReenterFunctionContext()
1205 ParmVarDecl *Param = FD->getParamDecl(P); in ActOnReenterFunctionContext()
1207 if (Param->getIdentifier()) { in ActOnReenterFunctionContext()
1208 S->AddDecl(Param); in ActOnReenterFunctionContext()
1216 // rather than the top-level class. in ActOnExitFunctionContext()
1218 CurContext = CurContext->getLexicalParent(); in ActOnExitFunctionContext()
1240 && Previous.getFoundDecl()->hasAttr<OverloadableAttr>()); in AllowOverloadingOfFunction()
1246 // non-transparent context. The declaration will be introduced into this in PushOnScopeChains()
1248 while (S->getEntity() && S->getEntity()->isTransparentContext()) in PushOnScopeChains()
1249 S = S->getParent(); in PushOnScopeChains()
1255 CurContext->addDecl(D); in PushOnScopeChains()
1257 // Out-of-line definitions shouldn't be pushed into scope in C++, unless they in PushOnScopeChains()
1258 // are function-local declarations. in PushOnScopeChains()
1259 if (getLangOpts().CPlusPlus && D->isOutOfLine() && in PushOnScopeChains()
1260 !D->getDeclContext()->getRedeclContext()->Equals( in PushOnScopeChains()
1261 D->getLexicalDeclContext()->getRedeclContext()) && in PushOnScopeChains()
1262 !D->getLexicalDeclContext()->isFunctionOrMethod()) in PushOnScopeChains()
1267 cast<FunctionDecl>(D)->isFunctionTemplateSpecialization()) in PushOnScopeChains()
1271 IdentifierResolver::iterator I = IdResolver.begin(D->getDeclName()), in PushOnScopeChains()
1274 if (S->isDeclScope(*I) && D->declarationReplaces(*I)) { in PushOnScopeChains()
1275 S->RemoveDecl(*I); in PushOnScopeChains()
1283 S->AddDecl(D); in PushOnScopeChains()
1285 if (isa<LabelDecl>(D) && !cast<LabelDecl>(D)->isGnuLocal()) { in PushOnScopeChains()
1286 // Implicitly-generated labels may end up getting generated in an order that in PushOnScopeChains()
1288 // the label at the appropriate place in the identifier chain. in PushOnScopeChains()
1289 for (I = IdResolver.begin(D->getDeclName()); I != IEnd; ++I) { in PushOnScopeChains()
1290 DeclContext *IDC = (*I)->getLexicalDeclContext()->getRedeclContext(); in PushOnScopeChains()
1292 if (!S->isDeclScope(*I)) in PushOnScopeChains()
1294 } else if (IDC->Encloses(CurContext)) in PushOnScopeChains()
1306 TUScope->AddDecl(D); in pushExternalDeclIntoScope()
1315 DeclContext *TargetDC = DC->getPrimaryContext(); in getScopeForDeclContext()
1317 if (DeclContext *ScopeDC = S->getEntity()) in getScopeForDeclContext()
1318 if (ScopeDC->getPrimaryContext() == TargetDC) in getScopeForDeclContext()
1320 } while ((S = S->getParent())); in getScopeForDeclContext()
1376 if (D->doesThisDeclarationHaveABody()) in IsDisallowedCopyOrAssign()
1380 return CD->isCopyConstructor(); in IsDisallowedCopyOrAssign()
1382 return Method->isCopyAssignmentOperator(); in IsDisallowedCopyOrAssign()
1395 // of the typedef, this function finds out if D might have non-external linkage.
1399 const DeclContext *DC = D->getDeclContext(); in mightHaveNonExternalLinkage()
1400 while (!DC->isTranslationUnit()) { in mightHaveNonExternalLinkage()
1402 if (!RD->hasNameForLinkage()) in mightHaveNonExternalLinkage()
1405 DC = DC->getParent(); in mightHaveNonExternalLinkage()
1408 return !D->isExternallyVisible(); in mightHaveNonExternalLinkage()
1422 if (D->isInvalidDecl() || D->isUsed() || D->hasAttr<UnusedAttr>()) in ShouldWarnIfUnusedFileScopedDecl()
1425 // Ignore all entities declared within templates, and out-of-line definitions in ShouldWarnIfUnusedFileScopedDecl()
1427 if (D->getDeclContext()->isDependentContext() || in ShouldWarnIfUnusedFileScopedDecl()
1428 D->getLexicalDeclContext()->isDependentContext()) in ShouldWarnIfUnusedFileScopedDecl()
1432 if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) in ShouldWarnIfUnusedFileScopedDecl()
1436 if (MD->isVirtual() || IsDisallowedCopyOrAssign(MD)) in ShouldWarnIfUnusedFileScopedDecl()
1440 if (FD->isInlined() && !isMainFileLoc(*this, FD->getLocation())) in ShouldWarnIfUnusedFileScopedDecl()
1444 if (FD->doesThisDeclarationHaveABody() && in ShouldWarnIfUnusedFileScopedDecl()
1451 if (!isMainFileLoc(*this, VD->getLocation())) in ShouldWarnIfUnusedFileScopedDecl()
1457 if (VD->isStaticDataMember() && in ShouldWarnIfUnusedFileScopedDecl()
1458 VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) in ShouldWarnIfUnusedFileScopedDecl()
1461 if (VD->isInline() && !isMainFileLoc(*this, VD->getLocation())) in ShouldWarnIfUnusedFileScopedDecl()
1468 // FIXME: This seems like a bogus check; it suppresses -Wunused-function in ShouldWarnIfUnusedFileScopedDecl()
1478 const FunctionDecl *First = FD->getFirstDecl(); in MarkUnusedFileScopedDecl()
1484 const VarDecl *First = VD->getFirstDecl(); in MarkUnusedFileScopedDecl()
1494 if (D->isInvalidDecl()) in ShouldDiagnoseUnusedDecl()
1497 if (D->isReferenced() || D->isUsed() || D->hasAttr<UnusedAttr>() || in ShouldDiagnoseUnusedDecl()
1498 D->hasAttr<ObjCPreciseLifetimeAttr>()) in ShouldDiagnoseUnusedDecl()
1506 bool WithinFunction = D->getDeclContext()->isFunctionOrMethod(); in ShouldDiagnoseUnusedDecl()
1507 if (const auto *R = dyn_cast<CXXRecordDecl>(D->getDeclContext())) in ShouldDiagnoseUnusedDecl()
1510 WithinFunction || (R->isLocalClass() && !R->isDependentType()); in ShouldDiagnoseUnusedDecl()
1517 // White-list anything that isn't a local variable. in ShouldDiagnoseUnusedDecl()
1524 // White-list anything with an __attribute__((unused)) type. in ShouldDiagnoseUnusedDecl()
1525 QualType Ty = VD->getType(); in ShouldDiagnoseUnusedDecl()
1528 if (const TypedefType *TT = Ty->getAs<TypedefType>()) { in ShouldDiagnoseUnusedDecl()
1529 if (TT->getDecl()->hasAttr<UnusedAttr>()) in ShouldDiagnoseUnusedDecl()
1535 if (Ty->isIncompleteType() || Ty->isDependentType()) in ShouldDiagnoseUnusedDecl()
1538 if (const TagType *TT = Ty->getAs<TagType>()) { in ShouldDiagnoseUnusedDecl()
1539 const TagDecl *Tag = TT->getDecl(); in ShouldDiagnoseUnusedDecl()
1540 if (Tag->hasAttr<UnusedAttr>()) in ShouldDiagnoseUnusedDecl()
1544 if (!RD->hasTrivialDestructor() && !RD->hasAttr<WarnUnusedAttr>()) in ShouldDiagnoseUnusedDecl()
1547 if (const Expr *Init = VD->getInit()) { in ShouldDiagnoseUnusedDecl()
1550 Init = Cleanups->getSubExpr(); in ShouldDiagnoseUnusedDecl()
1553 if (Construct && !Construct->isElidable()) { in ShouldDiagnoseUnusedDecl()
1554 CXXConstructorDecl *CD = Construct->getConstructor(); in ShouldDiagnoseUnusedDecl()
1555 if (!CD->isTrivial() && !RD->hasAttr<WarnUnusedAttr>()) in ShouldDiagnoseUnusedDecl()
1571 SourceLocation AfterColon = Lexer::findLocationAfterToken(D->getLocEnd(), in GenerateFixForUnusedDecl()
1576 getCharRange(D->getLocStart(), AfterColon)); in GenerateFixForUnusedDecl()
1581 if (D->getTypeForDecl()->isDependentType()) in DiagnoseUnusedNestedTypedefs()
1584 for (auto *TmpD : D->decls()) { in DiagnoseUnusedNestedTypedefs()
1592 /// DiagnoseUnusedDecl - Emit warnings about declarations that are not used
1600 // at end-of-translation-unit. in DiagnoseUnusedDecl()
1609 if (isa<VarDecl>(D) && cast<VarDecl>(D)->isExceptionVariable()) in DiagnoseUnusedDecl()
1616 Diag(D->getLocation(), DiagID) << D->getDeclName() << Hint; in DiagnoseUnusedDecl()
1621 // or address of a label taken, but no definition of it. Label fwd in CheckPoppedLabel()
1623 // MS inline assembly label name. in CheckPoppedLabel()
1625 if (L->isMSAsmLabel()) in CheckPoppedLabel()
1626 Diagnose = !L->isResolvedMSAsmLabel(); in CheckPoppedLabel()
1628 Diagnose = L->getStmt() == nullptr; in CheckPoppedLabel()
1630 S.Diag(L->getLocation(), diag::err_undeclared_label_use) <<L->getDeclName(); in CheckPoppedLabel()
1634 S->mergeNRVOIntoParent(); in ActOnPopScope()
1636 if (S->decl_empty()) return; in ActOnPopScope()
1637 assert((S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) && in ActOnPopScope()
1640 for (auto *TmpD : S->decls()) { in ActOnPopScope()
1646 if (!D->getDeclName()) continue; in ActOnPopScope()
1649 if (!S->hasUnrecoverableErrorOccurred()) { in ActOnPopScope()
1655 // If this was a forward reference to a label, verify it was defined. in ActOnPopScope()
1664 if (const auto *FD = dyn_cast<FieldDecl>(ShadowI->second)) { in ActOnPopScope()
1665 Diag(D->getLocation(), diag::warn_ctor_parm_shadows_field) in ActOnPopScope()
1666 << D << FD << FD->getParent(); in ActOnPopScope()
1667 Diag(FD->getLocation(), diag::note_previous_declaration); in ActOnPopScope()
1674 /// \brief Look for an Objective-C class in the translation unit.
1676 /// \param Id The name of the Objective-C class we're looking for. If
1677 /// typo-correction fixes this name, the Id will be updated
1685 /// \returns The declaration of the named Objective-C class, or NULL if the
1690 // The third "scope" argument is 0 since we aren't enabling lazy built-in in getObjCInterfaceDecl()
1696 // find an Objective-C class name. in getObjCInterfaceDecl()
1703 Id = IDecl->getIdentifier(); in getObjCInterfaceDecl()
1708 if (Def && Def->getDefinition()) in getObjCInterfaceDecl()
1709 Def = Def->getDefinition(); in getObjCInterfaceDecl()
1713 /// getNonFieldDeclScope - Retrieves the innermost scope, starting
1714 /// from S, where a non-field would be declared. This routine copes
1716 /// unions. For example, the following code is well-formed in C but
1717 /// ill-formed in C++:
1732 /// context but structures can contain non-field names. In C, this
1735 /// contain non-field names.
1737 while (((S->getFlags() & Scope::DeclScope) == 0) || in getNonFieldDeclScope()
1738 (S->getEntity() && S->getEntity()->isTransparentContext()) || in getNonFieldDeclScope()
1739 (S->isClassScope() && !getLangOpts().CPlusPlus)) in getNonFieldDeclScope()
1740 S = S->getParent(); in getNonFieldDeclScope()
1747 /// pre-existing declaration exists no action takes place.
1750 if (!II->isStr("objc_msgSendSuper")) in LookupPredefedObjCSuperType()
1776 /// LazilyCreateBuiltin - The specified Builtin-ID was first used at
1778 /// if we're creating this built-in in anticipation of redeclaring the
1779 /// built-in.
1812 CLinkageDecl->setImplicit(); in LazilyCreateBuiltin()
1813 Parent->addDecl(CLinkageDecl); in LazilyCreateBuiltin()
1822 R->isFunctionProtoType()); in LazilyCreateBuiltin()
1823 New->setImplicit(); in LazilyCreateBuiltin()
1829 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { in LazilyCreateBuiltin()
1832 nullptr, FT->getParamType(i), /*TInfo=*/nullptr, in LazilyCreateBuiltin()
1834 parm->setScopeInfo(0, i); in LazilyCreateBuiltin()
1837 New->setParams(Params); in LazilyCreateBuiltin()
1843 // TUScope is the translation-unit scope to insert this function into. in LazilyCreateBuiltin()
1873 // Non-hidden declarations are never ignored. in filterNonConflictingPreviousTypedefDecls()
1880 if (S.Context.hasSameType(OldTD->getUnderlyingType(), in filterNonConflictingPreviousTypedefDecls()
1881 Decl->getUnderlyingType())) in filterNonConflictingPreviousTypedefDecls()
1887 OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true) && in filterNonConflictingPreviousTypedefDecls()
1888 Decl->getAnonDeclWithTypedefName()) in filterNonConflictingPreviousTypedefDecls()
1901 OldType = OldTypedef->getUnderlyingType(); in isIncompatibleTypedef()
1904 QualType NewType = New->getUnderlyingType(); in isIncompatibleTypedef()
1906 if (NewType->isVariablyModifiedType()) { in isIncompatibleTypedef()
1907 // Must not redefine a typedef with a variably-modified type. in isIncompatibleTypedef()
1909 Diag(New->getLocation(), diag::err_redefinition_variably_modified_typedef) in isIncompatibleTypedef()
1911 if (Old->getLocation().isValid()) in isIncompatibleTypedef()
1912 Diag(Old->getLocation(), diag::note_previous_definition); in isIncompatibleTypedef()
1913 New->setInvalidDecl(); in isIncompatibleTypedef()
1918 !OldType->isDependentType() && in isIncompatibleTypedef()
1919 !NewType->isDependentType() && in isIncompatibleTypedef()
1922 Diag(New->getLocation(), diag::err_redefinition_different_typedef) in isIncompatibleTypedef()
1924 if (Old->getLocation().isValid()) in isIncompatibleTypedef()
1925 Diag(Old->getLocation(), diag::note_previous_definition); in isIncompatibleTypedef()
1926 New->setInvalidDecl(); in isIncompatibleTypedef()
1932 /// MergeTypedefNameDecl - We just parsed a typedef 'New' which has the
1941 if (New->isInvalidDecl()) return; in MergeTypedefNameDecl()
1943 // Allow multiple definitions for ObjC built-in typedefs. in MergeTypedefNameDecl()
1946 const IdentifierInfo *TypeID = New->getIdentifier(); in MergeTypedefNameDecl()
1947 switch (TypeID->getLength()) { in MergeTypedefNameDecl()
1951 if (!TypeID->isStr("id")) in MergeTypedefNameDecl()
1953 QualType T = New->getUnderlyingType(); in MergeTypedefNameDecl()
1954 if (!T->isPointerType()) in MergeTypedefNameDecl()
1956 if (!T->isVoidPointerType()) { in MergeTypedefNameDecl()
1957 QualType PT = T->getAs<PointerType>()->getPointeeType(); in MergeTypedefNameDecl()
1958 if (!PT->isStructureType()) in MergeTypedefNameDecl()
1962 // Install the built-in type for 'id', ignoring the current definition. in MergeTypedefNameDecl()
1963 New->setTypeForDecl(Context.getObjCIdType().getTypePtr()); in MergeTypedefNameDecl()
1967 if (!TypeID->isStr("Class")) in MergeTypedefNameDecl()
1969 Context.setObjCClassRedefinitionType(New->getUnderlyingType()); in MergeTypedefNameDecl()
1970 // Install the built-in type for 'Class', ignoring the current definition. in MergeTypedefNameDecl()
1971 New->setTypeForDecl(Context.getObjCClassType().getTypePtr()); in MergeTypedefNameDecl()
1974 if (!TypeID->isStr("SEL")) in MergeTypedefNameDecl()
1976 Context.setObjCSelRedefinitionType(New->getUnderlyingType()); in MergeTypedefNameDecl()
1977 // Install the built-in type for 'SEL', ignoring the current definition. in MergeTypedefNameDecl()
1978 New->setTypeForDecl(Context.getObjCSelType().getTypePtr()); in MergeTypedefNameDecl()
1981 // Fall through - the typedef name was not a builtin type. in MergeTypedefNameDecl()
1987 Diag(New->getLocation(), diag::err_redefinition_different_kind) in MergeTypedefNameDecl()
1988 << New->getDeclName(); in MergeTypedefNameDecl()
1991 if (OldD->getLocation().isValid()) in MergeTypedefNameDecl()
1992 Diag(OldD->getLocation(), diag::note_previous_definition); in MergeTypedefNameDecl()
1994 return New->setInvalidDecl(); in MergeTypedefNameDecl()
1998 if (Old->isInvalidDecl()) in MergeTypedefNameDecl()
1999 return New->setInvalidDecl(); in MergeTypedefNameDecl()
2002 auto *OldTag = OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true); in MergeTypedefNameDecl()
2003 auto *NewTag = New->getAnonDeclWithTypedefName(); in MergeTypedefNameDecl()
2006 OldTag->getCanonicalDecl() != NewTag->getCanonicalDecl() && in MergeTypedefNameDecl()
2010 New->setTypeForDecl(OldTD->getTypeForDecl()); in MergeTypedefNameDecl()
2011 if (OldTD->isModed()) in MergeTypedefNameDecl()
2012 New->setModedTypeSourceInfo(OldTD->getTypeSourceInfo(), in MergeTypedefNameDecl()
2013 OldTD->getUnderlyingType()); in MergeTypedefNameDecl()
2015 New->setTypeSourceInfo(OldTD->getTypeSourceInfo()); in MergeTypedefNameDecl()
2018 makeMergedDefinitionVisible(Hidden, NewTag->getLocation()); in MergeTypedefNameDecl()
2024 for (auto *D : NewTag->decls()) { in MergeTypedefNameDecl()
2026 assert(EnumScope->isDeclScope(ED)); in MergeTypedefNameDecl()
2027 EnumScope->RemoveDecl(ED); in MergeTypedefNameDecl()
2029 ED->getLexicalDeclContext()->removeDecl(ED); in MergeTypedefNameDecl()
2043 New->setPreviousDecl(Typedef); in MergeTypedefNameDecl()
2052 // In a given non-class scope, a typedef specifier can be used to in MergeTypedefNameDecl()
2060 // any class-name declared in that scope that is not also a typedef-name in MergeTypedefNameDecl()
2082 Diag(New->getLocation(), diag::err_redefinition) in MergeTypedefNameDecl()
2083 << New->getDeclName(); in MergeTypedefNameDecl()
2084 Diag(Old->getLocation(), diag::note_previous_definition); in MergeTypedefNameDecl()
2085 return New->setInvalidDecl(); in MergeTypedefNameDecl()
2094 // -Wtypedef-redefinition. If either the original or the redefinition is in MergeTypedefNameDecl()
2097 (Context.getSourceManager().isInSystemHeader(Old->getLocation()) || in MergeTypedefNameDecl()
2098 Context.getSourceManager().isInSystemHeader(New->getLocation()))) in MergeTypedefNameDecl()
2101 Diag(New->getLocation(), diag::ext_redefinition_of_typedef) in MergeTypedefNameDecl()
2102 << New->getDeclName(); in MergeTypedefNameDecl()
2103 Diag(Old->getLocation(), diag::note_previous_definition); in MergeTypedefNameDecl()
2106 /// DeclhasAttr - returns true if decl Declaration already has the target
2111 for (const auto *i : D->attrs()) in DeclHasAttr()
2112 if (i->getKind() == A->getKind()) { in DeclHasAttr()
2114 if (Ann->getAnnotation() == cast<AnnotateAttr>(i)->getAnnotation()) in DeclHasAttr()
2120 return OA->getOwnKind() == cast<OwnershipAttr>(i)->getOwnKind(); in DeclHasAttr()
2129 return VD->isThisDeclarationADefinition(); in isAttributeTargetADefinition()
2131 return TD->isCompleteDefinition() || TD->isBeingDefined(); in isAttributeTargetADefinition()
2145 for (auto *I : Old->specific_attrs<AlignedAttr>()) { in mergeAlignedAttrs()
2152 if (I->isAlignmentDependent()) in mergeAlignedAttrs()
2155 if (I->isAlignas()) in mergeAlignedAttrs()
2158 unsigned Align = I->getAlignment(S.Context); in mergeAlignedAttrs()
2168 for (auto *I : New->specific_attrs<AlignedAttr>()) { in mergeAlignedAttrs()
2169 if (I->isAlignmentDependent()) in mergeAlignedAttrs()
2172 if (I->isAlignas()) in mergeAlignedAttrs()
2175 unsigned Align = I->getAlignment(S.Context); in mergeAlignedAttrs()
2191 Ty = VD->getType(); in mergeAlignedAttrs()
2202 S.Diag(NewAlignasAttr->getLocation(), diag::err_alignas_mismatch) in mergeAlignedAttrs()
2205 S.Diag(OldAlignasAttr->getLocation(), diag::note_previous_declaration); in mergeAlignedAttrs()
2211 // if any declaration of an entity has an alignment-specifier, in mergeAlignedAttrs()
2218 S.Diag(New->getLocation(), diag::err_alignas_missing_on_definition) in mergeAlignedAttrs()
2220 S.Diag(OldAlignasAttr->getLocation(), diag::note_alignas_on_declaration) in mergeAlignedAttrs()
2228 AlignedAttr *Clone = OldStrictestAlignAttr->clone(S.Context); in mergeAlignedAttrs()
2229 Clone->setInherited(true); in mergeAlignedAttrs()
2230 New->addAttr(Clone); in mergeAlignedAttrs()
2236 !(AnyAdded && OldStrictestAlignAttr->isAlignas())) { in mergeAlignedAttrs()
2237 AlignedAttr *Clone = OldAlignasAttr->clone(S.Context); in mergeAlignedAttrs()
2238 Clone->setInherited(true); in mergeAlignedAttrs()
2239 New->addAttr(Clone); in mergeAlignedAttrs()
2250 unsigned AttrSpellingListIndex = Attr->getSpellingListIndex(); in mergeDeclAttribute()
2252 NewAttr = S.mergeAvailabilityAttr(D, AA->getRange(), AA->getPlatform(), in mergeDeclAttribute()
2253 AA->isImplicit(), AA->getIntroduced(), in mergeDeclAttribute()
2254 AA->getDeprecated(), in mergeDeclAttribute()
2255 AA->getObsoleted(), AA->getUnavailable(), in mergeDeclAttribute()
2256 AA->getMessage(), AA->getStrict(), in mergeDeclAttribute()
2257 AA->getReplacement(), AMK, in mergeDeclAttribute()
2260 NewAttr = S.mergeVisibilityAttr(D, VA->getRange(), VA->getVisibility(), in mergeDeclAttribute()
2263 NewAttr = S.mergeTypeVisibilityAttr(D, VA->getRange(), VA->getVisibility(), in mergeDeclAttribute()
2266 NewAttr = S.mergeDLLImportAttr(D, ImportA->getRange(), in mergeDeclAttribute()
2269 NewAttr = S.mergeDLLExportAttr(D, ExportA->getRange(), in mergeDeclAttribute()
2272 NewAttr = S.mergeFormatAttr(D, FA->getRange(), FA->getType(), in mergeDeclAttribute()
2273 FA->getFormatIdx(), FA->getFirstArg(), in mergeDeclAttribute()
2276 NewAttr = S.mergeSectionAttr(D, SA->getRange(), SA->getName(), in mergeDeclAttribute()
2279 NewAttr = S.mergeMSInheritanceAttr(D, IA->getRange(), IA->getBestCase(), in mergeDeclAttribute()
2281 IA->getSemanticSpelling()); in mergeDeclAttribute()
2283 NewAttr = S.mergeAlwaysInlineAttr(D, AA->getRange(), in mergeDeclAttribute()
2284 &S.Context.Idents.get(AA->getSpelling()), in mergeDeclAttribute()
2287 NewAttr = S.mergeMinSizeAttr(D, MA->getRange(), AttrSpellingListIndex); in mergeDeclAttribute()
2289 NewAttr = S.mergeOptimizeNoneAttr(D, OA->getRange(), AttrSpellingListIndex); in mergeDeclAttribute()
2292 D, InternalLinkageA->getRange(), in mergeDeclAttribute()
2293 &S.Context.Idents.get(InternalLinkageA->getSpelling()), in mergeDeclAttribute()
2296 NewAttr = S.mergeCommonAttr(D, CommonA->getRange(), in mergeDeclAttribute()
2297 &S.Context.Idents.get(CommonA->getSpelling()), in mergeDeclAttribute()
2307 else if (Attr->duplicatesAllowed() || !DeclHasAttr(D, Attr)) in mergeDeclAttribute()
2308 NewAttr = cast<InheritableAttr>(Attr->clone(S.Context)); in mergeDeclAttribute()
2311 NewAttr->setInherited(true); in mergeDeclAttribute()
2312 D->addAttr(NewAttr); in mergeDeclAttribute()
2323 return TD->getDefinition(); in getDefinition()
2325 const VarDecl *Def = VD->getDefinition(); in getDefinition()
2328 return VD->getActingDefinition(); in getDefinition()
2331 return FD->getDefinition(); in getDefinition()
2336 for (const auto *Attribute : D->attrs()) in hasAttribute()
2337 if (Attribute->getKind() == Kind) in hasAttribute()
2342 /// checkNewAttributesAfterDef - If we already have a definition, check that
2345 if (!New->hasAttrs()) in checkNewAttributesAfterDef()
2352 AttrVec &NewAttributes = New->getAttrs(); in checkNewAttributesAfterDef()
2364 --E; in checkNewAttributesAfterDef()
2369 unsigned Diag = cast<VarDecl>(Def)->isThisDeclarationADefinition() == in checkNewAttributesAfterDef()
2373 S.Diag(VD->getLocation(), Diag) << VD->getDeclName(); in checkNewAttributesAfterDef()
2374 S.Diag(Def->getLocation(), diag::note_previous_definition); in checkNewAttributesAfterDef()
2375 VD->setInvalidDecl(); in checkNewAttributesAfterDef()
2383 if (VD->isThisDeclarationADefinition() != VarDecl::Definition) { in checkNewAttributesAfterDef()
2389 if (hasAttribute(Def, NewAttribute->getKind())) { in checkNewAttributesAfterDef()
2399 if (AA->isAlignas()) { in checkNewAttributesAfterDef()
2401 // if any declaration of an entity has an alignment-specifier, in checkNewAttributesAfterDef()
2408 S.Diag(Def->getLocation(), diag::err_alignas_missing_on_definition) in checkNewAttributesAfterDef()
2410 S.Diag(NewAttribute->getLocation(), diag::note_alignas_on_declaration) in checkNewAttributesAfterDef()
2413 --E; in checkNewAttributesAfterDef()
2418 S.Diag(NewAttribute->getLocation(), in checkNewAttributesAfterDef()
2420 S.Diag(Def->getLocation(), diag::note_previous_definition); in checkNewAttributesAfterDef()
2422 --E; in checkNewAttributesAfterDef()
2426 /// mergeDeclAttributes - Copy attributes from the Old decl to the New one.
2429 if (UsedAttr *OldAttr = Old->getMostRecentDecl()->getAttr<UsedAttr>()) { in mergeDeclAttributes()
2430 UsedAttr *NewAttr = OldAttr->clone(Context); in mergeDeclAttributes()
2431 NewAttr->setInherited(true); in mergeDeclAttributes()
2432 New->addAttr(NewAttr); in mergeDeclAttributes()
2435 if (!Old->hasAttrs() && !New->hasAttrs()) in mergeDeclAttributes()
2438 // Attributes declared post-definition are currently ignored. in mergeDeclAttributes()
2441 if (AsmLabelAttr *NewA = New->getAttr<AsmLabelAttr>()) { in mergeDeclAttributes()
2442 if (AsmLabelAttr *OldA = Old->getAttr<AsmLabelAttr>()) { in mergeDeclAttributes()
2443 if (OldA->getLabel() != NewA->getLabel()) { in mergeDeclAttributes()
2444 // This redeclaration changes __asm__ label. in mergeDeclAttributes()
2445 Diag(New->getLocation(), diag::err_different_asm_label); in mergeDeclAttributes()
2446 Diag(OldA->getLocation(), diag::note_previous_declaration); in mergeDeclAttributes()
2448 } else if (Old->isUsed()) { in mergeDeclAttributes()
2449 // This redeclaration adds an __asm__ label to a declaration that has in mergeDeclAttributes()
2450 // already been ODR-used. in mergeDeclAttributes()
2451 Diag(New->getLocation(), diag::err_late_asm_label_name) in mergeDeclAttributes()
2452 << isa<FunctionDecl>(Old) << New->getAttr<AsmLabelAttr>()->getRange(); in mergeDeclAttributes()
2456 // Re-declaration cannot add abi_tag's. in mergeDeclAttributes()
2457 if (const auto *NewAbiTagAttr = New->getAttr<AbiTagAttr>()) { in mergeDeclAttributes()
2458 if (const auto *OldAbiTagAttr = Old->getAttr<AbiTagAttr>()) { in mergeDeclAttributes()
2459 for (const auto &NewTag : NewAbiTagAttr->tags()) { in mergeDeclAttributes()
2460 if (std::find(OldAbiTagAttr->tags_begin(), OldAbiTagAttr->tags_end(), in mergeDeclAttributes()
2461 NewTag) == OldAbiTagAttr->tags_end()) { in mergeDeclAttributes()
2462 Diag(NewAbiTagAttr->getLocation(), in mergeDeclAttributes()
2465 Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration); in mergeDeclAttributes()
2469 Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration); in mergeDeclAttributes()
2470 Diag(Old->getLocation(), diag::note_previous_declaration); in mergeDeclAttributes()
2474 if (!Old->hasAttrs()) in mergeDeclAttributes()
2477 bool foundAny = New->hasAttrs(); in mergeDeclAttributes()
2481 if (!foundAny) New->setAttrs(AttrVec()); in mergeDeclAttributes()
2483 for (auto *I : Old->specific_attrs<InheritableAttr>()) { in mergeDeclAttributes()
2512 if (!foundAny) New->dropAttrs(); in mergeDeclAttributes()
2515 /// mergeParamDeclAttributes - Copy attributes from the old parameter
2522 // carries_dependency attribute for its declarator-id if any declaration in mergeParamDeclAttributes()
2524 const CarriesDependencyAttr *CDA = newDecl->getAttr<CarriesDependencyAttr>(); in mergeParamDeclAttributes()
2525 if (CDA && !oldDecl->hasAttr<CarriesDependencyAttr>()) { in mergeParamDeclAttributes()
2526 S.Diag(CDA->getLocation(), in mergeParamDeclAttributes()
2531 cast<FunctionDecl>(oldDecl->getDeclContext())->getFirstDecl(); in mergeParamDeclAttributes()
2533 FirstFD->getParamDecl(oldDecl->getFunctionScopeIndex()); in mergeParamDeclAttributes()
2534 S.Diag(FirstVD->getLocation(), in mergeParamDeclAttributes()
2538 if (!oldDecl->hasAttrs()) in mergeParamDeclAttributes()
2541 bool foundAny = newDecl->hasAttrs(); in mergeParamDeclAttributes()
2545 if (!foundAny) newDecl->setAttrs(AttrVec()); in mergeParamDeclAttributes()
2547 for (const auto *I : oldDecl->specific_attrs<InheritableParamAttr>()) { in mergeParamDeclAttributes()
2550 cast<InheritableParamAttr>(I->clone(S.Context)); in mergeParamDeclAttributes()
2551 newAttr->setInherited(true); in mergeParamDeclAttributes()
2552 newDecl->addAttr(newAttr); in mergeParamDeclAttributes()
2557 if (!foundAny) newDecl->dropAttrs(); in mergeParamDeclAttributes()
2563 if (auto Oldnullability = OldParam->getType()->getNullability(S.Context)) { in mergeParamDeclTypes()
2564 if (auto Newnullability = NewParam->getType()->getNullability(S.Context)) { in mergeParamDeclTypes()
2566 S.Diag(NewParam->getLocation(), diag::warn_mismatched_nullability_attr) in mergeParamDeclTypes()
2569 ((NewParam->getObjCDeclQualifier() & Decl::OBJC_TQ_CSNullability) in mergeParamDeclTypes()
2573 ((OldParam->getObjCDeclQualifier() & Decl::OBJC_TQ_CSNullability) in mergeParamDeclTypes()
2575 S.Diag(OldParam->getLocation(), diag::note_previous_declaration); in mergeParamDeclTypes()
2578 QualType NewT = NewParam->getType(); in mergeParamDeclTypes()
2582 NewParam->setType(NewT); in mergeParamDeclTypes()
2599 /// getSpecialMember - get the special member enum for a method.
2602 if (Ctor->isDefaultConstructor()) in getSpecialMember()
2605 if (Ctor->isCopyConstructor()) in getSpecialMember()
2608 if (Ctor->isMoveConstructor()) in getSpecialMember()
2612 } else if (MD->isCopyAssignmentOperator()) { in getSpecialMember()
2614 } else if (MD->isMoveAssignmentOperator()) { in getSpecialMember()
2627 SourceLocation OldLocation = Old->getLocation(); in getNoteDiagForInvalidRedeclaration()
2628 if (Old->isThisDeclarationADefinition()) in getNoteDiagForInvalidRedeclaration()
2630 else if (Old->isImplicit()) { in getNoteDiagForInvalidRedeclaration()
2633 OldLocation = New->getLocation(); in getNoteDiagForInvalidRedeclaration()
2639 /// canRedefineFunction - checks if a function can be redefined. Currently,
2644 return ((FD->hasAttr<GNUInlineAttr>() || LangOpts.GNUInline) && in canRedefineFunction()
2646 FD->isInlineSpecified() && in canRedefineFunction()
2647 FD->getStorageClass() == SC_Extern); in canRedefineFunction()
2651 const AttributedType *AT = T->getAs<AttributedType>(); in getCallingConvAttributedType()
2652 while (AT && !AT->isCallingConv()) in getCallingConvAttributedType()
2653 AT = AT->getModifiedType()->getAs<AttributedType>(); in getCallingConvAttributedType()
2659 const DeclContext *DC = Old->getDeclContext(); in haveIncompatibleLanguageLinkages()
2660 if (DC->isRecord()) in haveIncompatibleLanguageLinkages()
2663 LanguageLinkage OldLinkage = Old->getLanguageLinkage(); in haveIncompatibleLanguageLinkages()
2664 if (OldLinkage == CXXLanguageLinkage && New->isInExternCContext()) in haveIncompatibleLanguageLinkages()
2666 if (OldLinkage == CLanguageLinkage && New->isInExternCXXContext()) in haveIncompatibleLanguageLinkages()
2671 template<typename T> static bool isExternC(T *D) { return D->isExternC(); } in isExternC()
2675 /// using-declaration is valid, given that we know it's not an overload
2683 // -- they shall all refer to the same entity, or all refer to functions in checkUsingShadowRedecl()
2685 // -- exactly one declaration shall declare a class name or enumeration in checkUsingShadowRedecl()
2693 // same name and the same parameter-type-list as a function introduced in checkUsingShadowRedecl()
2694 // by a using-declaration, and the declarations do not declare the same in checkUsingShadowRedecl()
2695 // function, the program is ill-formed. in checkUsingShadowRedecl()
2697 auto *Old = dyn_cast<ExpectedDecl>(OldS->getTargetDecl()); in checkUsingShadowRedecl()
2699 !Old->getDeclContext()->getRedeclContext()->Equals( in checkUsingShadowRedecl()
2700 New->getDeclContext()->getRedeclContext()) && in checkUsingShadowRedecl()
2705 S.Diag(New->getLocation(), diag::err_using_decl_conflict_reverse); in checkUsingShadowRedecl()
2706 S.Diag(OldS->getTargetDecl()->getLocation(), diag::note_using_decl_target); in checkUsingShadowRedecl()
2707 S.Diag(OldS->getUsingDecl()->getLocation(), diag::note_using_decl) << 0; in checkUsingShadowRedecl()
2715 assert(A->getNumParams() == B->getNumParams()); in hasIdenticalPassObjectSizeAttrs()
2718 const auto *AttrA = A->getAttr<PassObjectSizeAttr>(); in hasIdenticalPassObjectSizeAttrs()
2719 const auto *AttrB = B->getAttr<PassObjectSizeAttr>(); in hasIdenticalPassObjectSizeAttrs()
2722 return AttrA && AttrB && AttrA->getType() == AttrB->getType(); in hasIdenticalPassObjectSizeAttrs()
2725 return std::equal(A->param_begin(), A->param_end(), B->param_begin(), AttrEq); in hasIdenticalPassObjectSizeAttrs()
2728 /// MergeFunctionDecl - We just parsed a function 'New' from
2742 FunctionDecl *Old = OldD->getAsFunction(); in MergeFunctionDecl()
2745 if (New->getFriendObjectKind()) { in MergeFunctionDecl()
2746 Diag(New->getLocation(), diag::err_using_decl_friend); in MergeFunctionDecl()
2747 Diag(Shadow->getTargetDecl()->getLocation(), in MergeFunctionDecl()
2749 Diag(Shadow->getUsingDecl()->getLocation(), in MergeFunctionDecl()
2757 OldD = Old = cast<FunctionDecl>(Shadow->getTargetDecl()); in MergeFunctionDecl()
2759 Diag(New->getLocation(), diag::err_redefinition_different_kind) in MergeFunctionDecl()
2760 << New->getDeclName(); in MergeFunctionDecl()
2761 Diag(OldD->getLocation(), diag::note_previous_definition); in MergeFunctionDecl()
2767 if (Old->isInvalidDecl()) in MergeFunctionDecl()
2780 New->getStorageClass() == SC_Static && in MergeFunctionDecl()
2781 Old->hasExternalFormalLinkage() && in MergeFunctionDecl()
2782 !New->getTemplateSpecializationInfo() && in MergeFunctionDecl()
2785 Diag(New->getLocation(), diag::ext_static_non_static) << New; in MergeFunctionDecl()
2788 Diag(New->getLocation(), diag::err_static_non_static) << New; in MergeFunctionDecl()
2794 if (New->hasAttr<InternalLinkageAttr>() && in MergeFunctionDecl()
2795 !Old->hasAttr<InternalLinkageAttr>()) { in MergeFunctionDecl()
2796 Diag(New->getLocation(), diag::err_internal_linkage_redeclaration) in MergeFunctionDecl()
2797 << New->getDeclName(); in MergeFunctionDecl()
2798 Diag(Old->getLocation(), diag::note_previous_definition); in MergeFunctionDecl()
2799 New->dropAttr<InternalLinkageAttr>(); in MergeFunctionDecl()
2815 QualType OldQType = Context.getCanonicalType(Old->getType()); in MergeFunctionDecl()
2816 QualType NewQType = Context.getCanonicalType(New->getType()); in MergeFunctionDecl()
2819 FunctionType::ExtInfo OldTypeInfo = OldType->getExtInfo(); in MergeFunctionDecl()
2820 FunctionType::ExtInfo NewTypeInfo = NewType->getExtInfo(); in MergeFunctionDecl()
2824 FunctionDecl *First = Old->getFirstDecl(); in MergeFunctionDecl()
2826 First->getType().getCanonicalType()->castAs<FunctionType>(); in MergeFunctionDecl()
2827 FunctionType::ExtInfo FI = FT->getExtInfo(); in MergeFunctionDecl()
2828 bool NewCCExplicit = getCallingConvAttributedType(New->getType()); in MergeFunctionDecl()
2836 bool FirstCCExplicit = getCallingConvAttributedType(First->getType()); in MergeFunctionDecl()
2837 Diag(New->getLocation(), diag::err_cconv_change) in MergeFunctionDecl()
2844 Diag(First->getLocation(), diag::note_previous_declaration); in MergeFunctionDecl()
2859 Diag(New->getLocation(), diag::err_regparm_mismatch) in MergeFunctionDecl()
2860 << NewType->getRegParmType() in MergeFunctionDecl()
2861 << OldType->getRegParmType(); in MergeFunctionDecl()
2873 Diag(New->getLocation(), diag::err_returns_retained_mismatch); in MergeFunctionDecl()
2883 const FunctionType *AdjustedType = New->getType()->getAs<FunctionType>(); in MergeFunctionDecl()
2885 New->setType(QualType(AdjustedType, 0)); in MergeFunctionDecl()
2886 NewQType = Context.getCanonicalType(New->getType()); in MergeFunctionDecl()
2892 if (!Old->isInlined() && New->isInlined() && in MergeFunctionDecl()
2893 !New->hasAttr<GNUInlineAttr>() && in MergeFunctionDecl()
2895 Old->isUsed(false) && in MergeFunctionDecl()
2896 !Old->isDefined() && !New->isThisDeclarationADefinition()) in MergeFunctionDecl()
2897 UndefinedButUsed.insert(std::make_pair(Old->getCanonicalDecl(), in MergeFunctionDecl()
2902 if (New->hasAttr<GNUInlineAttr>() && in MergeFunctionDecl()
2903 Old->isInlined() && !Old->hasAttr<GNUInlineAttr>()) { in MergeFunctionDecl()
2904 UndefinedButUsed.erase(Old->getCanonicalDecl()); in MergeFunctionDecl()
2909 if (Old->getNumParams() > 0 && Old->getNumParams() == New->getNumParams() && in MergeFunctionDecl()
2911 Diag(New->getLocation(), diag::err_different_pass_object_size_params) in MergeFunctionDecl()
2912 << New->getDeclName(); in MergeFunctionDecl()
2913 Diag(OldLocation, PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
2920 // -- Function declarations that differ only in the return type in MergeFunctionDecl()
2929 (Old->getTypeSourceInfo() in MergeFunctionDecl()
2930 ? Old->getTypeSourceInfo()->getType()->castAs<FunctionType>() in MergeFunctionDecl()
2931 : OldType)->getReturnType(); in MergeFunctionDecl()
2933 (New->getTypeSourceInfo() in MergeFunctionDecl()
2934 ? New->getTypeSourceInfo()->getType()->castAs<FunctionType>() in MergeFunctionDecl()
2935 : NewType)->getReturnType(); in MergeFunctionDecl()
2938 !((NewQType->isDependentType() || OldQType->isDependentType()) && in MergeFunctionDecl()
2939 New->isLocalExternDecl())) { in MergeFunctionDecl()
2940 if (NewDeclaredReturnType->isObjCObjectPointerType() && in MergeFunctionDecl()
2941 OldDeclaredReturnType->isObjCObjectPointerType()) in MergeFunctionDecl()
2944 if (New->isCXXClassMember() && New->isOutOfLine()) in MergeFunctionDecl()
2945 Diag(New->getLocation(), diag::err_member_def_does_not_match_ret_type) in MergeFunctionDecl()
2946 << New << New->getReturnTypeSourceRange(); in MergeFunctionDecl()
2948 Diag(New->getLocation(), diag::err_ovl_diff_return_type) in MergeFunctionDecl()
2949 << New->getReturnTypeSourceRange(); in MergeFunctionDecl()
2950 Diag(OldLocation, PrevDiag) << Old << Old->getType() in MergeFunctionDecl()
2951 << Old->getReturnTypeSourceRange(); in MergeFunctionDecl()
2958 QualType OldReturnType = OldType->getReturnType(); in MergeFunctionDecl()
2959 QualType NewReturnType = cast<FunctionType>(NewQType)->getReturnType(); in MergeFunctionDecl()
2963 AutoType *OldAT = Old->getReturnType()->getContainedAutoType(); in MergeFunctionDecl()
2964 if (OldAT && OldAT->isDeduced()) { in MergeFunctionDecl()
2965 New->setType( in MergeFunctionDecl()
2966 SubstAutoType(New->getType(), in MergeFunctionDecl()
2967 OldAT->isDependentType() ? Context.DependentTy in MergeFunctionDecl()
2968 : OldAT->getDeducedType())); in MergeFunctionDecl()
2971 OldAT->isDependentType() ? Context.DependentTy in MergeFunctionDecl()
2972 : OldAT->getDeducedType())); in MergeFunctionDecl()
2980 NewMethod->setTrivial(OldMethod->isTrivial()); in MergeFunctionDecl()
2986 OldMethod->isFunctionTemplateSpecialization() && in MergeFunctionDecl()
2987 NewMethod->isFunctionTemplateSpecialization(); in MergeFunctionDecl()
2988 bool isFriend = NewMethod->getFriendObjectKind(); in MergeFunctionDecl()
2990 if (!isFriend && NewMethod->getLexicalDeclContext()->isRecord() && in MergeFunctionDecl()
2992 // -- Member function declarations with the same name and the in MergeFunctionDecl()
2995 if (OldMethod->isStatic() != NewMethod->isStatic()) { in MergeFunctionDecl()
2996 Diag(New->getLocation(), diag::err_ovl_static_nonstatic_member); in MergeFunctionDecl()
2997 Diag(OldLocation, PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
3003 // member-specification, except that a nested class or member in MergeFunctionDecl()
3016 Diag(New->getLocation(), NewDiag); in MergeFunctionDecl()
3018 Diag(New->getLocation(), diag::err_member_redeclared_in_instantiation) in MergeFunctionDecl()
3019 << New << New->getType(); in MergeFunctionDecl()
3021 Diag(OldLocation, PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
3029 } else if (OldMethod->isImplicit()) { in MergeFunctionDecl()
3031 NewMethod->setImplicit(); in MergeFunctionDecl()
3033 Diag(NewMethod->getLocation(), in MergeFunctionDecl()
3038 } else if (OldMethod->getFirstDecl()->isExplicitlyDefaulted() && !isFriend) { in MergeFunctionDecl()
3039 Diag(NewMethod->getLocation(), in MergeFunctionDecl()
3050 const CXX11NoReturnAttr *NRA = New->getAttr<CXX11NoReturnAttr>(); in MergeFunctionDecl()
3051 if (NRA && !Old->hasAttr<CXX11NoReturnAttr>()) { in MergeFunctionDecl()
3052 Diag(NRA->getLocation(), diag::err_noreturn_missing_on_first_decl); in MergeFunctionDecl()
3053 Diag(Old->getFirstDecl()->getLocation(), in MergeFunctionDecl()
3059 // carries_dependency attribute for its declarator-id if any declaration in MergeFunctionDecl()
3061 const CarriesDependencyAttr *CDA = New->getAttr<CarriesDependencyAttr>(); in MergeFunctionDecl()
3062 if (CDA && !Old->hasAttr<CarriesDependencyAttr>()) { in MergeFunctionDecl()
3063 Diag(CDA->getLocation(), in MergeFunctionDecl()
3065 Diag(Old->getFirstDecl()->getLocation(), in MergeFunctionDecl()
3071 // return type and the parameter-type-list. in MergeFunctionDecl()
3093 if (New->getFriendObjectKind() != Decl::FOK_None) { in MergeFunctionDecl()
3094 Diag(New->getLocation(), diag::ext_retained_language_linkage) << New; in MergeFunctionDecl()
3097 Diag(New->getLocation(), diag::err_different_language_linkage) << New; in MergeFunctionDecl()
3106 if ((NewQType->isDependentType() || OldQType->isDependentType()) && in MergeFunctionDecl()
3107 New->isLocalExternDecl()) { in MergeFunctionDecl()
3121 const FunctionType *OldFuncType = OldQType->getAs<FunctionType>(); in MergeFunctionDecl()
3122 const FunctionType *NewFuncType = NewQType->getAs<FunctionType>(); in MergeFunctionDecl()
3128 assert(!OldProto->hasExceptionSpec() && "Exception spec in C"); in MergeFunctionDecl()
3129 SmallVector<QualType, 16> ParamTypes(OldProto->param_types()); in MergeFunctionDecl()
3131 Context.getFunctionType(NewFuncType->getReturnType(), ParamTypes, in MergeFunctionDecl()
3132 OldProto->getExtProtoInfo()); in MergeFunctionDecl()
3133 New->setType(NewQType); in MergeFunctionDecl()
3134 New->setHasInheritedPrototype(); in MergeFunctionDecl()
3138 for (const auto &ParamType : OldProto->param_types()) { in MergeFunctionDecl()
3143 Param->setScopeInfo(0, Params.size()); in MergeFunctionDecl()
3144 Param->setImplicit(); in MergeFunctionDecl()
3148 New->setParams(Params); in MergeFunctionDecl()
3161 // If a variadic prototype is followed by a non-variadic K&R definition, in MergeFunctionDecl()
3166 Old->hasPrototype() && !New->hasPrototype() && in MergeFunctionDecl()
3167 New->getType()->getAs<FunctionProtoType>() && in MergeFunctionDecl()
3168 Old->getNumParams() == New->getNumParams()) { in MergeFunctionDecl()
3172 = Old->getType()->getAs<FunctionProtoType>(); in MergeFunctionDecl()
3174 = New->getType()->getAs<FunctionProtoType>(); in MergeFunctionDecl()
3177 QualType MergedReturn = Context.mergeTypes(OldProto->getReturnType(), in MergeFunctionDecl()
3178 NewProto->getReturnType()); in MergeFunctionDecl()
3180 for (unsigned Idx = 0, End = Old->getNumParams(); in MergeFunctionDecl()
3182 ParmVarDecl *OldParm = Old->getParamDecl(Idx); in MergeFunctionDecl()
3183 ParmVarDecl *NewParm = New->getParamDecl(Idx); in MergeFunctionDecl()
3184 if (Context.typesAreCompatible(OldParm->getType(), in MergeFunctionDecl()
3185 NewProto->getParamType(Idx))) { in MergeFunctionDecl()
3186 ArgTypes.push_back(NewParm->getType()); in MergeFunctionDecl()
3187 } else if (Context.typesAreCompatible(OldParm->getType(), in MergeFunctionDecl()
3188 NewParm->getType(), in MergeFunctionDecl()
3191 NewProto->getParamType(Idx) }; in MergeFunctionDecl()
3193 ArgTypes.push_back(NewParm->getType()); in MergeFunctionDecl()
3200 Diag(Warnings[Warn].NewParm->getLocation(), in MergeFunctionDecl()
3203 << Warnings[Warn].OldParm->getType(); in MergeFunctionDecl()
3204 if (Warnings[Warn].OldParm->getLocation().isValid()) in MergeFunctionDecl()
3205 Diag(Warnings[Warn].OldParm->getLocation(), in MergeFunctionDecl()
3210 New->setType(Context.getFunctionType(MergedReturn, ArgTypes, in MergeFunctionDecl()
3211 OldProto->getExtProtoInfo())); in MergeFunctionDecl()
3221 // If the previous declaration was an implicitly-generated builtin in MergeFunctionDecl()
3224 if (Old->isImplicit() && (BuiltinID = Old->getBuiltinID())) { in MergeFunctionDecl()
3225 // If it's actually a library-defined builtin function like 'malloc' in MergeFunctionDecl()
3228 Diag(New->getLocation(), diag::warn_redecl_library_builtin) << New; in MergeFunctionDecl()
3230 << Old << Old->getType(); in MergeFunctionDecl()
3233 // about the "builtin-ness" of the function. in MergeFunctionDecl()
3240 if (!New->getLexicalDeclContext()->isFunctionOrMethod()) in MergeFunctionDecl()
3241 New->getIdentifier()->revertBuiltin(); in MergeFunctionDecl()
3249 Diag(New->getLocation(), diag::err_conflicting_types) << New->getDeclName(); in MergeFunctionDecl()
3250 Diag(OldLocation, PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
3269 if (Old->isPure()) in MergeCompatibleFunctionDecls()
3270 New->setPure(); in MergeCompatibleFunctionDecls()
3273 if (Old->getMostRecentDecl()->isUsed(false)) in MergeCompatibleFunctionDecls()
3274 New->setIsUsed(); in MergeCompatibleFunctionDecls()
3278 if (New->getNumParams() == Old->getNumParams()) in MergeCompatibleFunctionDecls()
3279 for (unsigned i = 0, e = New->getNumParams(); i != e; ++i) { in MergeCompatibleFunctionDecls()
3280 ParmVarDecl *NewParam = New->getParamDecl(i); in MergeCompatibleFunctionDecls()
3281 ParmVarDecl *OldParam = Old->getParamDecl(i); in MergeCompatibleFunctionDecls()
3292 QualType Merged = Context.mergeTypes(Old->getType(), New->getType()); in MergeCompatibleFunctionDecls()
3294 New->setType(Merged); in MergeCompatibleFunctionDecls()
3303 isa<ObjCProtocolDecl>(oldMethod->getDeclContext()) in mergeObjCMethodDecls()
3305 : isa<ObjCImplDecl>(newMethod->getDeclContext()) ? AMK_Redeclaration in mergeObjCMethodDecls()
3311 ObjCMethodDecl::param_const_iterator oi = oldMethod->param_begin(), in mergeObjCMethodDecls()
3312 oe = oldMethod->param_end(); in mergeObjCMethodDecls()
3314 ni = newMethod->param_begin(), ne = newMethod->param_end(); in mergeObjCMethodDecls()
3322 assert(!S.Context.hasSameType(New->getType(), Old->getType())); in diagnoseVarDeclTypeMismatch()
3324 S.Diag(New->getLocation(), New->isThisDeclarationADefinition() in diagnoseVarDeclTypeMismatch()
3327 << New->getDeclName() << New->getType() << Old->getType(); in diagnoseVarDeclTypeMismatch()
3334 New->setInvalidDecl(); in diagnoseVarDeclTypeMismatch()
3337 /// MergeVarDeclTypes - We parsed a variable 'New' which has the same name and
3346 if (New->isInvalidDecl() || Old->isInvalidDecl()) in MergeVarDeclTypes()
3351 if (New->getType()->isUndeducedType()) { in MergeVarDeclTypes()
3354 } else if (Context.hasSameType(New->getType(), Old->getType())) { in MergeVarDeclTypes()
3363 else if (Old->getType()->isArrayType() && New->getType()->isArrayType()) { in MergeVarDeclTypes()
3364 const ArrayType *OldArray = Context.getAsArrayType(Old->getType()); in MergeVarDeclTypes()
3365 const ArrayType *NewArray = Context.getAsArrayType(New->getType()); in MergeVarDeclTypes()
3370 if (!NewArray->isIncompleteArrayType()) { in MergeVarDeclTypes()
3371 for (VarDecl *PrevVD = Old->getMostRecentDecl(); PrevVD; in MergeVarDeclTypes()
3372 PrevVD = PrevVD->getPreviousDecl()) { in MergeVarDeclTypes()
3373 const ArrayType *PrevVDTy = Context.getAsArrayType(PrevVD->getType()); in MergeVarDeclTypes()
3374 if (PrevVDTy->isIncompleteArrayType()) in MergeVarDeclTypes()
3382 if (OldArray->isIncompleteArrayType() && NewArray->isArrayType()) { in MergeVarDeclTypes()
3383 if (Context.hasSameType(OldArray->getElementType(), in MergeVarDeclTypes()
3384 NewArray->getElementType())) in MergeVarDeclTypes()
3385 MergedT = New->getType(); in MergeVarDeclTypes()
3390 else if (OldArray->isArrayType() && NewArray->isIncompleteArrayType()) { in MergeVarDeclTypes()
3391 if (Context.hasSameType(OldArray->getElementType(), in MergeVarDeclTypes()
3392 NewArray->getElementType())) in MergeVarDeclTypes()
3393 MergedT = Old->getType(); in MergeVarDeclTypes()
3396 else if (New->getType()->isObjCObjectPointerType() && in MergeVarDeclTypes()
3397 Old->getType()->isObjCObjectPointerType()) { in MergeVarDeclTypes()
3398 MergedT = Context.mergeObjCGCQualifiers(New->getType(), in MergeVarDeclTypes()
3399 Old->getType()); in MergeVarDeclTypes()
3405 MergedT = Context.mergeTypes(New->getType(), Old->getType()); in MergeVarDeclTypes()
3409 // block-scope variable. In other cases (static data members of class in MergeVarDeclTypes()
3413 if ((New->getType()->isDependentType() || in MergeVarDeclTypes()
3414 Old->getType()->isDependentType()) && New->isLocalVarDecl()) { in MergeVarDeclTypes()
3418 if (!New->getType()->isDependentType() && MergeTypeWithOld) in MergeVarDeclTypes()
3419 New->setType(Context.DependentTy); in MergeVarDeclTypes()
3428 New->setType(MergedT); in MergeVarDeclTypes()
3449 return NewVD->isPreviousDeclInSameBlockScope() || in mergeTypeWithPrevious()
3450 (!OldVD->getLexicalDeclContext()->isFunctionOrMethod() && in mergeTypeWithPrevious()
3451 !NewVD->getLexicalDeclContext()->isFunctionOrMethod()); in mergeTypeWithPrevious()
3453 // If the old declaration was function-local, don't merge with its in mergeTypeWithPrevious()
3455 return !OldVD->getLexicalDeclContext()->isFunctionOrMethod() || in mergeTypeWithPrevious()
3456 OldVD->getLexicalDeclContext() == NewVD->getLexicalDeclContext(); in mergeTypeWithPrevious()
3460 /// MergeVarDecl - We just parsed a variable 'New' which has the same name
3470 if (New->isInvalidDecl()) in MergeVarDecl()
3476 VarTemplateDecl *NewTemplate = New->getDescribedVarTemplate(); in MergeVarDecl()
3484 Old = OldTemplate ? OldTemplate->getTemplatedDecl() : nullptr; in MergeVarDecl()
3489 return New->setInvalidDecl(); in MergeVarDecl()
3496 return New->setInvalidDecl(); in MergeVarDecl()
3500 Diag(New->getLocation(), diag::err_redefinition_different_kind) in MergeVarDecl()
3501 << New->getDeclName(); in MergeVarDecl()
3502 Diag(Previous.getRepresentativeDecl()->getLocation(), in MergeVarDecl()
3504 return New->setInvalidDecl(); in MergeVarDecl()
3509 !TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(), in MergeVarDecl()
3510 OldTemplate->getTemplateParameters(), in MergeVarDecl()
3512 return New->setInvalidDecl(); in MergeVarDecl()
3515 // A member shall not be declared twice in the member-specification [...] in MergeVarDecl()
3518 if (Old->isStaticDataMember() && !New->isOutOfLine()) { in MergeVarDecl()
3519 Diag(New->getLocation(), diag::err_duplicate_member) in MergeVarDecl()
3520 << New->getIdentifier(); in MergeVarDecl()
3521 Diag(Old->getLocation(), diag::note_previous_declaration); in MergeVarDecl()
3522 New->setInvalidDecl(); in MergeVarDecl()
3526 // Warn if an already-declared variable is made a weak_import in a subsequent in MergeVarDecl()
3528 if (New->hasAttr<WeakImportAttr>() && in MergeVarDecl()
3529 Old->getStorageClass() == SC_None && in MergeVarDecl()
3530 !Old->hasAttr<WeakImportAttr>()) { in MergeVarDecl()
3531 Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName(); in MergeVarDecl()
3532 Diag(Old->getLocation(), diag::note_previous_definition); in MergeVarDecl()
3534 New->dropAttr<WeakImportAttr>(); in MergeVarDecl()
3537 if (New->hasAttr<InternalLinkageAttr>() && in MergeVarDecl()
3538 !Old->hasAttr<InternalLinkageAttr>()) { in MergeVarDecl()
3539 Diag(New->getLocation(), diag::err_internal_linkage_redeclaration) in MergeVarDecl()
3540 << New->getDeclName(); in MergeVarDecl()
3541 Diag(Old->getLocation(), diag::note_previous_definition); in MergeVarDecl()
3542 New->dropAttr<InternalLinkageAttr>(); in MergeVarDecl()
3546 VarDecl *MostRecent = Old->getMostRecentDecl(); in MergeVarDecl()
3550 if (New->isInvalidDecl()) in MergeVarDecl()
3555 if (New->isInvalidDecl()) in MergeVarDecl()
3563 // [dcl.stc]p8: Check if we have a non-static decl followed by a static. in MergeVarDecl()
3564 if (New->getStorageClass() == SC_Static && in MergeVarDecl()
3565 !New->isStaticDataMember() && in MergeVarDecl()
3566 Old->hasExternalFormalLinkage()) { in MergeVarDecl()
3568 Diag(New->getLocation(), diag::ext_static_non_static) in MergeVarDecl()
3569 << New->getDeclName(); in MergeVarDecl()
3572 Diag(New->getLocation(), diag::err_static_non_static) in MergeVarDecl()
3573 << New->getDeclName(); in MergeVarDecl()
3575 return New->setInvalidDecl(); in MergeVarDecl()
3579 // For an identifier declared with the storage-class specifier in MergeVarDecl()
3587 if (New->hasExternalStorage() && Old->hasLinkage()) in MergeVarDecl()
3589 else if (New->getCanonicalDecl()->getStorageClass() != SC_Static && in MergeVarDecl()
3590 !New->isStaticDataMember() && in MergeVarDecl()
3591 Old->getCanonicalDecl()->getStorageClass() == SC_Static) { in MergeVarDecl()
3592 Diag(New->getLocation(), diag::err_non_static_static) << New->getDeclName(); in MergeVarDecl()
3594 return New->setInvalidDecl(); in MergeVarDecl()
3597 // Check if extern is followed by non-extern and vice-versa. in MergeVarDecl()
3598 if (New->hasExternalStorage() && in MergeVarDecl()
3599 !Old->hasLinkage() && Old->isLocalVarDeclOrParm()) { in MergeVarDecl()
3600 Diag(New->getLocation(), diag::err_extern_non_extern) << New->getDeclName(); in MergeVarDecl()
3602 return New->setInvalidDecl(); in MergeVarDecl()
3604 if (Old->hasLinkage() && New->isLocalVarDeclOrParm() && in MergeVarDecl()
3605 !New->hasExternalStorage()) { in MergeVarDecl()
3606 Diag(New->getLocation(), diag::err_non_extern_extern) << New->getDeclName(); in MergeVarDecl()
3608 return New->setInvalidDecl(); in MergeVarDecl()
3615 if (!New->hasExternalStorage() && !New->isFileVarDecl() && in MergeVarDecl()
3616 // Don't complain about out-of-line definitions of static members. in MergeVarDecl()
3617 !(Old->getLexicalDeclContext()->isRecord() && in MergeVarDecl()
3618 !New->getLexicalDeclContext()->isRecord())) { in MergeVarDecl()
3619 Diag(New->getLocation(), diag::err_redefinition) << New->getDeclName(); in MergeVarDecl()
3621 return New->setInvalidDecl(); in MergeVarDecl()
3624 if (New->isInline() && !Old->getMostRecentDecl()->isInline()) { in MergeVarDecl()
3625 if (VarDecl *Def = Old->getDefinition()) { in MergeVarDecl()
3628 // its first declaration as inline, the program is ill-formed. in MergeVarDecl()
3629 Diag(New->getLocation(), diag::err_inline_decl_follows_def) << New; in MergeVarDecl()
3630 Diag(Def->getLocation(), diag::note_previous_definition); in MergeVarDecl()
3636 if (!Old->isInline() && New->isInline() && Old->isUsed(false) && in MergeVarDecl()
3637 !Old->getDefinition() && !New->isThisDeclarationADefinition()) in MergeVarDecl()
3638 UndefinedButUsed.insert(std::make_pair(Old->getCanonicalDecl(), in MergeVarDecl()
3641 if (New->getTLSKind() != Old->getTLSKind()) { in MergeVarDecl()
3642 if (!Old->getTLSKind()) { in MergeVarDecl()
3643 Diag(New->getLocation(), diag::err_thread_non_thread) << New->getDeclName(); in MergeVarDecl()
3645 } else if (!New->getTLSKind()) { in MergeVarDecl()
3646 Diag(New->getLocation(), diag::err_non_thread_thread) << New->getDeclName(); in MergeVarDecl()
3653 Diag(New->getLocation(), diag::err_thread_thread_different_kind) in MergeVarDecl()
3654 << New->getDeclName() << (New->getTLSKind() == VarDecl::TLS_Dynamic); in MergeVarDecl()
3662 New->isThisDeclarationADefinition() == VarDecl::Definition && in MergeVarDecl()
3663 (Def = Old->getDefinition())) { in MergeVarDecl()
3666 (New->getFormalLinkage() == InternalLinkage || in MergeVarDecl()
3667 New->getDescribedVarTemplate() || in MergeVarDecl()
3668 New->getNumTemplateParameterLists() || in MergeVarDecl()
3669 New->getDeclContext()->isDependentContext())) { in MergeVarDecl()
3672 } else if (Old->isStaticDataMember() && in MergeVarDecl()
3673 Old->getCanonicalDecl()->isInline() && in MergeVarDecl()
3674 Old->getCanonicalDecl()->isConstexpr()) { in MergeVarDecl()
3676 Diag(New->getLocation(), in MergeVarDecl()
3679 Diag(New->getLocation(), diag::err_redefinition) << New; in MergeVarDecl()
3680 Diag(Def->getLocation(), diag::note_previous_definition); in MergeVarDecl()
3681 New->setInvalidDecl(); in MergeVarDecl()
3687 Diag(New->getLocation(), diag::err_different_language_linkage) << New; in MergeVarDecl()
3689 New->setInvalidDecl(); in MergeVarDecl()
3694 if (Old->getMostRecentDecl()->isUsed(false)) in MergeVarDecl()
3695 New->setIsUsed(); in MergeVarDecl()
3698 New->setPreviousDecl(Old); in MergeVarDecl()
3700 NewTemplate->setPreviousDecl(OldTemplate); in MergeVarDecl()
3703 New->setAccess(Old->getAccess()); in MergeVarDecl()
3705 NewTemplate->setAccess(New->getAccess()); in MergeVarDecl()
3707 if (Old->isInline()) in MergeVarDecl()
3708 New->setImplicitlyInline(); in MergeVarDecl()
3711 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
3728 ? S->getMSCurManglingNumber() in getMSManglingNumber()
3729 : S->getMSLastManglingNumber(); in getMSManglingNumber()
3736 if (isa<CXXRecordDecl>(Tag->getParent())) { in handleTagNumbering()
3739 if (!Tag->getName().empty() || Tag->getTypedefNameForAnonDecl()) in handleTagNumbering()
3742 Context.getManglingNumberContext(Tag->getParent()); in handleTagNumbering()
3752 Tag->getDeclContext(), ManglingContextDecl)) { in handleTagNumbering()
3754 Tag, MCtx->getManglingNumber( in handleTagNumbering()
3761 if (TagFromDeclSpec->isInvalidDecl()) in setTagNameForLinkagePurposes()
3765 if (TagFromDeclSpec->hasNameForLinkage()) in setTagNameForLinkagePurposes()
3768 // A well-formed anonymous tag must always be a TUK_Definition. in setTagNameForLinkagePurposes()
3769 assert(TagFromDeclSpec->isThisDeclarationADefinition()); in setTagNameForLinkagePurposes()
3772 if (!Context.hasSameType(NewTD->getUnderlyingType(), in setTagNameForLinkagePurposes()
3785 if (TagFromDeclSpec->hasLinkageBeenComputed()) { in setTagNameForLinkagePurposes()
3786 Diag(NewTD->getLocation(), diag::err_typedef_changes_linkage); in setTagNameForLinkagePurposes()
3788 SourceLocation tagLoc = TagFromDeclSpec->getInnerLocStart(); in setTagNameForLinkagePurposes()
3793 textToInsert += NewTD->getIdentifier()->getName(); in setTagNameForLinkagePurposes()
3799 // Otherwise, set this is the anon-decl typedef for the tag. in setTagNameForLinkagePurposes()
3800 TagFromDeclSpec->setTypedefNameForAnonDecl(NewTD); in setTagNameForLinkagePurposes()
3820 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
3846 Tag = CTD->getTemplatedDecl(); in ParsedFreeStandingDeclSpec()
3851 Tag->setFreeStanding(); in ParsedFreeStandingDeclSpec()
3852 if (Tag->isInvalidDecl()) in ParsedFreeStandingDeclSpec()
3858 // or incomplete types shall not be restrict-qualified." in ParsedFreeStandingDeclSpec()
3901 !TemplateParams.empty() && TemplateParams.back()->size() == 0; in ParsedFreeStandingDeclSpec()
3902 if (Tag && SS.isNotEmpty() && !Tag->isCompleteDefinition() && in ParsedFreeStandingDeclSpec()
3906 // nested-name-specifier unless it is an explicit instantiation in ParsedFreeStandingDeclSpec()
3912 // Per C++ [dcl.enum]p1, an opaque-enum-declaration can't either. in ParsedFreeStandingDeclSpec()
3918 // Track whether this decl-specifier declares anything. in ParsedFreeStandingDeclSpec()
3923 if (!Record->getDeclName() && Record->isCompleteDefinition() && in ParsedFreeStandingDeclSpec()
3926 Record->getDeclContext()->isRecord()) { in ParsedFreeStandingDeclSpec()
3934 if (CurContext->isFunctionOrMethod()) in ParsedFreeStandingDeclSpec()
3945 // A struct-declaration that does not declare an anonymous structure or in ParsedFreeStandingDeclSpec()
3946 // anonymous union shall contain a struct-declarator-list. in ParsedFreeStandingDeclSpec()
3948 // This rule also existed in C89 and C99; the grammar for struct-declaration in ParsedFreeStandingDeclSpec()
3949 // did not permit a struct-declaration without a struct-declarator-list. in ParsedFreeStandingDeclSpec()
3950 if (!getLangOpts().CPlusPlus && CurContext->isRecord() && in ParsedFreeStandingDeclSpec()
3957 // STRUCT_TYPE; <- where STRUCT_TYPE is a typedef struct. in ParsedFreeStandingDeclSpec()
3958 // UNION_TYPE; <- where UNION_TYPE is a typedef union. in ParsedFreeStandingDeclSpec()
3959 if ((Tag && Tag->getDeclName()) || in ParsedFreeStandingDeclSpec()
3965 DS.getRepAsType().get()->getAsStructureType()) in ParsedFreeStandingDeclSpec()
3966 Record = RT->getDecl(); in ParsedFreeStandingDeclSpec()
3967 else if (const RecordType *UT = DS.getRepAsType().get()->getAsUnionType()) in ParsedFreeStandingDeclSpec()
3968 Record = UT->getDecl(); in ParsedFreeStandingDeclSpec()
3972 << Record->isUnion() << DS.getSourceRange(); in ParsedFreeStandingDeclSpec()
3982 (TagD && TagD->isInvalidDecl())) in ParsedFreeStandingDeclSpec()
3988 if (Enum->enumerator_begin() == Enum->enumerator_end() && in ParsedFreeStandingDeclSpec()
3989 !Enum->getIdentifier() && !Enum->isInvalidDecl()) in ParsedFreeStandingDeclSpec()
4002 Tag && Tag->getDeclContext()->isFunctionOrMethod()) in ParsedFreeStandingDeclSpec()
4004 << Tag->getTagKind() in ParsedFreeStandingDeclSpec()
4014 // unnamed bit-field, the decl-specifier-seq shall introduce one or more in ParsedFreeStandingDeclSpec()
4025 // If a storage-class-specifier appears in a decl-specifier-seq, [...] the in ParsedFreeStandingDeclSpec()
4026 // init-declarator-list of the declaration shall not be empty. in ParsedFreeStandingDeclSpec()
4028 // If a cv-qualifier appears in a decl-specifier-seq, the in ParsedFreeStandingDeclSpec()
4029 // init-declarator-list of the declaration shall not be empty. in ParsedFreeStandingDeclSpec()
4036 // Note that a linkage-specification sets a storage class, but in ParsedFreeStandingDeclSpec()
4075 attrs = attrs->getNext()) in ParsedFreeStandingDeclSpec()
4076 Diag(attrs->getLoc(), diag::warn_declspec_attribute_ignored) in ParsedFreeStandingDeclSpec()
4077 << attrs->getName() << GetDiagnosticTypeSpecifierID(TypeSpecType); in ParsedFreeStandingDeclSpec()
4099 NamedDecl *PrevDecl = R.getRepresentativeDecl()->getUnderlyingDecl(); in CheckAnonMemberRedeclaration()
4100 assert(PrevDecl && "Expected a non-null Decl"); in CheckAnonMemberRedeclaration()
4107 SemaRef.Diag(PrevDecl->getLocation(), diag::note_previous_declaration); in CheckAnonMemberRedeclaration()
4112 /// InjectAnonymousStructOrUnionMembers - Inject the members of the
4135 for (auto *D : AnonRecord->decls()) { in InjectAnonymousStructOrUnionMembers()
4137 cast<NamedDecl>(D)->getDeclName()) { in InjectAnonymousStructOrUnionMembers()
4139 if (CheckAnonMemberRedeclaration(SemaRef, S, Owner, VD->getDeclName(), in InjectAnonymousStructOrUnionMembers()
4140 VD->getLocation(), in InjectAnonymousStructOrUnionMembers()
4141 AnonRecord->isUnion())) { in InjectAnonymousStructOrUnionMembers()
4155 Chaining.append(IF->chain_begin(), IF->chain_end()); in InjectAnonymousStructOrUnionMembers()
4166 SemaRef.Context, Owner, VD->getLocation(), VD->getIdentifier(), in InjectAnonymousStructOrUnionMembers()
4167 VD->getType(), {NamedChain, Chaining.size()}); in InjectAnonymousStructOrUnionMembers()
4169 for (const auto *Attr : VD->attrs()) in InjectAnonymousStructOrUnionMembers()
4170 IndirectField->addAttr(Attr->clone(SemaRef.Context)); in InjectAnonymousStructOrUnionMembers()
4172 IndirectField->setAccess(AS); in InjectAnonymousStructOrUnionMembers()
4173 IndirectField->setImplicit(); in InjectAnonymousStructOrUnionMembers()
4177 if (AS != AS_none) IndirectField->setAccess(AS); in InjectAnonymousStructOrUnionMembers()
4187 /// StorageClassSpecToVarDeclStorageClass - Maps a DeclSpec::SCS to
4213 assert(Record->hasInClassInitializer()); in findDefaultInitializer()
4215 for (const auto *I : Record->decls()) { in findDefaultInitializer()
4218 FD = IFD->getAnonField(); in findDefaultInitializer()
4219 if (FD && FD->hasInClassInitializer()) in findDefaultInitializer()
4220 return FD->getLocation(); in findDefaultInitializer()
4223 llvm_unreachable("couldn't find in-class initializer"); in findDefaultInitializer()
4228 if (!Parent->isUnion() || !Parent->hasInClassInitializer()) in checkDuplicateDefaultInit()
4237 if (!Parent->isUnion() || !Parent->hasInClassInitializer()) in checkDuplicateDefaultInit()
4243 /// BuildAnonymousStructOrUnion - Handle the declaration of an
4251 DeclContext *Owner = Record->getDeclContext(); in BuildAnonymousStructOrUnion()
4254 if (Record->isUnion() && !getLangOpts().CPlusPlus && !getLangOpts().C11) in BuildAnonymousStructOrUnion()
4255 Diag(Record->getLocation(), diag::ext_anonymous_union); in BuildAnonymousStructOrUnion()
4256 else if (!Record->isUnion() && getLangOpts().CPlusPlus) in BuildAnonymousStructOrUnion()
4257 Diag(Record->getLocation(), diag::ext_gnu_anonymous_struct); in BuildAnonymousStructOrUnion()
4258 else if (!Record->isUnion() && !getLangOpts().C11) in BuildAnonymousStructOrUnion()
4259 Diag(Record->getLocation(), diag::ext_c11_anonymous_struct); in BuildAnonymousStructOrUnion()
4267 if (Record->isUnion()) { in BuildAnonymousStructOrUnion()
4274 cast<NamespaceDecl>(Owner)->getDeclName()))) { in BuildAnonymousStructOrUnion()
4275 Diag(Record->getLocation(), diag::err_anonymous_union_not_static) in BuildAnonymousStructOrUnion()
4276 << FixItHint::CreateInsertion(Record->getLocation(), "static "); in BuildAnonymousStructOrUnion()
4302 << Record->isUnion() << "const" in BuildAnonymousStructOrUnion()
4307 << Record->isUnion() << "volatile" in BuildAnonymousStructOrUnion()
4312 << Record->isUnion() << "restrict" in BuildAnonymousStructOrUnion()
4317 << Record->isUnion() << "_Atomic" in BuildAnonymousStructOrUnion()
4322 << Record->isUnion() << "__unaligned" in BuildAnonymousStructOrUnion()
4329 // The member-specification of an anonymous union shall only in BuildAnonymousStructOrUnion()
4330 // define non-static data members. [Note: nested types and in BuildAnonymousStructOrUnion()
4332 for (auto *Mem : Record->decls()) { in BuildAnonymousStructOrUnion()
4337 assert(FD->getAccess() != AS_none); in BuildAnonymousStructOrUnion()
4338 if (FD->getAccess() != AS_public) { in BuildAnonymousStructOrUnion()
4339 Diag(FD->getLocation(), diag::err_anonymous_record_nonpublic_member) in BuildAnonymousStructOrUnion()
4340 << Record->isUnion() << (FD->getAccess() == AS_protected); in BuildAnonymousStructOrUnion()
4345 // An object of a class with a non-trivial constructor, a non-trivial in BuildAnonymousStructOrUnion()
4346 // copy constructor, a non-trivial destructor, or a non-trivial copy in BuildAnonymousStructOrUnion()
4351 } else if (Mem->isImplicit()) { in BuildAnonymousStructOrUnion()
4353 } else if (isa<TagDecl>(Mem) && Mem->getDeclContext() != Record) { in BuildAnonymousStructOrUnion()
4355 // elaborated-type-specifier inside the anonymous struct or in BuildAnonymousStructOrUnion()
4359 if (!MemRecord->isAnonymousStructOrUnion() && in BuildAnonymousStructOrUnion()
4360 MemRecord->getDeclName()) { in BuildAnonymousStructOrUnion()
4363 Diag(MemRecord->getLocation(), diag::ext_anonymous_record_with_type) in BuildAnonymousStructOrUnion()
4364 << Record->isUnion(); in BuildAnonymousStructOrUnion()
4367 Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type) in BuildAnonymousStructOrUnion()
4368 << Record->isUnion(); in BuildAnonymousStructOrUnion()
4375 Diag(MemRecord->getLocation(), in BuildAnonymousStructOrUnion()
4377 << Record->isUnion(); in BuildAnonymousStructOrUnion()
4384 // We have something that isn't a non-static data in BuildAnonymousStructOrUnion()
4397 Diag(Mem->getLocation(), diag::ext_anonymous_record_with_type) in BuildAnonymousStructOrUnion()
4398 << Record->isUnion(); in BuildAnonymousStructOrUnion()
4400 Diag(Mem->getLocation(), DK) << Record->isUnion(); in BuildAnonymousStructOrUnion()
4408 // brace-or-equal-initializer. in BuildAnonymousStructOrUnion()
4409 if (cast<CXXRecordDecl>(Record)->hasInClassInitializer() && in BuildAnonymousStructOrUnion()
4410 Owner->isRecord()) in BuildAnonymousStructOrUnion()
4415 if (!Record->isUnion() && !Owner->isRecord()) { in BuildAnonymousStructOrUnion()
4416 Diag(Record->getLocation(), diag::err_anonymous_struct_not_member) in BuildAnonymousStructOrUnion()
4431 Record->getLocation(), in BuildAnonymousStructOrUnion()
4437 Anon->setAccess(AS); in BuildAnonymousStructOrUnion()
4439 FieldCollector->Add(cast<FieldDecl>(Anon)); in BuildAnonymousStructOrUnion()
4444 // mutable can only appear on non-static class members, so it's always in BuildAnonymousStructOrUnion()
4446 Diag(Record->getLocation(), diag::err_mutable_nonmember); in BuildAnonymousStructOrUnion()
4453 Record->getLocation(), /*IdentifierInfo=*/nullptr, in BuildAnonymousStructOrUnion()
4457 // Default-initialize the implicit variable. This initialization will be in BuildAnonymousStructOrUnion()
4458 // trivial in almost all cases, except if a union member has an in-class in BuildAnonymousStructOrUnion()
4463 Anon->setImplicit(); in BuildAnonymousStructOrUnion()
4466 Record->setAnonymousStructOrUnion(true); in BuildAnonymousStructOrUnion()
4471 Owner->addDecl(Anon); in BuildAnonymousStructOrUnion()
4483 if (getLangOpts().CPlusPlus && NewVD->isStaticLocal()) { in BuildAnonymousStructOrUnion()
4486 NewVD->getDeclContext(), ManglingContextDecl)) { in BuildAnonymousStructOrUnion()
4488 NewVD, MCtx->getManglingNumber( in BuildAnonymousStructOrUnion()
4490 Context.setStaticLocalNumber(NewVD, MCtx->getStaticLocalNumber(NewVD)); in BuildAnonymousStructOrUnion()
4496 Anon->setInvalidDecl(); in BuildAnonymousStructOrUnion()
4501 /// BuildMicrosoftCAnonymousStruct - Handle the declaration of an
4503 /// Ref: http://msdn.microsoft.com/en-us/library/z2cx9y4f.aspx
4536 Anon->setImplicit(); in BuildMicrosoftCAnonymousStruct()
4539 CurContext->addDecl(Anon); in BuildMicrosoftCAnonymousStruct()
4547 RecordDecl *RecordDef = Record->getDefinition(); in BuildMicrosoftCAnonymousStruct()
4548 if (RequireCompleteType(Anon->getLocation(), RecTy, in BuildMicrosoftCAnonymousStruct()
4552 Anon->setInvalidDecl(); in BuildMicrosoftCAnonymousStruct()
4553 ParentDecl->setInvalidDecl(); in BuildMicrosoftCAnonymousStruct()
4559 /// GetNameForDeclarator - Determine the full declaration name for the
4565 /// \brief Retrieves the declaration name from a parsed unqualified-id.
4621 // In well-formed code, we can only have a constructor in GetNameFromUnqualifiedId()
4622 // template-id that refers to the current context, so go there in GetNameFromUnqualifiedId()
4625 if (!CurClass || CurClass->getIdentifier() != Name.TemplateId->Name) in GetNameFromUnqualifiedId()
4631 // FIXME: Check two things: that the template-id names the same type as in GetNameFromUnqualifiedId()
4632 // CurClassType, and that the template-id does not occur when the name in GetNameFromUnqualifiedId()
4656 TemplateName TName = Name.TemplateId->Template.get(); in GetNameFromUnqualifiedId()
4657 SourceLocation TNameLoc = Name.TemplateId->TemplateNameLoc; in GetNameFromUnqualifiedId()
4668 if (Ty->isPointerType() || Ty->isReferenceType()) in getCoreType()
4669 Ty = Ty->getPointeeType(); in getCoreType()
4670 else if (Ty->isArrayType()) in getCoreType()
4671 Ty = Ty->castAsArrayTypeUnsafe()->getElementType(); in getCoreType()
4677 /// hasSimilarParameters - Determine whether the C++ functions Declaration
4679 /// used to improve diagnostics in the case where an out-of-line function
4689 if (Declaration->param_size() != Definition->param_size()) in hasSimilarParameters()
4691 for (unsigned Idx = 0; Idx < Declaration->param_size(); ++Idx) { in hasSimilarParameters()
4692 QualType DeclParamTy = Declaration->getParamDecl(Idx)->getType(); in hasSimilarParameters()
4693 QualType DefParamTy = Definition->getParamDecl(Idx)->getType(); in hasSimilarParameters()
4714 /// NeedsRebuildingInCurrentInstantiation - Checks whether the given
4718 /// and the base type in any member-pointer chunks.
4722 // - typenames, typeofs, and decltypes in RebuildDeclaratorInCurrentInstantiation()
4723 // - types which will become injected class names in RebuildDeclaratorInCurrentInstantiation()
4737 if (T.isNull() || !T->isDependentType()) break; in RebuildDeclaratorInCurrentInstantiation()
4750 ParsedType LocType = S.CreateParsedType(TSI->getType(), TSI); in RebuildDeclaratorInCurrentInstantiation()
4779 // Rebuild the scope specifier in-place. in RebuildDeclaratorInCurrentInstantiation()
4792 if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer() && in ActOnDeclarator()
4793 Dcl && Dcl->getDeclContext()->isFileContext()) in ActOnDeclarator()
4794 Dcl->setTopLevelDeclInObjCContainer(); in ActOnDeclarator()
4799 /// DiagnoseClassNameShadow - Implement C++ [class.mem]p13:
4802 /// - every static data member of class T;
4803 /// - every member function of class T
4804 /// - every member of class T that is itself a type;
4811 while (Record && Record->isAnonymousStructOrUnion()) in DiagnoseClassNameShadow()
4812 Record = dyn_cast<CXXRecordDecl>(Record->getParent()); in DiagnoseClassNameShadow()
4813 if (Record && Record->getIdentifier() && Record->getDeclName() == Name) { in DiagnoseClassNameShadow()
4821 /// \brief Diagnose a declaration whose declarator-id has the given
4822 /// nested-name-specifier.
4824 /// \param SS The nested-name-specifier of the declarator-id.
4826 /// \param DC The declaration context to which the nested-name-specifier
4839 Cur = Cur->getParent(); in diagnoseQualifiedDeclaration()
4848 // Note, it was once ill-formed to give redundant qualification in all in diagnoseQualifiedDeclaration()
4850 if (Cur->Equals(DC)) { in diagnoseQualifiedDeclaration()
4851 if (Cur->isRecord()) { in diagnoseQualifiedDeclaration()
4864 if (!Cur->Encloses(DC)) { in diagnoseQualifiedDeclaration()
4865 if (Cur->isRecord()) in diagnoseQualifiedDeclaration()
4884 if (Cur->isRecord()) { in diagnoseQualifiedDeclaration()
4903 // [...] "The nested-name-specifier of the qualified declarator-id shall in diagnoseQualifiedDeclaration()
4904 // not begin with a decltype-specifer" in diagnoseQualifiedDeclaration()
4909 SpecLoc.getNestedNameSpecifier()->getAsType())) in diagnoseQualifiedDeclaration()
4935 while ((S->getFlags() & Scope::DeclScope) == 0 || in HandleDeclarator()
4936 (S->getFlags() & Scope::TemplateParamScope) != 0) in HandleDeclarator()
4937 S = S->getParent(); in HandleDeclarator()
4960 bool IsDependentContext = DC->isDependentContext(); in HandleDeclarator()
4967 if (isa<CXXRecordDecl>(DC) && !cast<CXXRecordDecl>(DC)->hasDefinition()) { in HandleDeclarator()
4976 if (DC->isRecord()) in HandleDeclarator()
4994 QualType R = TInfo->getType(); in HandleDeclarator()
4996 if (!R->isFunctionType() && DiagnoseClassNameShadow(DC, NameInfo)) in HandleDeclarator()
5017 // linkage (C99 6.2.2p4-5 and C++ [basic.link]p6). in HandleDeclarator()
5024 else if (CurContext->isFunctionOrMethod() && in HandleDeclarator()
5026 R->isFunctionType())) { in HandleDeclarator()
5029 CurContext->getEnclosingNamespaceContext()->isTranslationUnit(); in HandleDeclarator()
5030 } else if (CurContext->getRedeclContext()->isTranslationUnit() && in HandleDeclarator()
5042 // When the declarator-id is qualified, the declaration shall refer to a in HandleDeclarator()
5057 // void X::f(int) { } // ill-formed in HandleDeclarator()
5065 // using-declaration in the scope of the class or namespace nominated by in HandleDeclarator()
5066 // the nested-name-specifier of the declarator-id. in HandleDeclarator()
5071 Previous.getFoundDecl()->isTemplateParameter()) { in HandleDeclarator()
5104 if (!DC->getRedeclContext()->isFileContext()) { in HandleDeclarator()
5121 } else if (R->isFunctionType()) { in HandleDeclarator()
5135 if (New->getDeclName() && AddToScope) { in HandleDeclarator()
5136 // Only make a locally-scoped extern declaration visible if it is the first in HandleDeclarator()
5139 bool AddToContext = !D.isRedeclaration() || !New->isLocalExternDecl(); in HandleDeclarator()
5142 CurContext->addHiddenDecl(New); in HandleDeclarator()
5165 if (T->isDependentType()) in TryToFixInvalidVariablyModifiedType()
5172 QualType Pointee = PTy->getPointeeType(); in TryToFixInvalidVariablyModifiedType()
5181 QualType Inner = PTy->getInnerType(); in TryToFixInvalidVariablyModifiedType()
5194 if (VLATy->getElementType()->isVariablyModifiedType()) in TryToFixInvalidVariablyModifiedType()
5198 if (!VLATy->getSizeExpr() || in TryToFixInvalidVariablyModifiedType()
5199 !VLATy->getSizeExpr()->EvaluateAsInt(Res, Context)) in TryToFixInvalidVariablyModifiedType()
5210 = ConstantArrayType::getNumAddressingBits(Context, VLATy->getElementType(), in TryToFixInvalidVariablyModifiedType()
5217 return Context.getConstantArrayType(VLATy->getElementType(), in TryToFixInvalidVariablyModifiedType()
5259 = TryToFixInvalidVariablyModifiedType(TInfo->getType(), Context, in TryToFixInvalidVariablyModifiedTypeSourceInfo()
5264 FixInvalidVariablyModifiedTypeLoc(TInfo->getTypeLoc(), in TryToFixInvalidVariablyModifiedTypeSourceInfo()
5265 FixedTInfo->getTypeLoc()); in TryToFixInvalidVariablyModifiedTypeSourceInfo()
5269 /// \brief Register the given locally-scoped extern "C" declaration so
5272 /// function-scope declarations.
5276 ND->getLexicalDeclContext()->getRedeclContext()->isTranslationUnit()) in RegisterLocallyScopedExternCDecl()
5280 // Note that we have a locally-scoped external with this name. in RegisterLocallyScopedExternCDecl()
5281 Context.getExternCContextDecl()->makeDeclVisibleInContext(ND); in RegisterLocallyScopedExternCDecl()
5286 auto Result = Context.getExternCContextDecl()->lookup(Name); in findLocallyScopedExternCDecl()
5339 TypedefDecl *NewTD = ParseTypedefDecl(S, D, TInfo->getType(), TInfo); in ActOnTypedefDeclarator()
5359 TypeSourceInfo *TInfo = NewTD->getTypeSourceInfo(); in CheckTypedefForVariablyModifiedType()
5360 QualType T = TInfo->getType(); in CheckTypedefForVariablyModifiedType()
5361 if (T->isVariablyModifiedType()) { in CheckTypedefForVariablyModifiedType()
5362 getCurFunction()->setHasBranchProtectedScope(); in CheckTypedefForVariablyModifiedType()
5364 if (S->getFnParent() == nullptr) { in CheckTypedefForVariablyModifiedType()
5372 Diag(NewTD->getLocation(), diag::warn_illegal_constant_array_size); in CheckTypedefForVariablyModifiedType()
5373 NewTD->setTypeSourceInfo(FixedTInfo); in CheckTypedefForVariablyModifiedType()
5376 Diag(NewTD->getLocation(), diag::err_typecheck_negative_array_size); in CheckTypedefForVariablyModifiedType()
5377 else if (T->isVariableArrayType()) in CheckTypedefForVariablyModifiedType()
5378 Diag(NewTD->getLocation(), diag::err_vla_decl_in_file_scope); in CheckTypedefForVariablyModifiedType()
5380 Diag(NewTD->getLocation(), diag::err_array_too_large) in CheckTypedefForVariablyModifiedType()
5383 Diag(NewTD->getLocation(), diag::err_vm_decl_in_file_scope); in CheckTypedefForVariablyModifiedType()
5384 NewTD->setInvalidDecl(); in CheckTypedefForVariablyModifiedType()
5390 /// ActOnTypedefNameDecl - Perform semantic checking for a declaration which
5391 /// declares a typedef-name, either using the 'typedef' type specifier or via
5392 /// a C++0x [dcl.typedef]p2 alias-declaration: 'using T = A;'.
5407 if (IdentifierInfo *II = NewTD->getIdentifier()) in ActOnTypedefNameDecl()
5408 if (!NewTD->isInvalidDecl() && in ActOnTypedefNameDecl()
5409 NewTD->getDeclContext()->getRedeclContext()->isTranslationUnit()) { in ActOnTypedefNameDecl()
5410 if (II->isStr("FILE")) in ActOnTypedefNameDecl()
5412 else if (II->isStr("jmp_buf")) in ActOnTypedefNameDecl()
5414 else if (II->isStr("sigjmp_buf")) in ActOnTypedefNameDecl()
5416 else if (II->isStr("ucontext_t")) in ActOnTypedefNameDecl()
5423 /// \brief Determines whether the given declaration is an out-of-scope
5431 /// 6.2.2p4-5, C++ [basic.link]p6).
5439 /// \returns true if PrevDecl is an out-of-scope previous declaration
5447 if (!PrevDecl->hasLinkage()) in isOutOfScopePreviousDeclaration()
5457 DeclContext *OuterContext = DC->getRedeclContext(); in isOutOfScopePreviousDeclaration()
5458 if (!OuterContext->isFunctionOrMethod()) in isOutOfScopePreviousDeclaration()
5459 // This rule only applies to block-scope declarations. in isOutOfScopePreviousDeclaration()
5462 DeclContext *PrevOuterContext = PrevDecl->getDeclContext(); in isOutOfScopePreviousDeclaration()
5463 if (PrevOuterContext->isRecord()) in isOutOfScopePreviousDeclaration()
5469 OuterContext = OuterContext->getEnclosingNamespaceContext(); in isOutOfScopePreviousDeclaration()
5470 PrevOuterContext = PrevOuterContext->getEnclosingNamespaceContext(); in isOutOfScopePreviousDeclaration()
5474 if (!OuterContext->Equals(PrevOuterContext)) in isOutOfScopePreviousDeclaration()
5484 DD->setQualifierInfo(SS.getWithLocInContext(DD->getASTContext())); in SetNestedNameSpecifier()
5488 QualType type = decl->getType(); in inferObjCARCLifetime()
5492 unsigned kind = -1U; in inferObjCARCLifetime()
5494 if (var->hasAttr<BlocksAttr>()) in inferObjCARCLifetime()
5496 else if (!var->hasLocalStorage()) in inferObjCARCLifetime()
5504 if (kind != -1U) { in inferObjCARCLifetime()
5505 Diag(decl->getLocation(), diag::err_arc_autoreleasing_var) in inferObjCARCLifetime()
5510 if (!type->isObjCLifetimeType()) in inferObjCARCLifetime()
5513 lifetime = type->getObjCARCImplicitLifetime(); in inferObjCARCLifetime()
5515 decl->setType(type); in inferObjCARCLifetime()
5519 // Thread-local variables cannot have lifetime. in inferObjCARCLifetime()
5521 var->getTLSKind()) { in inferObjCARCLifetime()
5522 Diag(var->getLocation(), diag::err_arc_thread_ownership) in inferObjCARCLifetime()
5523 << var->getType(); in inferObjCARCLifetime()
5539 S.Diag(Attr->getLocation(), diag::err_attribute_weak_static); in checkAttributesAfterMerging()
5545 S.Diag(Attr->getLocation(), diag::err_attribute_weakref_not_static); in checkAttributesAfterMerging()
5552 if (VD->hasInit()) { in checkAttributesAfterMerging()
5553 if (const auto *Attr = VD->getAttr<AliasAttr>()) { in checkAttributesAfterMerging()
5554 assert(VD->isThisDeclarationADefinition() && in checkAttributesAfterMerging()
5555 !VD->isExternallyVisible() && "Broken AliasAttr handled late!"); in checkAttributesAfterMerging()
5556 S.Diag(Attr->getLocation(), diag::err_alias_is_definition) << VD << 0; in checkAttributesAfterMerging()
5557 VD->dropAttr<AliasAttr>(); in checkAttributesAfterMerging()
5566 S.Diag(Attr->getLocation(), in checkAttributesAfterMerging()
5576 if (!ND.isExternallyVisible() || (VD && VD->isStaticLocal())) { in checkAttributesAfterMerging()
5586 if (MD->isVirtual()) { in checkAttributesAfterMerging()
5599 OldDecl = OldTD->getTemplatedDecl(); in checkDLLAttributeRedeclaration()
5604 NewDecl = NewTD->getTemplatedDecl(); in checkDLLAttributeRedeclaration()
5609 const DLLImportAttr *OldImportAttr = OldDecl->getAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
5610 const DLLExportAttr *OldExportAttr = OldDecl->getAttr<DLLExportAttr>(); in checkDLLAttributeRedeclaration()
5611 const DLLImportAttr *NewImportAttr = NewDecl->getAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
5612 const DLLExportAttr *NewExportAttr = NewDecl->getAttr<DLLExportAttr>(); in checkDLLAttributeRedeclaration()
5616 bool HasNewAttr = (NewImportAttr && !NewImportAttr->isInherited()) || in checkDLLAttributeRedeclaration()
5617 (NewExportAttr && !NewExportAttr->isInherited()); in checkDLLAttributeRedeclaration()
5625 if (AddsAttr && !IsSpecialization && !OldDecl->isImplicit()) { in checkDLLAttributeRedeclaration()
5628 if (!OldDecl->isCXXClassMember()) { in checkDLLAttributeRedeclaration()
5630 if (VD && !VD->getDescribedVarTemplate()) in checkDLLAttributeRedeclaration()
5633 if (FD && FD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) in checkDLLAttributeRedeclaration()
5640 if (OldDecl->isUsed()) in checkDLLAttributeRedeclaration()
5646 S.Diag(NewDecl->getLocation(), DiagID) in checkDLLAttributeRedeclaration()
5649 S.Diag(OldDecl->getLocation(), diag::note_previous_declaration); in checkDLLAttributeRedeclaration()
5651 NewDecl->setInvalidDecl(); in checkDLLAttributeRedeclaration()
5663 // Ignore static data because out-of-line definitions are diagnosed in checkDLLAttributeRedeclaration()
5665 IsStaticDataMember = VD->isStaticDataMember(); in checkDLLAttributeRedeclaration()
5666 IsDefinition = VD->isThisDeclarationADefinition(S.Context) != in checkDLLAttributeRedeclaration()
5669 IsInline = FD->isInlined(); in checkDLLAttributeRedeclaration()
5670 IsQualifiedFriend = FD->getQualifier() && in checkDLLAttributeRedeclaration()
5671 FD->getFriendObjectKind() == Decl::FOK_Declared; in checkDLLAttributeRedeclaration()
5675 !NewDecl->isLocalExternDecl() && !IsQualifiedFriend) { in checkDLLAttributeRedeclaration()
5677 S.Diag(NewDecl->getLocation(), in checkDLLAttributeRedeclaration()
5680 S.Diag(OldDecl->getLocation(), diag::note_previous_declaration); in checkDLLAttributeRedeclaration()
5681 NewDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
5682 NewDecl->addAttr(::new (S.Context) DLLExportAttr( in checkDLLAttributeRedeclaration()
5683 NewImportAttr->getRange(), S.Context, in checkDLLAttributeRedeclaration()
5684 NewImportAttr->getSpellingListIndex())); in checkDLLAttributeRedeclaration()
5686 S.Diag(NewDecl->getLocation(), in checkDLLAttributeRedeclaration()
5689 S.Diag(OldDecl->getLocation(), diag::note_previous_declaration); in checkDLLAttributeRedeclaration()
5690 S.Diag(OldImportAttr->getLocation(), diag::note_previous_attribute); in checkDLLAttributeRedeclaration()
5691 OldDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
5692 NewDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
5696 OldDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
5697 NewDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
5698 S.Diag(NewDecl->getLocation(), in checkDLLAttributeRedeclaration()
5711 if (!FD->isInlined()) return false; in isFunctionDefinitionDiscarded()
5714 if (S.getLangOpts().CPlusPlus && !FD->hasAttr<GNUInlineAttr>()) in isFunctionDefinitionDiscarded()
5717 // Okay, go ahead and call the relatively-more-expensive function. in isFunctionDefinitionDiscarded()
5724 FD->setLazyBody(1); in isFunctionDefinitionDiscarded()
5731 FD->setLazyBody(0); in isFunctionDefinitionDiscarded()
5757 if (!D->isInExternCContext() || D->template hasAttr<OverloadableAttr>()) in isIncompleteDeclExternC()
5761 if (S.getLangOpts().CUDA && (D->template hasAttr<CUDADeviceAttr>() || in isIncompleteDeclExternC()
5762 D->template hasAttr<CUDAHostAttr>())) in isIncompleteDeclExternC()
5765 return D->isExternC(); in isIncompleteDeclExternC()
5769 const DeclContext *DC = VD->getDeclContext()->getRedeclContext(); in shouldConsiderLinkage()
5770 if (DC->isFunctionOrMethod() || isa<OMPDeclareReductionDecl>(DC)) in shouldConsiderLinkage()
5771 return VD->hasExternalStorage(); in shouldConsiderLinkage()
5772 if (DC->isFileContext()) in shouldConsiderLinkage()
5774 if (DC->isRecord()) in shouldConsiderLinkage()
5780 const DeclContext *DC = FD->getDeclContext()->getRedeclContext(); in shouldConsiderLinkage()
5781 if (DC->isFileContext() || DC->isFunctionOrMethod() || in shouldConsiderLinkage()
5784 if (DC->isRecord()) in shouldConsiderLinkage()
5791 for (const AttributeList *L = AttrList; L; L = L->getNext()) in hasParsedAttr()
5792 if (L->getKind() == Kind) in hasParsedAttr()
5815 /// function-local external declaration.
5817 if (!DC->isFunctionOrMethod()) in adjustContextForLocalExternDecl()
5823 if (DC->isDependentContext()) in adjustContextForLocalExternDecl()
5832 // semantically-enclosing namespace, not a lexically-enclosing one. in adjustContextForLocalExternDecl()
5833 while (!DC->isFileContext() && !isa<LinkageSpecDecl>(DC)) in adjustContextForLocalExternDecl()
5834 DC = DC->getParent(); in adjustContextForLocalExternDecl()
5841 return FD->isExternC(); in isDeclExternC()
5843 return VD->isExternC(); in isDeclExternC()
5853 QualType R = TInfo->getType(); in ActOnVariableDeclarator()
5856 // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument. in ActOnVariableDeclarator()
5857 // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function in ActOnVariableDeclarator()
5859 if (getLangOpts().OpenCL && (R->isImageType() || R->isPipeType())) { in ActOnVariableDeclarator()
5872 if (SC == SC_None && !DC->isRecord() && in ActOnVariableDeclarator()
5884 while (NR->isPointerType()) { in ActOnVariableDeclarator()
5885 if (NR->isFunctionPointerType()) { in ActOnVariableDeclarator()
5890 NR = NR->getPointeeType(); in ActOnVariableDeclarator()
5896 if (Context.getBaseElementType(R)->isHalfType()) { in ActOnVariableDeclarator()
5904 // mutable can only appear on non-static class members, so it's always in ActOnVariableDeclarator()
5932 if (!DC->isRecord() && S->getFnParent() == nullptr) { in ActOnVariableDeclarator()
5933 // C99 6.9p2: The storage-class specifiers auto and register shall not in ActOnVariableDeclarator()
5946 if (R->isSamplerT() && (R.getAddressSpace() == LangAS::opencl_local || in ActOnVariableDeclarator()
5955 if (R->isEventT()) { in ActOnVariableDeclarator()
5956 if (S->getParent() == nullptr) { in ActOnVariableDeclarator()
5980 if (D.getDeclSpec().containsPlaceholderType() && R->getContainedAutoType()) in ActOnVariableDeclarator()
5984 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
5988 if (DC->isRecord() && !CurContext->isRecord()) { in ActOnVariableDeclarator()
5989 // This is an out-of-line definition of a static data member. in ActOnVariableDeclarator()
6015 if (SC == SC_Static && CurContext->isRecord()) { in ActOnVariableDeclarator()
6017 if (RD->isLocalClass()) in ActOnVariableDeclarator()
6020 << Name << RD->getDeclName(); in ActOnVariableDeclarator()
6023 // the program is ill-formed. C++11 drops this restriction. in ActOnVariableDeclarator()
6024 if (RD->isUnion()) in ActOnVariableDeclarator()
6030 else if (!RD->getDeclName()) in ActOnVariableDeclarator()
6033 << Name << RD->isUnion(); in ActOnVariableDeclarator()
6049 if (!TemplateParams->size() && in ActOnVariableDeclarator()
6053 Diag(TemplateParams->getTemplateLoc(), in ActOnVariableDeclarator()
6056 << SourceRange(TemplateParams->getTemplateLoc(), in ActOnVariableDeclarator()
6057 TemplateParams->getRAngleLoc()); in ActOnVariableDeclarator()
6064 IsPartialSpecialization = TemplateParams->size() > 0; in ActOnVariableDeclarator()
6065 } else { // if (TemplateParams->size() > 0) in ActOnVariableDeclarator()
6089 ? TemplateParamLists[0]->getTemplateLoc() in ActOnVariableDeclarator()
6107 NewVD->setDescribedVarTemplate(NewTemplate); in ActOnVariableDeclarator()
6112 if (D.getDeclSpec().containsPlaceholderType() && R->getContainedAutoType()) in ActOnVariableDeclarator()
6116 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
6118 NewTemplate->setInvalidDecl(); in ActOnVariableDeclarator()
6127 NewVD->setTemplateParameterListsInfo( in ActOnVariableDeclarator()
6131 NewVD->setConstexpr(true); in ActOnVariableDeclarator()
6135 if (NewVD->isStaticDataMember() && getLangOpts().CPlusPlus1z) in ActOnVariableDeclarator()
6136 NewVD->setImplicitlyInline(); in ActOnVariableDeclarator()
6140 if (VarTemplateDecl *VTD = NewVD->getDescribedVarTemplate()) in ActOnVariableDeclarator()
6141 VTD->setConcept(); in ActOnVariableDeclarator()
6150 NewVD->setInvalidDecl(true); in ActOnVariableDeclarator()
6157 NewVD->setInvalidDecl(true); in ActOnVariableDeclarator()
6171 // - The declared type shall have the type bool. in ActOnVariableDeclarator()
6172 if (!Context.hasSameType(NewVD->getType(), Context.BoolTy) && in ActOnVariableDeclarator()
6173 !NewVD->isInvalidDecl()) { in ActOnVariableDeclarator()
6175 NewVD->setInvalidDecl(true); in ActOnVariableDeclarator()
6181 if (CurContext->isFunctionOrMethod()) { in ActOnVariableDeclarator()
6190 NewVD->setInlineSpecified(); in ActOnVariableDeclarator()
6196 NewVD->setLexicalDeclContext(CurContext); in ActOnVariableDeclarator()
6198 NewTemplate->setLexicalDeclContext(CurContext); in ActOnVariableDeclarator()
6201 NewVD->setLocalExternDecl(); in ActOnVariableDeclarator()
6207 // storage-class-specifier static is implied if it does not appear in ActOnVariableDeclarator()
6209 // Core issue: 'static' is not implied if the variable is declared in ActOnVariableDeclarator()
6211 if (NewVD->hasLocalStorage() && in ActOnVariableDeclarator()
6214 !DC->isFunctionOrMethod())) in ActOnVariableDeclarator()
6227 NewVD->setTSCSpec(TSCS); in ActOnVariableDeclarator()
6232 NewVD->setTSCSpec(TSCS); in ActOnVariableDeclarator()
6244 if (SC == SC_Static && S->getFnParent() != nullptr && in ActOnVariableDeclarator()
6245 !NewVD->getType().isConstQualified()) { in ActOnVariableDeclarator()
6256 Diag(NewVD->getLocation(), diag::err_module_private_specialization) in ActOnVariableDeclarator()
6261 Diag(NewVD->getLocation(), diag::err_module_private_specialization) in ActOnVariableDeclarator()
6264 else if (NewVD->hasLocalStorage()) in ActOnVariableDeclarator()
6265 Diag(NewVD->getLocation(), diag::err_module_private_local) in ActOnVariableDeclarator()
6266 << 0 << NewVD->getDeclName() in ActOnVariableDeclarator()
6270 NewVD->setModulePrivate(); in ActOnVariableDeclarator()
6272 NewTemplate->setModulePrivate(); in ActOnVariableDeclarator()
6285 if (SC == SC_None && S->getFnParent() != nullptr && in ActOnVariableDeclarator()
6286 (NewVD->hasAttr<CUDASharedAttr>() || in ActOnVariableDeclarator()
6287 NewVD->hasAttr<CUDAConstantAttr>())) { in ActOnVariableDeclarator()
6288 NewVD->setStorageClass(SC_Static); in ActOnVariableDeclarator()
6295 assert(!NewVD->hasAttr<DLLImportAttr>() || in ActOnVariableDeclarator()
6296 NewVD->getAttr<DLLImportAttr>()->isInherited() || in ActOnVariableDeclarator()
6297 NewVD->isStaticDataMember() || NewVD->getStorageClass() != SC_None); in ActOnVariableDeclarator()
6299 // In auto-retain/release, infer strong retension for variables of in ActOnVariableDeclarator()
6302 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
6304 // Handle GNU asm-label extension (encoded as an attribute). in ActOnVariableDeclarator()
6308 StringRef Label = SE->getString(); in ActOnVariableDeclarator() local
6309 if (S->getFnParent() != nullptr) { in ActOnVariableDeclarator()
6313 Diag(E->getExprLoc(), diag::warn_asm_label_on_auto_decl) << Label; in ActOnVariableDeclarator()
6317 if (!Context.getTargetInfo().isValidGCCRegisterName(Label) && in ActOnVariableDeclarator()
6319 Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label; in ActOnVariableDeclarator()
6332 if (!TI.isValidGCCRegisterName(Label)) in ActOnVariableDeclarator()
6333 Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label; in ActOnVariableDeclarator()
6334 else if (!TI.validateGlobalRegisterVariable(Label, in ActOnVariableDeclarator()
6337 Diag(E->getExprLoc(), diag::err_asm_invalid_global_var_reg) << Label; in ActOnVariableDeclarator()
6339 Diag(E->getExprLoc(), diag::err_asm_register_size_mismatch) << Label; in ActOnVariableDeclarator()
6342 if (!R->isIntegralType(Context) && !R->isPointerType()) { in ActOnVariableDeclarator()
6344 NewVD->setInvalidDecl(true); in ActOnVariableDeclarator()
6348 NewVD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0), in ActOnVariableDeclarator()
6349 Context, Label, 0)); in ActOnVariableDeclarator()
6352 ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier()); in ActOnVariableDeclarator()
6355 NewVD->addAttr(I->second); in ActOnVariableDeclarator()
6358 Diag(NewVD->getLocation(), diag::warn_redefine_extname_not_applied) in ActOnVariableDeclarator()
6368 // scope and are out-of-semantic-context declarations (if the new in ActOnVariableDeclarator()
6378 NewVD->isLocalVarDecl() && NewVD->hasExternalStorage()) in ActOnVariableDeclarator()
6379 NewVD->setPreviousDeclInSameBlockScope( in ActOnVariableDeclarator()
6387 if (IsExplicitSpecialization && !NewVD->isInvalidDecl() && in ActOnVariableDeclarator()
6389 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
6396 // The user tried to define a non-static data member in ActOnVariableDeclarator()
6397 // out-of-line (C++ [dcl.meaning]p1). in ActOnVariableDeclarator()
6398 Diag(NewVD->getLocation(), diag::err_nonstatic_member_out_of_line) in ActOnVariableDeclarator()
6401 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
6408 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
6422 if (VarTmpl->isConcept()) { in ActOnVariableDeclarator()
6423 Diag(NewVD->getLocation(), diag::err_concept_specialized) in ActOnVariableDeclarator()
6427 Diag(VarTmpl->getLocation(), diag::note_previous_declaration); in ActOnVariableDeclarator()
6428 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
6435 NewVD->getPreviousDecl() in ActOnVariableDeclarator()
6436 ? NewVD->getPreviousDecl()->getDescribedVarTemplate() in ActOnVariableDeclarator()
6444 PrevVarTemplate ? PrevVarTemplate->getTemplateParameters() in ActOnVariableDeclarator()
6446 (D.getCXXScopeSpec().isSet() && DC && DC->isRecord() && in ActOnVariableDeclarator()
6447 DC->isDependentContext()) in ActOnVariableDeclarator()
6450 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
6455 PrevVarTemplate->getInstantiatedFromMemberTemplate()) in ActOnVariableDeclarator()
6456 PrevVarTemplate->setMemberSpecialization(); in ActOnVariableDeclarator()
6464 if (NewVD->isFirstDecl() && !NewVD->isInvalidDecl() && in ActOnVariableDeclarator()
6468 if (getLangOpts().CPlusPlus && NewVD->isStaticLocal()) { in ActOnVariableDeclarator()
6471 NewVD->getDeclContext(), ManglingContextDecl)) { in ActOnVariableDeclarator()
6473 NewVD, MCtx->getManglingNumber( in ActOnVariableDeclarator()
6475 Context.setStaticLocalNumber(NewVD, MCtx->getStaticLocalNumber(NewVD)); in ActOnVariableDeclarator()
6480 if (Name.isIdentifier() && Name.getAsIdentifierInfo()->isStr("main") && in ActOnVariableDeclarator()
6481 NewVD->getDeclContext()->getRedeclContext()->isTranslationUnit() && in ActOnVariableDeclarator()
6482 !getLangOpts().Freestanding && !NewVD->getDescribedVarTemplate()) { in ActOnVariableDeclarator()
6485 // A program that declares a variable main at global scope is ill-formed. in ActOnVariableDeclarator()
6489 // In C, and external-linkage variable named main results in undefined in ActOnVariableDeclarator()
6491 else if (NewVD->hasExternalFormalLinkage()) in ActOnVariableDeclarator()
6502 if (NewVD->isInvalidDecl()) in ActOnVariableDeclarator()
6503 NewTemplate->setInvalidDecl(); in ActOnVariableDeclarator()
6519 return OldDC->isFileContext() ? SDK_Global : SDK_Local; in computeShadowedDeclKind()
6522 /// \brief Diagnose variable or built-in function shadowing. Implements
6523 /// -Wshadow.
6537 if (D->hasGlobalStorage()) in CheckShadow()
6540 DeclContext *NewDC = D->getDeclContext(); in CheckShadow()
6553 if (MD->isStatic()) in CheckShadow()
6561 D = D->getCanonicalDecl(); in CheckShadow()
6568 if (shadowedVar->isExternC()) { in CheckShadow()
6571 for (auto I : shadowedVar->redecls()) in CheckShadow()
6572 if (I->isFileVarDecl()) { in CheckShadow()
6578 DeclContext *OldDC = ShadowedDecl->getDeclContext(); in CheckShadow()
6581 if (NewDC && NewDC->isRecord()) { in CheckShadow()
6582 // In particular, don't warn about shadowing non-class members. in CheckShadow()
6583 if (!OldDC->isRecord()) in CheckShadow()
6602 Diag(ShadowedDecl->getLocation(), diag::note_previous_declaration); in CheckShadow()
6605 /// \brief Check -Wshadow without the advantage of a previous lookup.
6607 if (Diags.isIgnored(diag::warn_decl_shadow, D->getLocation())) in CheckShadow()
6610 LookupResult R(*this, D->getDeclName(), D->getLocation(), in CheckShadow()
6622 E = E->IgnoreParenImpCasts(); in CheckShadowingDeclModification()
6626 const NamedDecl *D = cast<NamedDecl>(DRE->getDecl()->getCanonicalDecl()); in CheckShadowingDeclModification()
6630 const NamedDecl *ShadowedDecl = I->second; in CheckShadowingDeclModification()
6631 const DeclContext *OldDC = ShadowedDecl->getDeclContext(); in CheckShadowingDeclModification()
6633 Diag(D->getLocation(), diag::note_var_declared_here) << D; in CheckShadowingDeclModification()
6634 Diag(ShadowedDecl->getLocation(), diag::note_previous_declaration); in CheckShadowingDeclModification()
6646 NamedDecl *Prev = S.findLocallyScopedExternCDecl(ND->getDeclName()); in checkGlobalOrExternCConflict()
6663 // This is a global, non-extern "C" declaration, and there is a previous in checkGlobalOrExternCConflict()
6664 // non-global extern "C" declaration. Diagnose if this is a variable in checkGlobalOrExternCConflict()
6683 S.Context.getTranslationUnitDecl()->lookup(ND->getDeclName()); in checkGlobalOrExternCConflict()
6691 // the declaration is ill-formed, but that is a defect: it breaks the in checkGlobalOrExternCConflict()
6703 // is lexically inside an extern "C" linkage-spec. in checkGlobalOrExternCConflict()
6706 Prev = FD->getFirstDecl(); in checkGlobalOrExternCConflict()
6708 Prev = cast<VarDecl>(Prev)->getFirstDecl(); in checkGlobalOrExternCConflict()
6710 S.Diag(ND->getLocation(), diag::err_extern_c_global_conflict) in checkGlobalOrExternCConflict()
6712 S.Diag(Prev->getLocation(), diag::note_extern_c_global_conflict) in checkGlobalOrExternCConflict()
6731 // we find local extern decls in the surrounding file-scope DeclContext. in checkForConflictWithNonVisibleExternC()
6732 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit()) { in checkForConflictWithNonVisibleExternC()
6733 if (NamedDecl *Prev = S.findLocallyScopedExternCDecl(ND->getDeclName())) { in checkForConflictWithNonVisibleExternC()
6744 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit()) in checkForConflictWithNonVisibleExternC()
6759 if (NewVD->isInvalidDecl()) in CheckVariableDeclarationType()
6762 TypeSourceInfo *TInfo = NewVD->getTypeSourceInfo(); in CheckVariableDeclarationType()
6763 QualType T = TInfo->getType(); in CheckVariableDeclarationType()
6766 if (T->isUndeducedType()) in CheckVariableDeclarationType()
6769 if (NewVD->hasAttrs()) in CheckVariableDeclarationType()
6772 if (T->isObjCObjectType()) { in CheckVariableDeclarationType()
6773 Diag(NewVD->getLocation(), diag::err_statically_allocated_object) in CheckVariableDeclarationType()
6774 << FixItHint::CreateInsertion(NewVD->getLocation(), "*"); in CheckVariableDeclarationType()
6776 NewVD->setType(T); in CheckVariableDeclarationType()
6784 && NewVD->hasLocalStorage() && T.getAddressSpace() != 0) { in CheckVariableDeclarationType()
6785 Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl); in CheckVariableDeclarationType()
6786 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6790 // OpenCL v1.2 s6.8 - The static qualifier is valid only in program in CheckVariableDeclarationType()
6794 NewVD->isStaticLocal()) { in CheckVariableDeclarationType()
6795 Diag(NewVD->getLocation(), diag::err_static_function_scope); in CheckVariableDeclarationType()
6796 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6801 // OpenCL v2.0 s6.12.5 - The __block storage type is not supported. in CheckVariableDeclarationType()
6802 if (NewVD->hasAttr<BlocksAttr>()) { in CheckVariableDeclarationType()
6803 Diag(NewVD->getLocation(), diag::err_opencl_block_storage_type); in CheckVariableDeclarationType()
6807 if (T->isBlockPointerType()) { in CheckVariableDeclarationType()
6808 // OpenCL v2.0 s6.12.5 - Any block declaration must be const qualified and in CheckVariableDeclarationType()
6811 Diag(NewVD->getLocation(), diag::err_opencl_invalid_block_declaration) in CheckVariableDeclarationType()
6813 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6816 if (NewVD->hasExternalStorage()) { in CheckVariableDeclarationType()
6817 Diag(NewVD->getLocation(), diag::err_opencl_extern_block_declaration); in CheckVariableDeclarationType()
6818 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6821 // OpenCL v2.0 s6.12.5 - Blocks with variadic arguments are not supported. in CheckVariableDeclarationType()
6823 const BlockPointerType *BlkTy = T->getAs<BlockPointerType>(); in CheckVariableDeclarationType()
6825 BlkTy->getPointeeType()->getAs<FunctionProtoType>(); in CheckVariableDeclarationType()
6826 if (FTy && FTy->isVariadic()) { in CheckVariableDeclarationType()
6827 Diag(NewVD->getLocation(), diag::err_opencl_block_proto_variadic) in CheckVariableDeclarationType()
6828 << T << NewVD->getSourceRange(); in CheckVariableDeclarationType()
6829 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6833 // OpenCL v1.2 s6.5 - All program scope variables must be declared in the in CheckVariableDeclarationType()
6835 // OpenCL v2.0 s6.5.1 - Variables defined at program scope and static in CheckVariableDeclarationType()
6838 if (NewVD->isFileVarDecl() || NewVD->isStaticLocal() || in CheckVariableDeclarationType()
6839 NewVD->hasExternalStorage()) { in CheckVariableDeclarationType()
6840 if (!T->isSamplerT() && in CheckVariableDeclarationType()
6844 int Scope = NewVD->isStaticLocal() | NewVD->hasExternalStorage() << 1; in CheckVariableDeclarationType()
6846 Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space) in CheckVariableDeclarationType()
6849 Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space) in CheckVariableDeclarationType()
6851 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6856 Diag(NewVD->getLocation(), diag::err_opencl_function_variable) in CheckVariableDeclarationType()
6858 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6866 if (FD && !FD->hasAttr<OpenCLKernelAttr>()) { in CheckVariableDeclarationType()
6868 Diag(NewVD->getLocation(), diag::err_opencl_function_variable) in CheckVariableDeclarationType()
6869 << 0 /*non-kernel only*/ << "constant"; in CheckVariableDeclarationType()
6871 Diag(NewVD->getLocation(), diag::err_opencl_function_variable) in CheckVariableDeclarationType()
6872 << 0 /*non-kernel only*/ << "local"; in CheckVariableDeclarationType()
6873 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6880 if (NewVD->hasLocalStorage() && T.isObjCGCWeak() in CheckVariableDeclarationType()
6881 && !NewVD->hasAttr<BlocksAttr>()) { in CheckVariableDeclarationType()
6883 Diag(NewVD->getLocation(), diag::warn_gc_attribute_weak_on_local); in CheckVariableDeclarationType()
6886 Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local); in CheckVariableDeclarationType()
6890 bool isVM = T->isVariablyModifiedType(); in CheckVariableDeclarationType()
6891 if (isVM || NewVD->hasAttr<CleanupAttr>() || in CheckVariableDeclarationType()
6892 NewVD->hasAttr<BlocksAttr>()) in CheckVariableDeclarationType()
6893 getCurFunction()->setHasBranchProtectedScope(); in CheckVariableDeclarationType()
6895 if ((isVM && NewVD->hasLinkage()) || in CheckVariableDeclarationType()
6896 (T->isVariableArrayType() && NewVD->hasGlobalStorage())) { in CheckVariableDeclarationType()
6902 if (!FixedTInfo && T->isVariableArrayType()) { in CheckVariableDeclarationType()
6906 SourceRange SizeRange = VAT->getSizeExpr()->getSourceRange(); in CheckVariableDeclarationType()
6908 if (NewVD->isFileVarDecl()) in CheckVariableDeclarationType()
6909 Diag(NewVD->getLocation(), diag::err_vla_decl_in_file_scope) in CheckVariableDeclarationType()
6911 else if (NewVD->isStaticLocal()) in CheckVariableDeclarationType()
6912 Diag(NewVD->getLocation(), diag::err_vla_decl_has_static_storage) in CheckVariableDeclarationType()
6915 Diag(NewVD->getLocation(), diag::err_vla_decl_has_extern_linkage) in CheckVariableDeclarationType()
6917 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6922 if (NewVD->isFileVarDecl()) in CheckVariableDeclarationType()
6923 Diag(NewVD->getLocation(), diag::err_vm_decl_in_file_scope); in CheckVariableDeclarationType()
6925 Diag(NewVD->getLocation(), diag::err_vm_decl_has_extern_linkage); in CheckVariableDeclarationType()
6926 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6930 Diag(NewVD->getLocation(), diag::warn_illegal_constant_array_size); in CheckVariableDeclarationType()
6931 NewVD->setType(FixedTInfo->getType()); in CheckVariableDeclarationType()
6932 NewVD->setTypeSourceInfo(FixedTInfo); in CheckVariableDeclarationType()
6935 if (T->isVoidType()) { in CheckVariableDeclarationType()
6938 if (NewVD->isThisDeclarationADefinition() || getLangOpts().CPlusPlus) { in CheckVariableDeclarationType()
6939 Diag(NewVD->getLocation(), diag::err_typecheck_decl_incomplete_type) in CheckVariableDeclarationType()
6941 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6946 if (!NewVD->hasLocalStorage() && NewVD->hasAttr<BlocksAttr>()) { in CheckVariableDeclarationType()
6947 Diag(NewVD->getLocation(), diag::err_block_on_nonlocal); in CheckVariableDeclarationType()
6948 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6952 if (isVM && NewVD->hasAttr<BlocksAttr>()) { in CheckVariableDeclarationType()
6953 Diag(NewVD->getLocation(), diag::err_block_on_vm); in CheckVariableDeclarationType()
6954 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6958 if (NewVD->isConstexpr() && !T->isDependentType() && in CheckVariableDeclarationType()
6959 RequireLiteralType(NewVD->getLocation(), T, in CheckVariableDeclarationType()
6961 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
6966 /// \brief Perform semantic checking on a newly-created variable
6969 /// This routine performs all of the type-checking required for a
6975 /// Sets NewVD->isInvalidDecl() if an error was encountered.
6982 if (NewVD->isInvalidDecl()) in CheckVariableDeclaration()
6985 // If we did not find anything by this name, look for a non-visible in CheckVariableDeclaration()
7008 Specifier->getType()->getAs<RecordType>()->getDecl(); in operator ()()
7010 DeclarationName Name = Method->getDeclName(); in operator ()()
7015 QualType T = S->Context.getTypeDeclType(BaseRecord); in operator ()()
7016 CanQualType CT = S->Context.getCanonicalType(T); in operator ()()
7018 Name = S->Context.DeclarationNames.getCXXDestructorName(CT); in operator ()()
7021 for (Path.Decls = BaseRecord->lookup(Name); !Path.Decls.empty(); in operator ()()
7025 if (MD->isVirtual() && !S->IsOverload(Method, MD, false)) in operator ()()
7045 S.Diag(MD->getLocation(), DiagID) << MD->getDeclName(); in ReportOverrides()
7046 for (CXXMethodDecl::method_iterator I = MD->begin_overridden_methods(), in ReportOverrides()
7047 E = MD->end_overridden_methods(); in ReportOverrides()
7053 (OEK == OEK_NonDeleted && !(*I)->isDeleted()) || in ReportOverrides()
7054 (OEK == OEK_Deleted && (*I)->isDeleted())) in ReportOverrides()
7055 S.Diag((*I)->getLocation(), diag::note_overridden_virtual_function); in ReportOverrides()
7059 /// AddOverriddenMethods - See if a method overrides any in the base classes,
7070 if (DC->lookupInBases(FOM, Paths)) { in AddOverriddenMethods()
7073 MD->addOverriddenMethod(OldMD->getCanonicalDecl()); in AddOverriddenMethods()
7078 hasDeletedOverridenMethods |= OldMD->isDeleted(); in AddOverriddenMethods()
7079 hasNonDeletedOverridenMethods |= !OldMD->isDeleted(); in AddOverriddenMethods()
7086 if (hasDeletedOverridenMethods && !MD->isDeleted()) { in AddOverriddenMethods()
7089 if (hasNonDeletedOverridenMethods && MD->isDeleted()) { in AddOverriddenMethods()
7109 // Callback to only accept typo corrections that have a non-zero edit distance.
7116 ExpectedParent(Parent ? Parent->getCanonicalDecl() : nullptr) {} in DifferentNameValidatorCCC()
7128 if (FD && !FD->hasBody() && in ValidateCandidate()
7131 CXXRecordDecl *Parent = MD->getParent(); in ValidateCandidate()
7132 if (Parent && Parent->getCanonicalDecl() == ExpectedParent) in ValidateCandidate()
7163 DeclarationName Name = NewFD->getDeclName(); in DiagnoseInvalidRedeclaration()
7164 DeclContext *NewDC = NewFD->getDeclContext(); in DiagnoseInvalidRedeclaration()
7171 LookupResult Prev(SemaRef, Name, NewFD->getLocation(), in DiagnoseInvalidRedeclaration()
7176 NewFD->setInvalidDecl(); in DiagnoseInvalidRedeclaration()
7182 "Cannot have an ambiguity in previous-declaration lookup"); in DiagnoseInvalidRedeclaration()
7202 SemaRef.Context, NewFD, MD ? MD->getParent() : nullptr), in DiagnoseInvalidRedeclaration()
7213 if (FD && !FD->hasBody() && in DiagnoseInvalidRedeclaration()
7228 // pieces need to verify the typo-corrected C++ declaration and hopefully in DiagnoseInvalidRedeclaration()
7232 Correction.getCorrectionDecl()->getDeclContext(), in DiagnoseInvalidRedeclaration()
7233 NewFD->getTypeSourceInfo(), Previous, ExtraArgs.TemplateParamLists, in DiagnoseInvalidRedeclaration()
7242 Decl *Canonical = Result->getCanonicalDecl(); in DiagnoseInvalidRedeclaration()
7245 if ((*I)->getCanonicalDecl() == Canonical) in DiagnoseInvalidRedeclaration()
7265 SemaRef.Diag(NewFD->getLocation(), DiagMsg) in DiagnoseInvalidRedeclaration()
7266 << Name << NewDC << IsDefinition << NewFD->getLocation(); in DiagnoseInvalidRedeclaration()
7270 NewFDisConst = NewMD->isConst(); in DiagnoseInvalidRedeclaration()
7275 FunctionDecl *FD = NearMatch->first; in DiagnoseInvalidRedeclaration()
7277 bool FDisConst = MD && MD->isConst(); in DiagnoseInvalidRedeclaration()
7281 if (unsigned Idx = NearMatch->second) { in DiagnoseInvalidRedeclaration()
7282 ParmVarDecl *FDParam = FD->getParamDecl(Idx-1); in DiagnoseInvalidRedeclaration()
7283 SourceLocation Loc = FDParam->getTypeSpecStartLoc(); in DiagnoseInvalidRedeclaration()
7284 if (Loc.isInvalid()) Loc = FD->getLocation(); in DiagnoseInvalidRedeclaration()
7287 << Idx << FDParam->getType() in DiagnoseInvalidRedeclaration()
7288 << NewFD->getParamDecl(Idx - 1)->getType(); in DiagnoseInvalidRedeclaration()
7290 SemaRef.Diag(FD->getLocation(), diag::note_member_def_close_const_match) in DiagnoseInvalidRedeclaration()
7291 << NewFDisConst << FD->getSourceRange().getEnd(); in DiagnoseInvalidRedeclaration()
7293 SemaRef.Diag(FD->getLocation(), in DiagnoseInvalidRedeclaration()
7316 if (SemaRef.CurContext->getRedeclContext()->isFunctionOrMethod()) { in getFunctionStorageClass()
7319 // block scope shall have no explicit storage-class specifier in getFunctionStorageClass()
7349 // - there is a prototype in the declarator, or in CreateNewFunctionDecl()
7350 // - the type R of the function is some kind of typedef or other reference in CreateNewFunctionDecl()
7354 (!isa<FunctionType>(R.getTypePtr()) && R->isFunctionProtoType()); in CreateNewFunctionDecl()
7361 NewFD->setInvalidDecl(); in CreateNewFunctionDecl()
7372 if (!DC->isRecord() && in CreateNewFunctionDecl()
7374 D.getIdentifierLoc(), R->getAs<FunctionType>()->getReturnType(), in CreateNewFunctionDecl()
7380 assert(DC->isRecord() && in CreateNewFunctionDecl()
7392 if (DC->isRecord()) { in CreateNewFunctionDecl()
7404 if (SemaRef.getLangOpts().CPlusPlus11 && !Record->isDependentType() && in CreateNewFunctionDecl()
7405 Record->getDefinition() && !Record->isBeingDefined() && in CreateNewFunctionDecl()
7406 R->getAs<FunctionProtoType>()->getExceptionSpecType() == EST_None) { in CreateNewFunctionDecl()
7427 if (!DC->isRecord()) { in CreateNewFunctionDecl()
7440 } else if (DC->isRecord()) { in CreateNewFunctionDecl()
7446 Name.getAsIdentifierInfo() == cast<CXXRecordDecl>(DC)->getIdentifier()){ in CreateNewFunctionDecl()
7459 IsVirtualOkay = !Ret->isStatic(); in CreateNewFunctionDecl()
7464 if (!isFriend && SemaRef.CurContext->isRecord()) in CreateNewFunctionDecl()
7469 // - we're in C++ (where every function has a prototype), in CreateNewFunctionDecl()
7487 if (PT->isPointerType()) { in getOpenCLKernelParameterType()
7488 QualType PointeeType = PT->getPointeeType(); in getOpenCLKernelParameterType()
7489 if (PointeeType->isPointerType()) in getOpenCLKernelParameterType()
7498 if (PT->isImageType()) in getOpenCLKernelParameterType()
7501 if (PT->isBooleanType()) in getOpenCLKernelParameterType()
7504 if (PT->isEventT()) in getOpenCLKernelParameterType()
7507 if (PT->isHalfType()) in getOpenCLKernelParameterType()
7510 if (PT->isRecordType()) in getOpenCLKernelParameterType()
7521 QualType PT = Param->getType(); in checkIsValidOpenCLKernelParameter()
7533 S.Diag(Param->getLocation(), diag::err_opencl_ptrptr_kernel_param); in checkIsValidOpenCLKernelParameter()
7541 S.Diag(Param->getLocation(), diag::err_opencl_private_ptr_kernel_param); in checkIsValidOpenCLKernelParameter()
7547 // built-in scalar types bool, half, size_t, ptrdiff_t, intptr_t, and in checkIsValidOpenCLKernelParameter()
7549 // one of these built-in scalar types. in checkIsValidOpenCLKernelParameter()
7555 S.Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT; in checkIsValidOpenCLKernelParameter()
7576 const RecordDecl *PD = PT->castAs<RecordType>()->getDecl(); in checkIsValidOpenCLKernelParameter()
7587 ValidTypes.insert(Hist->getType().getTypePtr()); in checkIsValidOpenCLKernelParameter()
7597 RD = Field->getType()->castAs<RecordType>()->getDecl(); in checkIsValidOpenCLKernelParameter()
7605 for (const auto *FD : RD->fields()) { in checkIsValidOpenCLKernelParameter()
7606 QualType QT = FD->getType(); in checkIsValidOpenCLKernelParameter()
7626 S.Diag(Param->getLocation(), in checkIsValidOpenCLKernelParameter()
7628 << PT->isUnionType() in checkIsValidOpenCLKernelParameter()
7631 S.Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT; in checkIsValidOpenCLKernelParameter()
7634 S.Diag(PD->getLocation(), diag::note_within_field_of_type) in checkIsValidOpenCLKernelParameter()
7635 << PD->getDeclName(); in checkIsValidOpenCLKernelParameter()
7644 S.Diag(OuterField->getLocation(), diag::note_within_field_of_type) in checkIsValidOpenCLKernelParameter()
7645 << OuterField->getType(); in checkIsValidOpenCLKernelParameter()
7648 S.Diag(FD->getLocation(), diag::note_illegal_field_declared_here) in checkIsValidOpenCLKernelParameter()
7649 << QT->isPointerType() in checkIsValidOpenCLKernelParameter()
7662 QualType R = TInfo->getType(); in ActOnFunctionDeclarator()
7664 assert(R.getTypePtr()->isFunctionType()); in ActOnFunctionDeclarator()
7698 if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer()) in ActOnFunctionDeclarator()
7699 NewFD->setTopLevelDeclInObjCContainer(); in ActOnFunctionDeclarator()
7701 // Set the lexical context. If this is a function-scope declaration, or has a in ActOnFunctionDeclarator()
7704 NewFD->setLexicalDeclContext(CurContext); in ActOnFunctionDeclarator()
7707 NewFD->setLocalExternDecl(); in ActOnFunctionDeclarator()
7720 NewFD->setImplicitlyInline(); in ActOnFunctionDeclarator()
7727 dyn_cast<CXXRecordDecl>(NewFD->getDeclContext())) { in ActOnFunctionDeclarator()
7728 if (Parent->isInterface() && cast<CXXMethodDecl>(NewFD)->isUserProvided()) in ActOnFunctionDeclarator()
7729 NewFD->setPure(true); in ActOnFunctionDeclarator()
7733 if (isVirtual && Parent->isUnion()) in ActOnFunctionDeclarator()
7741 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
7755 if (TemplateParams->size() > 0) { in ActOnFunctionDeclarator()
7760 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
7764 Diag(NewFD->getLocation(), diag::err_destructor_template); in ActOnFunctionDeclarator()
7765 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
7771 if (DC->isDependentContext()) { in ActOnFunctionDeclarator()
7778 NewFD->getLocation(), in ActOnFunctionDeclarator()
7781 FunctionTemplate->setLexicalDeclContext(CurContext); in ActOnFunctionDeclarator()
7782 NewFD->setDescribedFunctionTemplate(FunctionTemplate); in ActOnFunctionDeclarator()
7786 NewFD->setTemplateParameterListsInfo(Context, in ActOnFunctionDeclarator()
7794 NewFD->setTemplateParameterListsInfo(Context, TemplateParamLists); in ActOnFunctionDeclarator()
7799 SourceRange RemoveRange = TemplateParams->getSourceRange(); in ActOnFunctionDeclarator()
7802 // template-id, we're actually silently creating a problem: in ActOnFunctionDeclarator()
7824 NewFD->setTemplateParameterListsInfo(Context, TemplateParamLists); in ActOnFunctionDeclarator()
7828 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
7830 FunctionTemplate->setInvalidDecl(); in ActOnFunctionDeclarator()
7836 // member-specification of a class declaration; see 10.3. in ActOnFunctionDeclarator()
7838 if (isVirtual && !NewFD->isInvalidDecl()) { in ActOnFunctionDeclarator()
7842 } else if (!CurContext->isRecord()) { in ActOnFunctionDeclarator()
7847 } else if (NewFD->getDescribedFunctionTemplate()) { in ActOnFunctionDeclarator()
7855 NewFD->setVirtualAsWritten(true); in ActOnFunctionDeclarator()
7859 NewFD->getReturnType()->isUndeducedType()) in ActOnFunctionDeclarator()
7864 (NewFD->isDependentContext() || in ActOnFunctionDeclarator()
7865 (isFriend && CurContext->isDependentContext())) && in ActOnFunctionDeclarator()
7866 NewFD->getReturnType()->isUndeducedType()) { in ActOnFunctionDeclarator()
7874 NewFD->getType()->castAs<FunctionProtoType>(); in ActOnFunctionDeclarator()
7876 SubstAutoType(FPT->getReturnType(), Context.DependentTy); in ActOnFunctionDeclarator()
7877 NewFD->setType(Context.getFunctionType(Result, FPT->getParamTypes(), in ActOnFunctionDeclarator()
7878 FPT->getExtProtoInfo())); in ActOnFunctionDeclarator()
7884 if (isInline && !NewFD->isInvalidDecl()) { in ActOnFunctionDeclarator()
7885 if (CurContext->isFunctionOrMethod()) { in ActOnFunctionDeclarator()
7897 if (isExplicit && !NewFD->isInvalidDecl()) { in ActOnFunctionDeclarator()
7898 if (!CurContext->isRecord()) { in ActOnFunctionDeclarator()
7916 NewFD->setImplicitlyInline(); in ActOnFunctionDeclarator()
7927 if (FunctionTemplateDecl *FTD = NewFD->getDescribedFunctionTemplate()) in ActOnFunctionDeclarator()
7928 FTD->setConcept(); in ActOnFunctionDeclarator()
7935 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
7939 // have no exception-specification and is treated as if it were specified in ActOnFunctionDeclarator()
7941 if (const FunctionProtoType *FPT = R->getAs<FunctionProtoType>()) { in ActOnFunctionDeclarator()
7942 if (FPT->hasExceptionSpec()) { in ActOnFunctionDeclarator()
7946 Diag(NewFD->getLocation(), diag::err_function_concept_exception_spec) in ActOnFunctionDeclarator()
7948 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
7955 // - The declared return type shall have the type bool. in ActOnFunctionDeclarator()
7956 if (!Context.hasSameType(FPT->getReturnType(), Context.BoolTy)) { in ActOnFunctionDeclarator()
7958 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
7963 // - The declaration's parameter list shall be equivalent to an empty in ActOnFunctionDeclarator()
7965 if (FPT->getNumParams() > 0 || FPT->isVariadic()) in ActOnFunctionDeclarator()
7966 Diag(NewFD->getLocation(), diag::err_function_concept_with_params); in ActOnFunctionDeclarator()
7971 NewFD->setImplicitlyInline(); in ActOnFunctionDeclarator()
7980 NewFD->setInvalidDecl(true); in ActOnFunctionDeclarator()
7987 NewFD->setInvalidDecl(true); in ActOnFunctionDeclarator()
7994 NewFD->setInvalidDecl(true); in ActOnFunctionDeclarator()
8003 NewFD->setInvalidDecl(true); in ActOnFunctionDeclarator()
8017 NewFD->setModulePrivate(); in ActOnFunctionDeclarator()
8019 FunctionTemplate->setModulePrivate(); in ActOnFunctionDeclarator()
8025 FunctionTemplate->setObjectOfFriendDecl(); in ActOnFunctionDeclarator()
8026 FunctionTemplate->setAccess(AS_public); in ActOnFunctionDeclarator()
8028 NewFD->setObjectOfFriendDecl(); in ActOnFunctionDeclarator()
8029 NewFD->setAccess(AS_public); in ActOnFunctionDeclarator()
8041 NewFD->setDefaulted(); in ActOnFunctionDeclarator()
8045 NewFD->setDeletedAsWritten(); in ActOnFunctionDeclarator()
8054 NewFD->setImplicitlyInline(); in ActOnFunctionDeclarator()
8058 !CurContext->isRecord()) { in ActOnFunctionDeclarator()
8064 // Complain about the 'static' specifier if it's on an out-of-line in ActOnFunctionDeclarator()
8072 // A deallocation function with no exception-specification is treated in ActOnFunctionDeclarator()
8074 const FunctionProtoType *FPT = R->getAs<FunctionProtoType>(); in ActOnFunctionDeclarator()
8077 getLangOpts().CPlusPlus11 && FPT && !FPT->hasExceptionSpec()) in ActOnFunctionDeclarator()
8078 NewFD->setType(Context.getFunctionType( in ActOnFunctionDeclarator()
8079 FPT->getReturnType(), FPT->getParamTypes(), in ActOnFunctionDeclarator()
8080 FPT->getExtProtoInfo().withExceptionSpec(EST_BasicNoexcept))); in ActOnFunctionDeclarator()
8089 // Handle GNU asm-label extension (encoded as an attribute). in ActOnFunctionDeclarator()
8093 NewFD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0), Context, in ActOnFunctionDeclarator()
8094 SE->getString(), 0)); in ActOnFunctionDeclarator()
8097 ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier()); in ActOnFunctionDeclarator()
8100 NewFD->addAttr(I->second); in ActOnFunctionDeclarator()
8103 Diag(NewFD->getLocation(), diag::warn_redefine_extname_not_applied) in ActOnFunctionDeclarator()
8114 // Check for C99 6.7.5.3p10 - foo(void) is a non-varargs in ActOnFunctionDeclarator()
8122 assert(Param->getDeclContext() != NewFD && "Was set before ?"); in ActOnFunctionDeclarator()
8123 Param->setDeclContext(NewFD); in ActOnFunctionDeclarator()
8126 if (Param->isInvalidDecl()) in ActOnFunctionDeclarator()
8127 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
8130 } else if (const FunctionProtoType *FT = R->getAs<FunctionProtoType>()) { in ActOnFunctionDeclarator()
8141 for (const auto &AI : FT->param_types()) { in ActOnFunctionDeclarator()
8144 Param->setScopeInfo(0, Params.size()); in ActOnFunctionDeclarator()
8148 assert(R->isFunctionNoProtoType() && NewFD->getNumParams() == 0 && in ActOnFunctionDeclarator()
8149 "Should not need args for typedef of non-prototype fn"); in ActOnFunctionDeclarator()
8153 NewFD->setParams(Params); in ActOnFunctionDeclarator()
8161 NewFD->setDeclsInPrototypeScope(DeclsInPrototypeScope); in ActOnFunctionDeclarator()
8165 NewFD->addAttr( in ActOnFunctionDeclarator()
8171 if (!NewFD->isInvalidDecl() && in ActOnFunctionDeclarator()
8172 NewFD->getReturnType()->isVariablyModifiedType()) { in ActOnFunctionDeclarator()
8173 Diag(NewFD->getLocation(), diag::err_vm_func_decl); in ActOnFunctionDeclarator()
8174 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
8179 !NewFD->hasAttr<SectionAttr>()) { in ActOnFunctionDeclarator()
8180 NewFD->addAttr( in ActOnFunctionDeclarator()
8182 CodeSegStack.CurrentValue->getString(), in ActOnFunctionDeclarator()
8184 if (UnifySection(CodeSegStack.CurrentValue->getString(), in ActOnFunctionDeclarator()
8188 NewFD->dropAttr<SectionAttr>(); in ActOnFunctionDeclarator()
8200 unsigned AddressSpace = NewFD->getReturnType().getAddressSpace(); in ActOnFunctionDeclarator()
8204 Diag(NewFD->getLocation(), in ActOnFunctionDeclarator()
8206 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
8213 if (!NewFD->isInvalidDecl() && NewFD->isMain()) in ActOnFunctionDeclarator()
8216 if (!NewFD->isInvalidDecl() && NewFD->isMSVCRTEntryPoint()) in ActOnFunctionDeclarator()
8219 if (!NewFD->isInvalidDecl()) in ActOnFunctionDeclarator()
8225 assert((NewFD->isInvalidDecl() || !D.isRedeclaration() || in ActOnFunctionDeclarator()
8229 // Diagnose no-prototype function declarations with calling conventions that in ActOnFunctionDeclarator()
8232 const FunctionType *FT = NewFD->getType()->castAs<FunctionType>(); in ActOnFunctionDeclarator()
8234 CallingConv CC = FT->getExtInfo().getCC(); in ActOnFunctionDeclarator()
8240 Diag(NewFD->getLocation(), DiagID) in ActOnFunctionDeclarator()
8248 // N.B. We diagnose declarations instead of definitions per LWG issue 2340. in ActOnFunctionDeclarator()
8253 NewFD->isReplaceableGlobalAllocationFunction() && in ActOnFunctionDeclarator()
8254 !NewFD->hasAttr<UsedAttr>()) in ActOnFunctionDeclarator()
8257 << NewFD->getDeclName(); in ActOnFunctionDeclarator()
8259 // If the declarator is a template-id, translate the parser's template in ActOnFunctionDeclarator()
8263 TemplateArgs.setLAngleLoc(TemplateId->LAngleLoc); in ActOnFunctionDeclarator()
8264 TemplateArgs.setRAngleLoc(TemplateId->RAngleLoc); in ActOnFunctionDeclarator()
8265 ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(), in ActOnFunctionDeclarator()
8266 TemplateId->NumArgs); in ActOnFunctionDeclarator()
8272 if (NewFD->isInvalidDecl()) { in ActOnFunctionDeclarator()
8277 << SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc); in ActOnFunctionDeclarator()
8305 (NewFD->getType()->isDependentType() || DC->isDependentContext() || in ActOnFunctionDeclarator()
8313 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
8315 if (CurContext->isDependentContext() && CurContext->isRecord() in ActOnFunctionDeclarator()
8318 Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ? in ActOnFunctionDeclarator()
8321 << NewFD->getDeclName(); in ActOnFunctionDeclarator()
8326 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
8329 // A storage-class-specifier shall not be specified in an explicit in ActOnFunctionDeclarator()
8332 NewFD->getTemplateSpecializationInfo(); in ActOnFunctionDeclarator()
8334 if (SC != Info->getTemplate()->getTemplatedDecl()->getStorageClass()) in ActOnFunctionDeclarator()
8335 Diag(NewFD->getLocation(), in ActOnFunctionDeclarator()
8342 Diag(NewFD->getLocation(), in ActOnFunctionDeclarator()
8349 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
8354 if (!NewFD->isInvalidDecl() && NewFD->isMain()) in ActOnFunctionDeclarator()
8357 if (!NewFD->isInvalidDecl() && NewFD->isMSVCRTEntryPoint()) in ActOnFunctionDeclarator()
8360 if (!NewFD->isInvalidDecl()) in ActOnFunctionDeclarator()
8368 assert((NewFD->isInvalidDecl() || !D.isRedeclaration() || in ActOnFunctionDeclarator()
8378 if (!NewFD->isInvalidDecl()) in ActOnFunctionDeclarator()
8379 Access = NewFD->getPreviousDecl()->getAccess(); in ActOnFunctionDeclarator()
8381 NewFD->setAccess(Access); in ActOnFunctionDeclarator()
8382 if (FunctionTemplate) FunctionTemplate->setAccess(Access); in ActOnFunctionDeclarator()
8385 if (NewFD->isOverloadedOperator() && !DC->isRecord() && in ActOnFunctionDeclarator()
8386 PrincipalDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) in ActOnFunctionDeclarator()
8387 PrincipalDecl->setNonMemberOperator(); in ActOnFunctionDeclarator()
8393 FunctionTemplate->getPreviousDecl(); in ActOnFunctionDeclarator()
8394 CheckTemplateParameterList(FunctionTemplate->getTemplateParameters(), in ActOnFunctionDeclarator()
8395 PrevTemplate ? PrevTemplate->getTemplateParameters() in ActOnFunctionDeclarator()
8402 DC && DC->isRecord() && in ActOnFunctionDeclarator()
8403 DC->isDependentContext()) in ActOnFunctionDeclarator()
8408 if (NewFD->isInvalidDecl()) { in ActOnFunctionDeclarator()
8414 if (isa<CXXRecordDecl>(NewFD->getDeclContext())) in ActOnFunctionDeclarator()
8415 NewFD->setAccess(AS_public); in ActOnFunctionDeclarator()
8419 // ...with the major exception of templated-scope or in ActOnFunctionDeclarator()
8420 // dependent-scope friend declarations. in ActOnFunctionDeclarator()
8430 D.getCXXScopeSpec().getScopeRep()->isDependent() || in ActOnFunctionDeclarator()
8431 CurContext->isDependentContext())) { in ActOnFunctionDeclarator()
8434 // The user tried to provide an out-of-line definition for a in ActOnFunctionDeclarator()
8443 // void X::f() { } // ill-formed in ActOnFunctionDeclarator()
8446 // matches (e.g., those that differ only in cv-qualifiers and in ActOnFunctionDeclarator()
8458 } else if (isFriend && cast<CXXRecordDecl>(CurContext)->isLocalClass()) { in ActOnFunctionDeclarator()
8466 isa<CXXMethodDecl>(NewFD) && NewFD->isOutOfLine() && in ActOnFunctionDeclarator()
8469 // An out-of-line member function declaration must also be a in ActOnFunctionDeclarator()
8476 Diag(NewFD->getLocation(), diag::ext_out_of_line_declaration) in ActOnFunctionDeclarator()
8486 if (NewFD->hasAttr<OverloadableAttr>() && in ActOnFunctionDeclarator()
8487 !NewFD->getType()->getAs<FunctionProtoType>()) { in ActOnFunctionDeclarator()
8488 Diag(NewFD->getLocation(), in ActOnFunctionDeclarator()
8493 const FunctionType *FT = NewFD->getType()->getAs<FunctionType>(); in ActOnFunctionDeclarator()
8497 EPI.ExtInfo = FT->getExtInfo(); in ActOnFunctionDeclarator()
8499 QualType R = Context.getFunctionType(FT->getReturnType(), None, EPI); in ActOnFunctionDeclarator()
8500 NewFD->setType(R); in ActOnFunctionDeclarator()
8505 if (!DC->isRecord() && NewFD->isExternallyVisible()) in ActOnFunctionDeclarator()
8519 if (NewFD->isFirstDecl() && !NewFD->isInvalidDecl() && in ActOnFunctionDeclarator()
8524 NewFD->setRangeEnd(D.getSourceRange().getEnd()); in ActOnFunctionDeclarator()
8534 IdentifierInfo *II = NewFD->getIdentifier(); in ActOnFunctionDeclarator()
8535 if (II && II->isStr("cudaConfigureCall") && !NewFD->isInvalidDecl() && in ActOnFunctionDeclarator()
8536 NewFD->getDeclContext()->getRedeclContext()->isTranslationUnit()) { in ActOnFunctionDeclarator()
8537 if (!R->getAs<FunctionType>()->getReturnType()->isScalarType()) in ActOnFunctionDeclarator()
8538 Diag(NewFD->getLocation(), diag::err_config_scalar_return); in ActOnFunctionDeclarator()
8544 // in device-side CUDA code, unless someone passed in ActOnFunctionDeclarator()
8545 // -fcuda-allow-variadic-functions. in ActOnFunctionDeclarator()
8546 if (!getLangOpts().CUDAAllowVariadicFunctions && NewFD->isVariadic() && in ActOnFunctionDeclarator()
8547 (NewFD->hasAttr<CUDADeviceAttr>() || in ActOnFunctionDeclarator()
8548 NewFD->hasAttr<CUDAGlobalAttr>()) && in ActOnFunctionDeclarator()
8549 !(II && II->isStr("printf") && NewFD->isExternC() && in ActOnFunctionDeclarator()
8551 Diag(NewFD->getLocation(), diag::err_variadic_device_fn); in ActOnFunctionDeclarator()
8557 if (NewFD->isInvalidDecl()) in ActOnFunctionDeclarator()
8558 FunctionTemplate->setInvalidDecl(); in ActOnFunctionDeclarator()
8563 if (NewFD->hasAttr<OpenCLKernelAttr>()) { in ActOnFunctionDeclarator()
8571 // OpenCL v1.2, s6.9 -- Kernels can only have return type void. in ActOnFunctionDeclarator()
8572 if (!NewFD->getReturnType()->isVoidType()) { in ActOnFunctionDeclarator()
8573 SourceRange RTRange = NewFD->getReturnTypeSourceRange(); in ActOnFunctionDeclarator()
8581 for (auto Param : NewFD->parameters()) in ActOnFunctionDeclarator()
8584 for (const ParmVarDecl *Param : NewFD->parameters()) { in ActOnFunctionDeclarator()
8585 QualType PT = Param->getType(); in ActOnFunctionDeclarator()
8587 // OpenCL 2.0 pipe restrictions forbids pipe packet types to be non-value in ActOnFunctionDeclarator()
8590 if(const PipeType *PipeTy = PT->getAs<PipeType>()) { in ActOnFunctionDeclarator()
8591 QualType ElemTy = PipeTy->getElementType(); in ActOnFunctionDeclarator()
8592 if (ElemTy->isReferenceType() || ElemTy->isPointerType()) { in ActOnFunctionDeclarator()
8593 Diag(Param->getTypeSpecStartLoc(), diag::err_reference_pipe_type ); in ActOnFunctionDeclarator()
8611 CurContext->addDecl(NewSpec); in ActOnFunctionDeclarator()
8631 /// This sets NewFD->isInvalidDecl() to true if there was an error.
8637 assert(!NewFD->getReturnType()->isVariablyModifiedType() && in CheckFunctionDeclaration()
8678 if (!getLangOpts().CPlusPlus && !NewFD->hasAttr<OverloadableAttr>()) { in CheckFunctionDeclaration()
8681 Diag(NewFD->getLocation(), diag::err_attribute_overloadable_missing) in CheckFunctionDeclaration()
8689 Diag(OverloadedDecl->getLocation(), in CheckFunctionDeclaration()
8691 NewFD->addAttr(OverloadableAttr::CreateImplicit(Context)); in CheckFunctionDeclaration()
8707 if (OldDecl->hasAttr<OverloadableAttr>()) { in CheckFunctionDeclaration()
8708 if (!getLangOpts().CPlusPlus && !NewFD->hasAttr<OverloadableAttr>()) { in CheckFunctionDeclaration()
8709 Diag(NewFD->getLocation(), diag::err_attribute_overloadable_missing) in CheckFunctionDeclaration()
8711 Diag(Previous.getFoundDecl()->getLocation(), in CheckFunctionDeclaration()
8713 NewFD->addAttr(OverloadableAttr::CreateImplicit(Context)); in CheckFunctionDeclaration()
8724 // A constexpr specifier for a non-static member function that is not in CheckFunctionDeclaration()
8727 // This needs to be delayed until we know whether this is an out-of-line in CheckFunctionDeclaration()
8733 if (!getLangOpts().CPlusPlus14 && MD && MD->isConstexpr() && in CheckFunctionDeclaration()
8734 !MD->isStatic() && !isa<CXXConstructorDecl>(MD) && in CheckFunctionDeclaration()
8735 (MD->getTypeQualifiers() & Qualifiers::Const) == 0) { in CheckFunctionDeclaration()
8738 OldMD = dyn_cast_or_null<CXXMethodDecl>(OldDecl->getAsFunction()); in CheckFunctionDeclaration()
8739 if (!OldMD || !OldMD->isStatic()) { in CheckFunctionDeclaration()
8741 MD->getType()->castAs<FunctionProtoType>(); in CheckFunctionDeclaration()
8742 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); in CheckFunctionDeclaration()
8744 MD->setType(Context.getFunctionType(FPT->getReturnType(), in CheckFunctionDeclaration()
8745 FPT->getParamTypes(), EPI)); in CheckFunctionDeclaration()
8751 if (FunctionTypeLoc FTL = MD->getTypeSourceInfo()->getTypeLoc() in CheckFunctionDeclaration()
8755 Diag(MD->getLocation(), diag::warn_cxx14_compat_constexpr_not_const) in CheckFunctionDeclaration()
8765 NewFD->setInvalidDecl(); in CheckFunctionDeclaration()
8774 NewFD->setPreviousDeclaration(OldTemplateDecl->getTemplatedDecl()); in CheckFunctionDeclaration()
8776 = NewFD->getDescribedFunctionTemplate(); in CheckFunctionDeclaration()
8777 assert(NewTemplateDecl && "Template/non-template mismatch"); in CheckFunctionDeclaration()
8779 = dyn_cast<CXXMethodDecl>(NewTemplateDecl->getTemplatedDecl())) { in CheckFunctionDeclaration()
8780 Method->setAccess(OldTemplateDecl->getAccess()); in CheckFunctionDeclaration()
8781 NewTemplateDecl->setAccess(OldTemplateDecl->getAccess()); in CheckFunctionDeclaration()
8787 NewTemplateDecl->getInstantiatedFromMemberTemplate()) { in CheckFunctionDeclaration()
8788 NewTemplateDecl->setMemberSpecialization(); in CheckFunctionDeclaration()
8789 assert(OldTemplateDecl->isMemberSpecialization()); in CheckFunctionDeclaration()
8792 if (OldTemplateDecl->getTemplatedDecl()->isDeleted()) { in CheckFunctionDeclaration()
8794 OldTemplateDecl->getTemplatedDecl(); in CheckFunctionDeclaration()
8795 assert(OldTemplatedDecl->getCanonicalDecl() == OldTemplatedDecl); in CheckFunctionDeclaration()
8796 OldTemplatedDecl->setDeletedAsWritten(false); in CheckFunctionDeclaration()
8802 NewFD->setPreviousDeclaration(cast<FunctionDecl>(OldDecl)); in CheckFunctionDeclaration()
8805 NewFD->setAccess(OldDecl->getAccess()); in CheckFunctionDeclaration()
8812 // C++-specific checks. in CheckFunctionDeclaration()
8817 CXXRecordDecl *Record = Destructor->getParent(); in CheckFunctionDeclaration()
8822 if (!ClassType->isDependentType()) { in CheckFunctionDeclaration()
8826 if (NewFD->getDeclName() != Name) { in CheckFunctionDeclaration()
8827 Diag(NewFD->getLocation(), diag::err_destructor_name); in CheckFunctionDeclaration()
8828 NewFD->setInvalidDecl(); in CheckFunctionDeclaration()
8839 if (!Method->isFunctionTemplateSpecialization() && in CheckFunctionDeclaration()
8840 !Method->getDescribedFunctionTemplate() && in CheckFunctionDeclaration()
8841 Method->isCanonicalDecl()) { in CheckFunctionDeclaration()
8842 if (AddOverriddenMethods(Method->getParent(), Method)) { in CheckFunctionDeclaration()
8844 if (NewFD->getStorageClass() == SC_Static) { in CheckFunctionDeclaration()
8850 if (Method->isStatic()) in CheckFunctionDeclaration()
8855 if (NewFD->isOverloadedOperator() && in CheckFunctionDeclaration()
8857 NewFD->setInvalidDecl(); in CheckFunctionDeclaration()
8862 if (NewFD->getLiteralIdentifier() && in CheckFunctionDeclaration()
8864 NewFD->setInvalidDecl(); in CheckFunctionDeclaration()
8871 if (!CurContext->isRecord()) in CheckFunctionDeclaration()
8876 if (unsigned BuiltinID = NewFD->getBuiltinID()) { in CheckFunctionDeclaration()
8878 LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier()); in CheckFunctionDeclaration()
8880 if (!T.isNull() && !Context.hasSameType(T, NewFD->getType())) { in CheckFunctionDeclaration()
8890 // But, issue any diagnostic on the first declaration only. in CheckFunctionDeclaration()
8891 if (Previous.empty() && NewFD->isExternC()) { in CheckFunctionDeclaration()
8892 QualType R = NewFD->getReturnType(); in CheckFunctionDeclaration()
8893 if (R->isIncompleteType() && !R->isVoidType()) in CheckFunctionDeclaration()
8894 Diag(NewFD->getLocation(), diag::warn_return_value_udt_incomplete) in CheckFunctionDeclaration()
8896 else if (!R.isPODType(Context) && !R->isVoidType() && in CheckFunctionDeclaration()
8897 !R->isObjCObjectPointerType()) in CheckFunctionDeclaration()
8898 Diag(NewFD->getLocation(), diag::warn_return_value_udt) << NewFD << R; in CheckFunctionDeclaration()
8907 // constexpr is ill-formed. in CheckMain()
8912 if (FD->getStorageClass() == SC_Static) in CheckMain()
8916 if (FD->isInlineSpecified()) in CheckMain()
8926 if (FD->isConstexpr()) { in CheckMain()
8929 FD->setConstexpr(false); in CheckMain()
8933 Diag(FD->getLocation(), diag::err_opencl_no_main) in CheckMain()
8934 << FD->hasAttr<OpenCLKernelAttr>(); in CheckMain()
8935 FD->setInvalidDecl(); in CheckMain()
8939 QualType T = FD->getType(); in CheckMain()
8940 assert(T->isFunctionType() && "function decl is not of function type"); in CheckMain()
8941 const FunctionType* FT = T->castAs<FunctionType>(); in CheckMain()
8944 // In C with GNU extensions we allow main() to have non-integer return in CheckMain()
8946 // implicit-return-zero rule. in CheckMain()
8949 if (Context.hasSameUnqualifiedType(FT->getReturnType(), Context.IntTy)) in CheckMain()
8950 FD->setHasImplicitReturnZero(true); in CheckMain()
8952 Diag(FD->getTypeSpecStartLoc(), diag::ext_main_returns_nonint); in CheckMain()
8953 SourceRange RTRange = FD->getReturnTypeSourceRange(); in CheckMain()
8964 if (Context.hasSameType(FT->getReturnType(), Context.IntTy)) in CheckMain()
8965 FD->setHasImplicitReturnZero(true); in CheckMain()
8967 // Otherwise, this is just a flat-out error. in CheckMain()
8968 SourceRange RTRange = FD->getReturnTypeSourceRange(); in CheckMain()
8969 Diag(FD->getTypeSpecStartLoc(), diag::err_main_returns_nonint) in CheckMain()
8972 FD->setInvalidDecl(true); in CheckMain()
8980 unsigned nparams = FTP->getNumParams(); in CheckMain()
8981 assert(FD->getNumParams() == nparams); in CheckMain()
8985 if (FTP->isVariadic()) { in CheckMain()
8986 Diag(FD->getLocation(), diag::ext_variadic_main); in CheckMain()
8998 Diag(FD->getLocation(), diag::err_main_surplus_args) << nparams; in CheckMain()
8999 FD->setInvalidDecl(true); in CheckMain()
9011 QualType AT = FTP->getParamType(i); in CheckMain()
9025 if ((PT = qs.strip(AT)->getAs<PointerType>()) && in CheckMain()
9026 (PT = qs.strip(PT->getPointeeType())->getAs<PointerType>()) && in CheckMain()
9027 Context.hasSameType(QualType(qs.strip(PT->getPointeeType()), 0), in CheckMain()
9035 Diag(FD->getLocation(), diag::err_main_arg_wrong) << i << Expected[i]; in CheckMain()
9037 FD->setInvalidDecl(true); in CheckMain()
9041 if (nparams == 1 && !FD->isInvalidDecl()) { in CheckMain()
9042 Diag(FD->getLocation(), diag::warn_main_one_arg); in CheckMain()
9045 if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) { in CheckMain()
9046 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD; in CheckMain()
9047 FD->setInvalidDecl(); in CheckMain()
9052 QualType T = FD->getType(); in CheckMSVCRTEntryPoint()
9053 assert(T->isFunctionType() && "function decl is not of function type"); in CheckMSVCRTEntryPoint()
9054 const FunctionType *FT = T->castAs<FunctionType>(); in CheckMSVCRTEntryPoint()
9058 if (FT->getReturnType()->isIntegralOrEnumerationType() || in CheckMSVCRTEntryPoint()
9059 FT->getReturnType()->isAnyPointerType() || in CheckMSVCRTEntryPoint()
9060 FT->getReturnType()->isNullPtrType()) in CheckMSVCRTEntryPoint()
9061 // DllMain is exempt because a return value of zero means it failed. in CheckMSVCRTEntryPoint()
9062 if (FD->getName() != "DllMain") in CheckMSVCRTEntryPoint()
9063 FD->setHasImplicitReturnZero(true); in CheckMSVCRTEntryPoint()
9065 if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) { in CheckMSVCRTEntryPoint()
9066 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD; in CheckMSVCRTEntryPoint()
9067 FD->setInvalidDecl(); in CheckMSVCRTEntryPoint()
9073 // any assignment, increment, decrement, function-calls, or in CheckForConstantInitializer()
9081 if (Init->isConstantInitializer(Context, false, &Culprit)) in CheckForConstantInitializer()
9083 Diag(Culprit->getExprLoc(), diag::err_init_element_not_constant) in CheckForConstantInitializer()
9084 << Culprit->getSourceRange(); in CheckForConstantInitializer()
9112 isPODType = VD->getType().isPODType(S.Context); in SelfReferenceChecker()
9113 isRecordType = VD->getType()->isRecordType(); in SelfReferenceChecker()
9114 isReferenceType = VD->getType()->isReferenceType(); in SelfReferenceChecker()
9131 for (auto Child : InitList->children()) { in CheckExpr()
9147 FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl()); in CheckInitListMemberExpr()
9151 if (FD->getType()->isReferenceType()) in CheckInitListMemberExpr()
9153 Base = ME->getBase()->IgnoreParenImpCasts(); in CheckInitListMemberExpr()
9158 if (!DRE || DRE->getDecl() != OrigDecl) in CheckInitListMemberExpr()
9168 UsedFieldIndex.push_back(I->getFieldIndex()); in CheckInitListMemberExpr()
9193 E = E->IgnoreParens(); in HandleValue()
9200 Visit(CO->getCond()); in HandleValue()
9201 HandleValue(CO->getTrueExpr()); in HandleValue()
9202 HandleValue(CO->getFalseExpr()); in HandleValue()
9208 Visit(BCO->getCond()); in HandleValue()
9209 HandleValue(BCO->getFalseExpr()); in HandleValue()
9214 HandleValue(OVE->getSourceExpr()); in HandleValue()
9219 if (BO->getOpcode() == BO_Comma) { in HandleValue()
9220 Visit(BO->getLHS()); in HandleValue()
9221 HandleValue(BO->getRHS()); in HandleValue()
9233 Expr *Base = E->IgnoreParenImpCasts(); in HandleValue()
9236 if (!isa<FieldDecl>(ME->getMemberDecl())) in HandleValue()
9238 Base = ME->getBase()->IgnoreParenImpCasts(); in HandleValue()
9249 // uses of references are bad, not just r-value uses.
9256 if (E->getCastKind() == CK_LValueToRValue) { in VisitImplicitCastExpr()
9257 HandleValue(E->getSubExpr()); in VisitImplicitCastExpr()
9271 if (E->getType()->canDecayToPointerType()) return; in VisitMemberExpr()
9273 // Warn when a non-static method call is followed by non-static member in VisitMemberExpr()
9275 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(E->getMemberDecl()); in VisitMemberExpr()
9276 bool Warn = (MD && !MD->isStatic()); in VisitMemberExpr()
9277 Expr *Base = E->getBase()->IgnoreParenImpCasts(); in VisitMemberExpr()
9279 if (!isa<FieldDecl>(ME->getMemberDecl())) in VisitMemberExpr()
9281 Base = ME->getBase()->IgnoreParenImpCasts(); in VisitMemberExpr()
9296 Expr *Callee = E->getCallee(); in VisitCXXOperatorCallExpr()
9302 for (auto Arg: E->arguments()) in VisitCXXOperatorCallExpr()
9303 HandleValue(Arg->IgnoreParenImpCasts()); in VisitCXXOperatorCallExpr()
9307 // For POD record types, addresses of its own members are well-defined. in VisitUnaryOperator()
9308 if (E->getOpcode() == UO_AddrOf && isRecordType && in VisitUnaryOperator()
9309 isa<MemberExpr>(E->getSubExpr()->IgnoreParens())) { in VisitUnaryOperator()
9311 HandleValue(E->getSubExpr()); in VisitUnaryOperator()
9315 if (E->isIncrementDecrementOp()) { in VisitUnaryOperator()
9316 HandleValue(E->getSubExpr()); in VisitUnaryOperator()
9326 if (E->getConstructor()->isCopyConstructor()) { in VisitCXXConstructExpr()
9327 Expr *ArgExpr = E->getArg(0); in VisitCXXConstructExpr()
9329 if (ILE->getNumInits() == 1) in VisitCXXConstructExpr()
9330 ArgExpr = ILE->getInit(0); in VisitCXXConstructExpr()
9332 if (ICE->getCastKind() == CK_NoOp) in VisitCXXConstructExpr()
9333 ArgExpr = ICE->getSubExpr(); in VisitCXXConstructExpr()
9342 if (E->getNumArgs() == 1) { in VisitCallExpr()
9343 if (FunctionDecl *FD = E->getDirectCallee()) { in VisitCallExpr()
9344 if (FD->isInStdNamespace() && FD->getIdentifier() && in VisitCallExpr()
9345 FD->getIdentifier()->isStr("move")) { in VisitCallExpr()
9346 HandleValue(E->getArg(0)); in VisitCallExpr()
9356 if (E->isCompoundAssignmentOp()) { in VisitBinaryOperator()
9357 HandleValue(E->getLHS()); in VisitBinaryOperator()
9358 Visit(E->getRHS()); in VisitBinaryOperator()
9369 Visit(E->getCond()); in VisitBinaryConditionalOperator()
9370 Visit(E->getFalseExpr()); in VisitBinaryConditionalOperator()
9374 Decl* ReferenceDecl = DRE->getDecl(); in HandleDeclRefExpr()
9379 } else if (cast<VarDecl>(OrigDecl)->isStaticLocal()) { in HandleDeclRefExpr()
9381 } else if (isa<TranslationUnitDecl>(OrigDecl->getDeclContext()) || in HandleDeclRefExpr()
9382 isa<NamespaceDecl>(OrigDecl->getDeclContext()) || in HandleDeclRefExpr()
9383 DRE->getDecl()->getType()->isRecordType()) { in HandleDeclRefExpr()
9390 S.DiagRuntimeBehavior(DRE->getLocStart(), DRE, in HandleDeclRefExpr()
9392 << DRE->getNameInfo().getName() in HandleDeclRefExpr()
9393 << OrigDecl->getLocation() in HandleDeclRefExpr()
9394 << DRE->getSourceRange()); in HandleDeclRefExpr()
9398 /// CheckSelfReference - Warns if OrigDecl is used in expression E.
9406 E = E->IgnoreParens(); in CheckSelfReference()
9410 if (!DirectInit && !cast<VarDecl>(OrigDecl)->getType()->isRecordType()) in CheckSelfReference()
9412 if (ICE->getCastKind() == CK_LValueToRValue) in CheckSelfReference()
9413 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr())) in CheckSelfReference()
9414 if (DRE->getDecl() == OrigDecl) in CheckSelfReference()
9427 assert((!VDecl || !VDecl->isInitCapture()) && in deduceVarTypeFromInitializer()
9433 DeduceInits = PL->exprs(); in deduceVarTypeFromInitializer()
9435 DeduceInits = IL->inits(); in deduceVarTypeFromInitializer()
9442 Diag(Init->getLocStart(), IsInitCapture in deduceVarTypeFromInitializer()
9450 Diag(DeduceInits[1]->getLocStart(), in deduceVarTypeFromInitializer()
9459 Diag(Init->getLocStart(), IsInitCapture in deduceVarTypeFromInitializer()
9469 Init->getType() == Context.UnknownAnyTy && !IsInitCapture) { in deduceVarTypeFromInitializer()
9486 << (DeduceInit->getType().isNull() ? TSI->getType() in deduceVarTypeFromInitializer()
9487 : DeduceInit->getType()) in deduceVarTypeFromInitializer()
9488 << DeduceInit->getSourceRange(); in deduceVarTypeFromInitializer()
9491 << Name << TSI->getType() in deduceVarTypeFromInitializer()
9492 << (DeduceInit->getType().isNull() ? TSI->getType() in deduceVarTypeFromInitializer()
9493 : DeduceInit->getType()) in deduceVarTypeFromInitializer()
9494 << DeduceInit->getSourceRange(); in deduceVarTypeFromInitializer()
9497 // Warn if we deduced 'id'. 'auto' usually implies type-safety, but using in deduceVarTypeFromInitializer()
9503 !IsInitCapture && !DeducedType.isNull() && DeducedType->isObjCIdType()) { in deduceVarTypeFromInitializer()
9504 SourceLocation Loc = TSI->getTypeLoc().getBeginLoc(); in deduceVarTypeFromInitializer()
9511 /// AddInitializerToDecl - Adds the initializer Init to the
9518 if (!RealDecl || RealDecl->isInvalidDecl()) { in AddInitializerToDecl()
9524 // Pure-specifiers are handled in ActOnPureSpecifier. in AddInitializerToDecl()
9525 Diag(Method->getLocation(), diag::err_member_function_initialization) in AddInitializerToDecl()
9526 << Method->getDeclName() << Init->getSourceRange(); in AddInitializerToDecl()
9527 Method->setInvalidDecl(); in AddInitializerToDecl()
9534 Diag(RealDecl->getLocation(), diag::err_illegal_initializer); in AddInitializerToDecl()
9535 RealDecl->setInvalidDecl(); in AddInitializerToDecl()
9540 if (TypeMayContainAuto && VDecl->getType()->isUndeducedType()) { in AddInitializerToDecl()
9546 RealDecl->setInvalidDecl(); in AddInitializerToDecl()
9552 VDecl, VDecl->getDeclName(), VDecl->getType(), in AddInitializerToDecl()
9553 VDecl->getTypeSourceInfo(), VDecl->getSourceRange(), DirectInit, Init); in AddInitializerToDecl()
9555 RealDecl->setInvalidDecl(); in AddInitializerToDecl()
9559 VDecl->setType(DeducedType); in AddInitializerToDecl()
9560 assert(VDecl->isLinkageValid()); in AddInitializerToDecl()
9564 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9568 if (VarDecl *Old = VDecl->getPreviousDecl()) { in AddInitializerToDecl()
9576 if (VDecl->isInvalidDecl()) in AddInitializerToDecl()
9581 if (VDecl->hasAttr<DLLImportAttr>() && !VDecl->isStaticDataMember()) { in AddInitializerToDecl()
9582 Diag(VDecl->getLocation(), diag::err_attribute_dllimport_data_definition); in AddInitializerToDecl()
9583 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9587 if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) { in AddInitializerToDecl()
9589 Diag(VDecl->getLocation(), diag::err_block_extern_cant_init); in AddInitializerToDecl()
9590 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9594 if (!VDecl->getType()->isDependentType()) { in AddInitializerToDecl()
9598 QualType BaseDeclType = VDecl->getType(); in AddInitializerToDecl()
9600 BaseDeclType = Array->getElementType(); in AddInitializerToDecl()
9601 if (RequireCompleteType(VDecl->getLocation(), BaseDeclType, in AddInitializerToDecl()
9603 RealDecl->setInvalidDecl(); in AddInitializerToDecl()
9608 if (RequireNonAbstractType(VDecl->getLocation(), VDecl->getType(), in AddInitializerToDecl()
9611 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9615 if ((Def = VDecl->getDefinition()) && Def != VDecl) { in AddInitializerToDecl()
9618 (VDecl->getFormalLinkage() == InternalLinkage || in AddInitializerToDecl()
9619 VDecl->getDescribedVarTemplate() || in AddInitializerToDecl()
9620 VDecl->getNumTemplateParameterLists() || in AddInitializerToDecl()
9621 VDecl->getDeclContext()->isDependentContext())) { in AddInitializerToDecl()
9625 Diag(VDecl->getLocation(), diag::err_redefinition) in AddInitializerToDecl()
9626 << VDecl->getDeclName(); in AddInitializerToDecl()
9627 Diag(Def->getLocation(), diag::note_previous_definition); in AddInitializerToDecl()
9628 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9637 // specify a constant-initializer which shall be an integral in AddInitializerToDecl()
9644 // data members we also need to check whether there was an in-class in AddInitializerToDecl()
9646 if (VDecl->isStaticDataMember() && VDecl->getCanonicalDecl()->hasInit()) { in AddInitializerToDecl()
9647 Diag(Init->getExprLoc(), diag::err_static_data_member_reinitialization) in AddInitializerToDecl()
9648 << VDecl->getDeclName(); in AddInitializerToDecl()
9649 Diag(VDecl->getCanonicalDecl()->getInit()->getExprLoc(), in AddInitializerToDecl()
9655 if (VDecl->hasLocalStorage()) in AddInitializerToDecl()
9656 getCurFunction()->setHasBranchProtectedScope(); in AddInitializerToDecl()
9659 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9666 if (VDecl->getType().getAddressSpace() == LangAS::opencl_local) { in AddInitializerToDecl()
9667 Diag(VDecl->getLocation(), diag::err_local_cant_init); in AddInitializerToDecl()
9668 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9674 QualType DclT = VDecl->getType(), SavT = DclT; in AddInitializerToDecl()
9677 // and we are assigning it to a variable of Objective-C pointer type. in AddInitializerToDecl()
9678 if (getLangOpts().DebuggerCastResultToId && DclT->isObjCObjectPointerType() && in AddInitializerToDecl()
9679 Init->getType() == Context.UnknownAnyTy) { in AddInitializerToDecl()
9682 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9690 if (!VDecl->isInvalidDecl()) { in AddInitializerToDecl()
9695 ? InitializationKind::CreateDirect(VDecl->getLocation(), in AddInitializerToDecl()
9696 Init->getLocStart(), in AddInitializerToDecl()
9697 Init->getLocEnd()) in AddInitializerToDecl()
9698 : InitializationKind::CreateDirectList(VDecl->getLocation()) in AddInitializerToDecl()
9699 : InitializationKind::CreateCopy(VDecl->getLocation(), in AddInitializerToDecl()
9700 Init->getLocStart()); in AddInitializerToDecl()
9704 Args = MultiExprArg(CXXDirectInit->getExprs(), in AddInitializerToDecl()
9705 CXXDirectInit->getNumExprs()); in AddInitializerToDecl()
9715 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9720 if (VDecl->isInvalidDecl()) in AddInitializerToDecl()
9728 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9735 // Check for self-references within variable initializers. in AddInitializerToDecl()
9738 if (!VDecl->hasLocalStorage() || VDecl->getType()->isRecordType() || in AddInitializerToDecl()
9739 VDecl->getType()->isReferenceType()) { in AddInitializerToDecl()
9747 if (!VDecl->isInvalidDecl() && (DclT != SavT)) in AddInitializerToDecl()
9748 VDecl->setType(DclT); in AddInitializerToDecl()
9750 if (!VDecl->isInvalidDecl()) { in AddInitializerToDecl()
9751 checkUnsafeAssigns(VDecl->getLocation(), VDecl->getType(), Init); in AddInitializerToDecl()
9753 if (VDecl->hasAttr<BlocksAttr>()) in AddInitializerToDecl()
9762 // -Wrepeated-use-of-weak is made flow-sensitive. in AddInitializerToDecl()
9763 if (VDecl->getType().getObjCLifetime() == Qualifiers::OCL_Strong && in AddInitializerToDecl()
9765 Init->getLocStart())) in AddInitializerToDecl()
9766 getCurFunction()->markSafeWeakUse(Init); in AddInitializerToDecl()
9769 // The initialization is usually a full-expression. in AddInitializerToDecl()
9773 // full-expression. For instance, in: in AddInitializerToDecl()
9780 ExprResult Result = ActOnFinishFullExpr(Init, VDecl->getLocation(), in AddInitializerToDecl()
9782 VDecl->isConstexpr()); in AddInitializerToDecl()
9784 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9790 VDecl->setInit(Init); in AddInitializerToDecl()
9792 if (VDecl->isLocalVarDecl()) { in AddInitializerToDecl()
9796 if (!getLangOpts().CPlusPlus && !VDecl->isInvalidDecl()) { in AddInitializerToDecl()
9798 if (VDecl->getStorageClass() == SC_Static) in AddInitializerToDecl()
9800 // C89 is stricter than C99 for non-static aggregate types. in AddInitializerToDecl()
9804 else if (!getLangOpts().C99 && VDecl->getType()->isAggregateType() && in AddInitializerToDecl()
9806 !Init->isConstantInitializer(Context, false, &Culprit)) in AddInitializerToDecl()
9807 Diag(Culprit->getExprLoc(), in AddInitializerToDecl()
9809 << Culprit->getSourceRange(); in AddInitializerToDecl()
9811 } else if (VDecl->isStaticDataMember() && !VDecl->isInline() && in AddInitializerToDecl()
9812 VDecl->getLexicalDeclContext()->isRecord()) { in AddInitializerToDecl()
9813 // This is an in-class initialization for a static data member, e.g., in AddInitializerToDecl()
9820 // A member-declarator can contain a constant-initializer only in AddInitializerToDecl()
9825 // If a non-volatile non-inline const static data member is of integral in AddInitializerToDecl()
9827 // specify a brace-or-equal-initializer in which every initalizer-clause in AddInitializerToDecl()
9828 // that is an assignment-expression is a constant expression. A static in AddInitializerToDecl()
9831 // brace-or-equal-initializer in which every initializer-clause that is in AddInitializerToDecl()
9832 // an assignment-expression is a constant expression. in AddInitializerToDecl()
9835 if (DclT->isDependentType()) { in AddInitializerToDecl()
9840 } else if (VDecl->isConstexpr()) { in AddInitializerToDecl()
9844 Diag(VDecl->getLocation(), diag::err_in_class_initializer_non_const) in AddInitializerToDecl()
9845 << Init->getSourceRange(); in AddInitializerToDecl()
9846 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9849 } else if (DclT->isIntegralOrEnumerationType()) { in AddInitializerToDecl()
9853 // In C++11, a non-constexpr const static data member with an in AddInitializerToDecl()
9854 // in-class initializer cannot be volatile. in AddInitializerToDecl()
9855 Diag(VDecl->getLocation(), diag::err_in_class_initializer_volatile); in AddInitializerToDecl()
9856 else if (Init->isValueDependent()) in AddInitializerToDecl()
9858 else if (Init->isIntegerConstantExpr(Context, &Loc)) in AddInitializerToDecl()
9860 else if (Init->isEvaluatable(Context)) { in AddInitializerToDecl()
9862 // but report this as a use of an extension for -pedantic. in AddInitializerToDecl()
9864 << Init->getSourceRange(); in AddInitializerToDecl()
9866 // Otherwise, this is some crazy unknown case. Report the issue at the in AddInitializerToDecl()
9869 << Init->getSourceRange(); in AddInitializerToDecl()
9870 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9873 // We allow foldable floating-point constants as an extension. in AddInitializerToDecl()
9874 } else if (DclT->isFloatingType()) { // also permits complex, which is ok in AddInitializerToDecl()
9878 Diag(VDecl->getLocation(), in AddInitializerToDecl()
9880 << DclT << Init->getSourceRange(); in AddInitializerToDecl()
9881 Diag(VDecl->getLocStart(), in AddInitializerToDecl()
9883 << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr "); in AddInitializerToDecl()
9885 Diag(VDecl->getLocation(), diag::ext_in_class_initializer_float_type) in AddInitializerToDecl()
9886 << DclT << Init->getSourceRange(); in AddInitializerToDecl()
9888 if (!Init->isValueDependent() && !Init->isEvaluatable(Context)) { in AddInitializerToDecl()
9889 Diag(Init->getExprLoc(), diag::err_in_class_initializer_non_constant) in AddInitializerToDecl()
9890 << Init->getSourceRange(); in AddInitializerToDecl()
9891 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9896 } else if (getLangOpts().CPlusPlus11 && DclT->isLiteralType(Context)) { in AddInitializerToDecl()
9897 Diag(VDecl->getLocation(), diag::err_in_class_initializer_literal_type) in AddInitializerToDecl()
9898 << DclT << Init->getSourceRange() in AddInitializerToDecl()
9899 << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr "); in AddInitializerToDecl()
9900 VDecl->setConstexpr(true); in AddInitializerToDecl()
9903 Diag(VDecl->getLocation(), diag::err_in_class_initializer_bad_type) in AddInitializerToDecl()
9904 << DclT << Init->getSourceRange(); in AddInitializerToDecl()
9905 VDecl->setInvalidDecl(); in AddInitializerToDecl()
9907 } else if (VDecl->isFileVarDecl()) { in AddInitializerToDecl()
9908 if (VDecl->getStorageClass() == SC_Extern && in AddInitializerToDecl()
9910 !(Context.getBaseElementType(VDecl->getType()).isConstQualified() || in AddInitializerToDecl()
9911 VDecl->isExternC())) && in AddInitializerToDecl()
9912 !isTemplateInstantiation(VDecl->getTemplateSpecializationKind())) in AddInitializerToDecl()
9913 Diag(VDecl->getLocation(), diag::warn_extern_init); in AddInitializerToDecl()
9916 if (!getLangOpts().CPlusPlus && !VDecl->isInvalidDecl()) in AddInitializerToDecl()
9920 // We will represent direct-initialization similarly to copy-initialization: in AddInitializerToDecl()
9921 // int x(1); -as-> int x = 1; in AddInitializerToDecl()
9922 // ClassType x(a,b,c); -as-> ClassType x = ClassType(a,b,c); in AddInitializerToDecl()
9935 assert(DirectInit && "Call-style initializer must be direct init."); in AddInitializerToDecl()
9936 VDecl->setInitStyle(VarDecl::CallInit); in AddInitializerToDecl()
9938 // This must be list-initialization. No other way is direct-initialization. in AddInitializerToDecl()
9939 VDecl->setInitStyle(VarDecl::ListInit); in AddInitializerToDecl()
9945 /// ActOnInitializerError - Given that there was an error parsing an
9949 // Our main concern here is re-establishing invariants like "a in ActOnInitializerError()
9951 if (!D || D->isInvalidDecl()) return; in ActOnInitializerError()
9958 D->setInvalidDecl(); in ActOnInitializerError()
9962 QualType Ty = VD->getType(); in ActOnInitializerError()
9963 if (Ty->isDependentType()) return; in ActOnInitializerError()
9966 if (RequireCompleteType(VD->getLocation(), in ActOnInitializerError()
9969 VD->setInvalidDecl(); in ActOnInitializerError()
9973 // Require a non-abstract type. in ActOnInitializerError()
9974 if (RequireNonAbstractType(VD->getLocation(), Ty, in ActOnInitializerError()
9977 VD->setInvalidDecl(); in ActOnInitializerError()
9992 QualType Type = Var->getType(); in ActOnUninitializedDecl()
9995 if (TypeMayContainAuto && Type->getContainedAutoType()) { in ActOnUninitializedDecl()
9996 Diag(Var->getLocation(), diag::err_auto_var_requires_init) in ActOnUninitializedDecl()
9997 << Var->getDeclName() << Type; in ActOnUninitializedDecl()
9998 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10004 // a brace-or-equal-initializer. in ActOnUninitializedDecl()
10008 if (Var->isConstexpr() && !Var->isThisDeclarationADefinition()) { in ActOnUninitializedDecl()
10009 if (Var->isStaticDataMember()) { in ActOnUninitializedDecl()
10010 // C++1z removes the relevant rule; the in-class declaration is always in ActOnUninitializedDecl()
10013 Diag(Var->getLocation(), in ActOnUninitializedDecl()
10015 << Var->getDeclName(); in ActOnUninitializedDecl()
10016 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10020 Diag(Var->getLocation(), diag::err_invalid_constexpr_var_decl); in ActOnUninitializedDecl()
10021 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10029 if (VarTemplateDecl *VTD = Var->getDescribedVarTemplate()) { in ActOnUninitializedDecl()
10030 if (VTD->isConcept()) { in ActOnUninitializedDecl()
10031 Diag(Var->getLocation(), diag::err_var_concept_not_initialized); in ActOnUninitializedDecl()
10032 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10039 if (!Var->isInvalidDecl() && in ActOnUninitializedDecl()
10040 Var->getType().getAddressSpace() == LangAS::opencl_constant && in ActOnUninitializedDecl()
10041 Var->getStorageClass() != SC_Extern && !Var->getInit()) { in ActOnUninitializedDecl()
10042 Diag(Var->getLocation(), diag::err_opencl_constant_no_init); in ActOnUninitializedDecl()
10043 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10047 switch (Var->isThisDeclarationADefinition()) { in ActOnUninitializedDecl()
10049 if (!Var->isStaticDataMember() || !Var->getAnyInitializer()) in ActOnUninitializedDecl()
10052 // We have an out-of-line definition of a static data member in ActOnUninitializedDecl()
10053 // that has an in-class initializer, so we type-check this like in ActOnUninitializedDecl()
10064 if (!Type->isDependentType() && Var->isLocalVarDecl() && in ActOnUninitializedDecl()
10065 !Var->hasLinkage() && !Var->isInvalidDecl() && in ActOnUninitializedDecl()
10066 RequireCompleteType(Var->getLocation(), Type, in ActOnUninitializedDecl()
10068 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10071 if (!Type->isDependentType() && !Var->isInvalidDecl() && in ActOnUninitializedDecl()
10072 RequireNonAbstractType(Var->getLocation(), Type, in ActOnUninitializedDecl()
10075 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10076 if (!Type->isDependentType() && !Var->isInvalidDecl() && in ActOnUninitializedDecl()
10077 Var->getStorageClass() == SC_PrivateExtern) { in ActOnUninitializedDecl()
10078 Diag(Var->getLocation(), diag::warn_private_extern); in ActOnUninitializedDecl()
10079 Diag(Var->getLocation(), diag::note_private_extern); in ActOnUninitializedDecl()
10087 // storage-class specifier or with the storage-class specifier "static", in ActOnUninitializedDecl()
10090 if (!Var->isInvalidDecl()) { in ActOnUninitializedDecl()
10093 if (RequireCompleteType(Var->getLocation(), in ActOnUninitializedDecl()
10094 ArrayT->getElementType(), in ActOnUninitializedDecl()
10096 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10097 } else if (Var->getStorageClass() == SC_Static) { in ActOnUninitializedDecl()
10104 // is accepted by gcc. Hence here we issue a warning instead of in ActOnUninitializedDecl()
10107 if (Var->isFirstDecl()) in ActOnUninitializedDecl()
10108 RequireCompleteType(Var->getLocation(), Type, in ActOnUninitializedDecl()
10114 if (!Var->isInvalidDecl()) in ActOnUninitializedDecl()
10121 if (Type->isIncompleteArrayType()) { in ActOnUninitializedDecl()
10122 Diag(Var->getLocation(), in ActOnUninitializedDecl()
10124 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10130 if (Type->isReferenceType()) { in ActOnUninitializedDecl()
10131 Diag(Var->getLocation(), diag::err_reference_var_requires_init) in ActOnUninitializedDecl()
10132 << Var->getDeclName() in ActOnUninitializedDecl()
10133 << SourceRange(Var->getLocation(), Var->getLocation()); in ActOnUninitializedDecl()
10134 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10138 // Do not attempt to type-check the default initializer for a in ActOnUninitializedDecl()
10140 if (Type->isDependentType()) in ActOnUninitializedDecl()
10143 if (Var->isInvalidDecl()) in ActOnUninitializedDecl()
10146 if (!Var->hasAttr<AliasAttr>()) { in ActOnUninitializedDecl()
10147 if (RequireCompleteType(Var->getLocation(), in ActOnUninitializedDecl()
10150 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10158 if (RequireNonAbstractType(Var->getLocation(), Type, in ActOnUninitializedDecl()
10161 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10171 // ill-formed unless the variable has scalar type, class type with a in ActOnUninitializedDecl()
10172 // trivial default constructor and a trivial destructor, a cv-qualified in ActOnUninitializedDecl()
10175 if (getLangOpts().CPlusPlus && Var->hasLocalStorage()) { in ActOnUninitializedDecl()
10177 = Context.getBaseElementType(Type)->getAs<RecordType>()) { in ActOnUninitializedDecl()
10178 CXXRecordDecl *CXXRecord = cast<CXXRecordDecl>(Record->getDecl()); in ActOnUninitializedDecl()
10182 if (!CXXRecord->isPOD()) in ActOnUninitializedDecl()
10183 getCurFunction()->setHasBranchProtectedScope(); in ActOnUninitializedDecl()
10189 // object is of (possibly cv-qualified) non-POD class type (or in ActOnUninitializedDecl()
10190 // array thereof), the object shall be default-initialized; if in ActOnUninitializedDecl()
10191 // the object is of const-qualified type, the underlying class in ActOnUninitializedDecl()
10192 // type shall have a user-declared default in ActOnUninitializedDecl()
10194 // a non- static object, the object and its subobjects, if in ActOnUninitializedDecl()
10196 // or any of its subobjects are of const-qualified type, the in ActOnUninitializedDecl()
10197 // program is ill-formed. in ActOnUninitializedDecl()
10200 // default-initialized; [...]. in ActOnUninitializedDecl()
10203 = InitializationKind::CreateDefault(Var->getLocation()); in ActOnUninitializedDecl()
10208 Var->setInvalidDecl(); in ActOnUninitializedDecl()
10210 Var->setInit(MaybeCreateExprWithCleanups(Init.get())); in ActOnUninitializedDecl()
10212 Var->setInitStyle(VarDecl::CallInit); in ActOnUninitializedDecl()
10226 Diag(D->getLocation(), diag::err_for_range_decl_must_be_var); in ActOnCXXForRangeDecl()
10227 D->setInvalidDecl(); in ActOnCXXForRangeDecl()
10231 VD->setCXXForRangeDecl(true); in ActOnCXXForRangeDecl()
10233 // for-range-declaration cannot be given a storage class specifier. in ActOnCXXForRangeDecl()
10234 int Error = -1; in ActOnCXXForRangeDecl()
10235 switch (VD->getStorageClass()) { in ActOnCXXForRangeDecl()
10254 if (Error != -1) { in ActOnCXXForRangeDecl()
10255 Diag(VD->getOuterLocStart(), diag::err_for_range_storage_class) in ActOnCXXForRangeDecl()
10256 << VD->getDeclName() << Error; in ActOnCXXForRangeDecl()
10257 D->setInvalidDecl(); in ActOnCXXForRangeDecl()
10267 // A range-based for statement of the form in ActOnCXXForRangeIdentifier()
10268 // for ( for-range-identifier : for-range-initializer ) statement in ActOnCXXForRangeIdentifier()
10270 // for ( auto&& for-range-identifier : for-range-initializer ) statement in ActOnCXXForRangeIdentifier()
10286 cast<VarDecl>(Var)->setCXXForRangeDecl(true); in ActOnCXXForRangeIdentifier()
10293 if (var->isInvalidDecl()) return; in CheckCompleteVariableDeclaration()
10296 // OpenCL v2.0 s6.12.5 - Every block variable declaration must have an in CheckCompleteVariableDeclaration()
10298 if (var->getTypeSourceInfo()->getType()->isBlockPointerType() && in CheckCompleteVariableDeclaration()
10299 !var->hasInit()) { in CheckCompleteVariableDeclaration()
10300 Diag(var->getLocation(), diag::err_opencl_invalid_block_declaration) in CheckCompleteVariableDeclaration()
10302 var->setInvalidDecl(); in CheckCompleteVariableDeclaration()
10307 // In Objective-C, don't allow jumps past the implicit initialization of a in CheckCompleteVariableDeclaration()
10310 var->hasLocalStorage()) { in CheckCompleteVariableDeclaration()
10311 switch (var->getType().getObjCLifetime()) { in CheckCompleteVariableDeclaration()
10319 getCurFunction()->setHasBranchProtectedScope(); in CheckCompleteVariableDeclaration()
10324 // Warn about externally-visible variables being defined without a in CheckCompleteVariableDeclaration()
10329 if (var->isThisDeclarationADefinition() && in CheckCompleteVariableDeclaration()
10330 var->getDeclContext()->getRedeclContext()->isFileContext() && in CheckCompleteVariableDeclaration()
10331 var->isExternallyVisible() && var->hasLinkage() && in CheckCompleteVariableDeclaration()
10333 var->getLocation())) { in CheckCompleteVariableDeclaration()
10335 VarDecl *prev = var->getPreviousDecl(); in CheckCompleteVariableDeclaration()
10336 while (prev && prev->isThisDeclarationADefinition()) in CheckCompleteVariableDeclaration()
10337 prev = prev->getPreviousDecl(); in CheckCompleteVariableDeclaration()
10340 Diag(var->getLocation(), diag::warn_missing_variable_declarations) << var; in CheckCompleteVariableDeclaration()
10343 if (var->getTLSKind() == VarDecl::TLS_Static) { in CheckCompleteVariableDeclaration()
10345 if (var->getType().isDestructedType()) { in CheckCompleteVariableDeclaration()
10348 // have a non-trivial destructor. in CheckCompleteVariableDeclaration()
10349 Diag(var->getLocation(), diag::err_thread_nontrivial_dtor); in CheckCompleteVariableDeclaration()
10351 Diag(var->getLocation(), diag::note_use_thread_local); in CheckCompleteVariableDeclaration()
10352 } else if (getLangOpts().CPlusPlus && var->hasInit() && in CheckCompleteVariableDeclaration()
10353 !var->getInit()->isConstantInitializer( in CheckCompleteVariableDeclaration()
10354 Context, var->getType()->isReferenceType(), &Culprit)) { in CheckCompleteVariableDeclaration()
10359 Diag(Culprit->getExprLoc(), diag::err_thread_dynamic_init) in CheckCompleteVariableDeclaration()
10360 << Culprit->getSourceRange(); in CheckCompleteVariableDeclaration()
10362 Diag(var->getLocation(), diag::note_use_thread_local); in CheckCompleteVariableDeclaration()
10367 bool GlobalStorage = var->hasGlobalStorage(); in CheckCompleteVariableDeclaration()
10368 if (GlobalStorage && var->isThisDeclarationADefinition() && in CheckCompleteVariableDeclaration()
10372 if (var->getType().isConstQualified()) in CheckCompleteVariableDeclaration()
10374 else if (!var->getInit()) { in CheckCompleteVariableDeclaration()
10381 if (Stack->CurrentValue && !var->hasAttr<SectionAttr>()) { in CheckCompleteVariableDeclaration()
10382 var->addAttr(SectionAttr::CreateImplicit( in CheckCompleteVariableDeclaration()
10384 Stack->CurrentValue->getString(), Stack->CurrentPragmaLocation)); in CheckCompleteVariableDeclaration()
10386 if (const SectionAttr *SA = var->getAttr<SectionAttr>()) in CheckCompleteVariableDeclaration()
10387 if (UnifySection(SA->getName(), SectionFlags, var)) in CheckCompleteVariableDeclaration()
10388 var->dropAttr<SectionAttr>(); in CheckCompleteVariableDeclaration()
10393 if (CurInitSeg && var->getInit()) in CheckCompleteVariableDeclaration()
10394 var->addAttr(InitSegAttr::CreateImplicit(Context, CurInitSeg->getString(), in CheckCompleteVariableDeclaration()
10401 QualType type = var->getType(); in CheckCompleteVariableDeclaration()
10402 if (type->isDependentType()) return; in CheckCompleteVariableDeclaration()
10404 // __block variables might require us to capture a copy-initializer. in CheckCompleteVariableDeclaration()
10405 if (var->hasAttr<BlocksAttr>()) { in CheckCompleteVariableDeclaration()
10411 if (type->isStructureOrClassType()) { in CheckCompleteVariableDeclaration()
10413 SourceLocation poi = var->getLocation(); in CheckCompleteVariableDeclaration()
10418 var, var->getType(), varRef, /*AllowNRVO=*/true); in CheckCompleteVariableDeclaration()
10427 Expr *Init = var->getInit(); in CheckCompleteVariableDeclaration()
10428 bool IsGlobal = GlobalStorage && !var->isStaticLocal(); in CheckCompleteVariableDeclaration()
10431 if (!var->getDeclContext()->isDependentContext() && in CheckCompleteVariableDeclaration()
10432 Init && !Init->isValueDependent()) { in CheckCompleteVariableDeclaration()
10433 if (IsGlobal && !var->isConstexpr() && in CheckCompleteVariableDeclaration()
10435 var->getLocation())) { in CheckCompleteVariableDeclaration()
10437 // warn about globals with a non-trivial destructor because we already in CheckCompleteVariableDeclaration()
10439 CXXRecordDecl *RD = baseType->getAsCXXRecordDecl(); in CheckCompleteVariableDeclaration()
10440 if (!(RD && !RD->hasTrivialDestructor()) && in CheckCompleteVariableDeclaration()
10441 !Init->isConstantInitializer(Context, baseType->isReferenceType())) in CheckCompleteVariableDeclaration()
10442 Diag(var->getLocation(), diag::warn_global_constructor) in CheckCompleteVariableDeclaration()
10443 << Init->getSourceRange(); in CheckCompleteVariableDeclaration()
10446 if (var->isConstexpr()) { in CheckCompleteVariableDeclaration()
10448 if (!var->evaluateValue(Notes) || !var->isInitICE()) { in CheckCompleteVariableDeclaration()
10449 SourceLocation DiagLoc = var->getLocation(); in CheckCompleteVariableDeclaration()
10458 << var << Init->getSourceRange(); in CheckCompleteVariableDeclaration()
10462 } else if (var->isUsableInConstantExpressions(Context)) { in CheckCompleteVariableDeclaration()
10466 var->checkInitIsICE(); in CheckCompleteVariableDeclaration()
10471 if (const RecordType *recordType = baseType->getAs<RecordType>()) in CheckCompleteVariableDeclaration()
10477 if (VD->getType()->isDependentType()) in hasDependentAlignment()
10479 for (auto *I : VD->specific_attrs<AlignedAttr>()) in hasDependentAlignment()
10480 if (I->isAlignmentDependent()) in hasDependentAlignment()
10485 /// FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform
10504 if (VD->getTLSKind() && !hasDependentAlignment(VD)) { in FinalizeDeclaration()
10507 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum) in FinalizeDeclaration()
10514 if (VD->isStaticLocal()) { in FinalizeDeclaration()
10516 dyn_cast_or_null<FunctionDecl>(VD->getParentFunctionOrMethod())) { in FinalizeDeclaration()
10519 auto *NewAttr = cast<InheritableAttr>(A->clone(getASTContext())); in FinalizeDeclaration()
10520 NewAttr->setInherited(true); in FinalizeDeclaration()
10521 VD->addAttr(NewAttr); in FinalizeDeclaration()
10527 (FD->hasAttr<CUDADeviceAttr>() || FD->hasAttr<CUDAGlobalAttr>()) && in FinalizeDeclaration()
10528 !VD->hasAttr<CUDASharedAttr>()) { in FinalizeDeclaration()
10529 Diag(VD->getLocation(), diag::err_device_static_local_var); in FinalizeDeclaration()
10530 VD->setInvalidDecl(); in FinalizeDeclaration()
10535 // Perform check for initializers of device-side global variables. in FinalizeDeclaration()
10541 const Expr *Init = VD->getInit(); in FinalizeDeclaration()
10542 if (Init && VD->hasGlobalStorage() && in FinalizeDeclaration()
10543 (VD->hasAttr<CUDADeviceAttr>() || VD->hasAttr<CUDAConstantAttr>() || in FinalizeDeclaration()
10544 VD->hasAttr<CUDASharedAttr>())) { in FinalizeDeclaration()
10545 assert((!VD->isStaticLocal() || VD->hasAttr<CUDASharedAttr>())); in FinalizeDeclaration()
10549 isEmptyCudaConstructor(VD->getLocation(), CE->getConstructor()); in FinalizeDeclaration()
10550 // We'll allow constant initializers even if it's a non-empty in FinalizeDeclaration()
10554 (VD->hasAttr<CUDADeviceAttr>() || VD->hasAttr<CUDAConstantAttr>())) in FinalizeDeclaration()
10555 AllowedInit = VD->getInit()->isConstantInitializer( in FinalizeDeclaration()
10556 Context, VD->getType()->isReferenceType()); in FinalizeDeclaration()
10560 if (CXXRecordDecl *RD = VD->getType()->getAsCXXRecordDecl()) in FinalizeDeclaration()
10562 isEmptyCudaDestructor(VD->getLocation(), RD->getDestructor()); in FinalizeDeclaration()
10565 Diag(VD->getLocation(), VD->hasAttr<CUDASharedAttr>() in FinalizeDeclaration()
10568 << Init->getSourceRange(); in FinalizeDeclaration()
10569 VD->setInvalidDecl(); in FinalizeDeclaration()
10577 // Imported static data members cannot be defined out-of-line. in FinalizeDeclaration()
10579 if (VD->isStaticDataMember() && VD->isOutOfLine() && in FinalizeDeclaration()
10580 VD->isThisDeclarationADefinition()) { in FinalizeDeclaration()
10584 cast<CXXRecordDecl>(VD->getFirstDecl()->getDeclContext()); in FinalizeDeclaration()
10587 Context->getDescribedClassTemplate(); in FinalizeDeclaration()
10589 Diag(VD->getLocation(), in FinalizeDeclaration()
10593 Diag(IA->getLocation(), diag::note_attribute); in FinalizeDeclaration()
10595 VD->setInvalidDecl(); in FinalizeDeclaration()
10601 if (DLLAttr && VD->getTLSKind()) { in FinalizeDeclaration()
10602 auto *F = dyn_cast_or_null<FunctionDecl>(VD->getParentFunctionOrMethod()); in FinalizeDeclaration()
10604 assert(VD->isStaticLocal()); in FinalizeDeclaration()
10609 Diag(VD->getLocation(), diag::err_attribute_dll_thread_local) << VD in FinalizeDeclaration()
10611 VD->setInvalidDecl(); in FinalizeDeclaration()
10615 if (UsedAttr *Attr = VD->getAttr<UsedAttr>()) { in FinalizeDeclaration()
10616 if (!Attr->isInherited() && !VD->isThisDeclarationADefinition()) { in FinalizeDeclaration()
10617 Diag(Attr->getLocation(), diag::warn_attribute_ignored) << Attr; in FinalizeDeclaration()
10618 VD->dropAttr<UsedAttr>(); in FinalizeDeclaration()
10622 const DeclContext *DC = VD->getDeclContext(); in FinalizeDeclaration()
10625 if (DC->getRedeclContext()->isFileContext() && VD->isExternallyVisible()) in FinalizeDeclaration()
10629 if (VD->isFileVarDecl() && !VD->getDescribedVarTemplate() && in FinalizeDeclaration()
10635 if (!VD->hasAttr<TypeTagForDatatypeAttr>() || in FinalizeDeclaration()
10636 !VD->getType()->isIntegralOrEnumerationType()) in FinalizeDeclaration()
10639 for (const auto *I : ThisDecl->specific_attrs<TypeTagForDatatypeAttr>()) { in FinalizeDeclaration()
10640 const Expr *MagicValueExpr = VD->getInit(); in FinalizeDeclaration()
10645 if (!MagicValueExpr->isIntegerConstantExpr(MagicValueInt, Context)) { in FinalizeDeclaration()
10646 Diag(I->getRange().getBegin(), in FinalizeDeclaration()
10648 << LangOpts.CPlusPlus << MagicValueExpr->getSourceRange(); in FinalizeDeclaration()
10652 Diag(I->getRange().getBegin(), in FinalizeDeclaration()
10654 << LangOpts.CPlusPlus << MagicValueExpr->getSourceRange(); in FinalizeDeclaration()
10658 RegisterTypeTagForDatatype(I->getArgumentKind(), in FinalizeDeclaration()
10660 I->getMatchingCType(), in FinalizeDeclaration()
10661 I->getLayoutCompatible(), in FinalizeDeclaration()
10662 I->getMustBeNull()); in FinalizeDeclaration()
10685 if (FirstDeclaratorInGroup && !Tag->hasNameForLinkage() && in FinalizeDeclaratorGroup()
10694 /// BuildDeclaratorGroup - convert a list of declarations into a declaration
10701 // deduction, the program is ill-formed. in BuildDeclaratorGroup()
10702 // FIXME: When initializer-list support is added, a distinction is needed in BuildDeclaratorGroup()
10712 AutoType *AT = D->getType()->getContainedAutoType(); in BuildDeclaratorGroup()
10714 if (AT && D->isInvalidDecl()) in BuildDeclaratorGroup()
10716 QualType U = AT ? AT->getDeducedType() : QualType(); in BuildDeclaratorGroup()
10724 Diag(D->getTypeSourceInfo()->getTypeLoc().getBeginLoc(), in BuildDeclaratorGroup()
10726 << (unsigned)AT->getKeyword() in BuildDeclaratorGroup()
10727 << Deduced << DeducedDecl->getDeclName() in BuildDeclaratorGroup()
10728 << U << D->getDeclName() in BuildDeclaratorGroup()
10729 << DeducedDecl->getInit()->getSourceRange() in BuildDeclaratorGroup()
10730 << D->getInit()->getSourceRange(); in BuildDeclaratorGroup()
10731 D->setInvalidDecl(); in BuildDeclaratorGroup()
10755 Group[0]->getLocation()) && in ActOnDocumentableDecls()
10757 Group[0]->getLocation())) in ActOnDocumentableDecls()
10777 !Comments.back()->isAttached()) { in ActOnDocumentableDecls()
10782 // declaration, but also comments that *follow* the declaration -- thanks to in ActOnDocumentableDecls()
10790 /// ActOnParamDeclarator - Called from Parser::ParseFunctionDeclarator()
10825 QualType parmDeclType = TInfo->getType(); in ActOnParamDeclarator()
10858 if (PrevDecl->isTemplateParameter()) { in ActOnParamDeclarator()
10863 } else if (S->isDeclScope(PrevDecl)) { in ActOnParamDeclarator()
10865 Diag(PrevDecl->getLocation(), diag::note_previous_declaration); in ActOnParamDeclarator()
10885 New->setInvalidDecl(); in ActOnParamDeclarator()
10887 assert(S->isFunctionPrototypeScope()); in ActOnParamDeclarator()
10888 assert(S->getFunctionPrototypeDepth() >= 1); in ActOnParamDeclarator()
10889 New->setScopeInfo(S->getFunctionPrototypeDepth() - 1, in ActOnParamDeclarator()
10890 S->getNextFunctionPrototypeIndex()); in ActOnParamDeclarator()
10893 S->AddDecl(New); in ActOnParamDeclarator()
10900 Diag(New->getLocation(), diag::err_module_private_local) in ActOnParamDeclarator()
10901 << 1 << New->getDeclName() in ActOnParamDeclarator()
10905 if (New->hasAttr<BlocksAttr>()) { in ActOnParamDeclarator()
10906 Diag(New->getLocation(), diag::err_block_on_nonlocal); in ActOnParamDeclarator()
10922 Param->setImplicit(); in BuildParmVarDeclForTypedef()
10927 // Don't diagnose unused-parameter errors in template instantiations; we in DiagnoseUnusedParameters()
10933 if (!Parameter->isReferenced() && Parameter->getDeclName() && in DiagnoseUnusedParameters()
10934 !Parameter->hasAttr<UnusedAttr>()) { in DiagnoseUnusedParameters()
10935 Diag(Parameter->getLocation(), diag::warn_unused_parameter) in DiagnoseUnusedParameters()
10936 << Parameter->getDeclName(); in DiagnoseUnusedParameters()
10946 // Warn if the return value is pass-by-value and larger than the specified in DiagnoseSizeOfParametersAndReturnValue()
10948 if (!ReturnTy->isDependentType() && ReturnTy.isPODType(Context)) { in DiagnoseSizeOfParametersAndReturnValue()
10951 Diag(D->getLocation(), diag::warn_return_value_size) in DiagnoseSizeOfParametersAndReturnValue()
10952 << D->getDeclName() << Size; in DiagnoseSizeOfParametersAndReturnValue()
10955 // Warn if any parameter is pass-by-value and larger than the specified in DiagnoseSizeOfParametersAndReturnValue()
10958 QualType T = Parameter->getType(); in DiagnoseSizeOfParametersAndReturnValue()
10959 if (T->isDependentType() || !T.isPODType(Context)) in DiagnoseSizeOfParametersAndReturnValue()
10963 Diag(Parameter->getLocation(), diag::warn_parameter_size) in DiagnoseSizeOfParametersAndReturnValue()
10964 << Parameter->getDeclName() << Size; in DiagnoseSizeOfParametersAndReturnValue()
10975 T->isObjCLifetimeType()) { in CheckParameter()
10980 // - if it's const, use __unsafe_unretained in CheckParameter()
10981 // - otherwise, it's an error in CheckParameter()
10982 if (T->isArrayType()) { in CheckParameter()
10990 lifetime = T->getObjCARCImplicitLifetime(); in CheckParameter()
11002 if (!CurContext->isRecord() && in CheckParameter()
11005 New->setInvalidDecl(); in CheckParameter()
11009 if (T->isObjCObjectType()) { in CheckParameter()
11011 getLocForEndOfToken(TSInfo->getTypeLoc().getLocEnd()); in CheckParameter()
11016 New->setType(T); in CheckParameter()
11020 // duration shall not be qualified by an address-space qualifier." in CheckParameter()
11026 if (!(getLangOpts().OpenCL && T->isArrayType())) { in CheckParameter()
11028 New->setInvalidDecl(); in CheckParameter()
11043 --i; in ActOnFinishKNRParamDeclarations()
11047 << " int " << FTI.Params[i].Ident->getName() << ";\n"; in ActOnFinishKNRParamDeclarations()
11077 Scope *ParentScope = FnBodyScope->getParent(); in ActOnStartOfFunctionDef()
11091 if (FD->isInvalidDecl()) in ShouldWarnAboutMissingPrototype()
11095 if (!FD->isGlobal()) in ShouldWarnAboutMissingPrototype()
11103 if (FD->isMain()) in ShouldWarnAboutMissingPrototype()
11107 if (FD->isInlined()) in ShouldWarnAboutMissingPrototype()
11111 if (FD->getDescribedFunctionTemplate()) in ShouldWarnAboutMissingPrototype()
11115 if (FD->isFunctionTemplateSpecialization()) in ShouldWarnAboutMissingPrototype()
11119 if (FD->hasAttr<OpenCLKernelAttr>()) in ShouldWarnAboutMissingPrototype()
11123 if (FD->isDeleted()) in ShouldWarnAboutMissingPrototype()
11127 for (const FunctionDecl *Prev = FD->getPreviousDecl(); in ShouldWarnAboutMissingPrototype()
11128 Prev; Prev = Prev->getPreviousDecl()) { in ShouldWarnAboutMissingPrototype()
11131 if (Prev->getLexicalDeclContext()->isFunctionOrMethod()) in ShouldWarnAboutMissingPrototype()
11134 MissingPrototype = !Prev->getType()->isFunctionProtoType(); in ShouldWarnAboutMissingPrototype()
11135 if (FD->getNumParams() == 0) in ShouldWarnAboutMissingPrototype()
11151 if (!FD->isDefined(Definition)) in CheckForFunctionRedefinition()
11160 (Definition->getFormalLinkage() == InternalLinkage || in CheckForFunctionRedefinition()
11161 Definition->isInlined() || in CheckForFunctionRedefinition()
11162 Definition->getDescribedFunctionTemplate() || in CheckForFunctionRedefinition()
11163 Definition->getNumTemplateParameterLists())) { in CheckForFunctionRedefinition()
11164 SkipBody->ShouldSkip = true; in CheckForFunctionRedefinition()
11165 if (auto *TD = Definition->getDescribedFunctionTemplate()) in CheckForFunctionRedefinition()
11166 makeMergedDefinitionVisible(TD, FD->getLocation()); in CheckForFunctionRedefinition()
11169 FD->getLocation()); in CheckForFunctionRedefinition()
11173 if (getLangOpts().GNUMode && Definition->isInlineSpecified() && in CheckForFunctionRedefinition()
11174 Definition->getStorageClass() == SC_Extern) in CheckForFunctionRedefinition()
11175 Diag(FD->getLocation(), diag::err_redefinition_extern_inline) in CheckForFunctionRedefinition()
11176 << FD->getDeclName() << getLangOpts().CPlusPlus; in CheckForFunctionRedefinition()
11178 Diag(FD->getLocation(), diag::err_redefinition) << FD->getDeclName(); in CheckForFunctionRedefinition()
11180 Diag(Definition->getLocation(), diag::note_previous_definition); in CheckForFunctionRedefinition()
11181 FD->setInvalidDecl(); in CheckForFunctionRedefinition()
11186 CXXRecordDecl *const LambdaClass = CallOperator->getParent(); in RebuildLambdaScopeInfo()
11189 LSI->CallOperator = CallOperator; in RebuildLambdaScopeInfo()
11190 LSI->Lambda = LambdaClass; in RebuildLambdaScopeInfo()
11191 LSI->ReturnType = CallOperator->getReturnType(); in RebuildLambdaScopeInfo()
11192 const LambdaCaptureDefault LCD = LambdaClass->getLambdaCaptureDefault(); in RebuildLambdaScopeInfo()
11195 LSI->ImpCaptureStyle = CapturingScopeInfo::ImpCap_None; in RebuildLambdaScopeInfo()
11197 LSI->ImpCaptureStyle = CapturingScopeInfo::ImpCap_LambdaByval; in RebuildLambdaScopeInfo()
11199 LSI->ImpCaptureStyle = CapturingScopeInfo::ImpCap_LambdaByref; in RebuildLambdaScopeInfo()
11200 DeclarationNameInfo DNI = CallOperator->getNameInfo(); in RebuildLambdaScopeInfo()
11202 LSI->IntroducerRange = DNI.getCXXOperatorNameRange(); in RebuildLambdaScopeInfo()
11203 LSI->Mutable = !CallOperator->isConst(); in RebuildLambdaScopeInfo()
11207 auto I = LambdaClass->field_begin(); in RebuildLambdaScopeInfo()
11208 for (const auto &C : LambdaClass->captures()) { in RebuildLambdaScopeInfo()
11211 if (VD->isInitCapture()) in RebuildLambdaScopeInfo()
11212 S.CurrentInstantiationScope->InstantiatedLocal(VD, VD); in RebuildLambdaScopeInfo()
11213 QualType CaptureType = VD->getType(); in RebuildLambdaScopeInfo()
11215 LSI->addCapture(VD, /*IsBlock*/false, ByRef, in RebuildLambdaScopeInfo()
11222 LSI->addThisCapture(/*Nested*/ false, C.getLocation(), in RebuildLambdaScopeInfo()
11226 LSI->addVLATypeCapture(C.getLocation(), I->getType()); in RebuildLambdaScopeInfo()
11242 FD = FunTmpl->getTemplatedDecl(); in ActOnStartOfFunctionDef()
11247 if (!FD->isLateTemplateParsed()) { in ActOnStartOfFunctionDef()
11251 if (SkipBody && SkipBody->ShouldSkip) in ActOnStartOfFunctionDef()
11275 if (unsigned BuiltinID = FD->getBuiltinID()) { in ActOnStartOfFunctionDef()
11278 Diag(FD->getLocation(), diag::err_builtin_definition) << FD; in ActOnStartOfFunctionDef()
11279 FD->setInvalidDecl(); in ActOnStartOfFunctionDef()
11285 QualType ResultType = FD->getReturnType(); in ActOnStartOfFunctionDef()
11286 if (!ResultType->isDependentType() && !ResultType->isVoidType() && in ActOnStartOfFunctionDef()
11287 !FD->isInvalidDecl() && in ActOnStartOfFunctionDef()
11288 RequireCompleteType(FD->getLocation(), ResultType, in ActOnStartOfFunctionDef()
11290 FD->setInvalidDecl(); in ActOnStartOfFunctionDef()
11296 CheckParmsForFunctionDef(FD->parameters(), in ActOnStartOfFunctionDef()
11300 for (auto Param : FD->parameters()) { in ActOnStartOfFunctionDef()
11301 Param->setOwningFunction(FD); in ActOnStartOfFunctionDef()
11304 if (Param->getIdentifier() && FnBodyScope) { in ActOnStartOfFunctionDef()
11315 I = FD->getDeclsInPrototypeScope().begin(), in ActOnStartOfFunctionDef()
11316 E = FD->getDeclsInPrototypeScope().end(); in ActOnStartOfFunctionDef()
11323 if (D->getLexicalDeclContext() == Context.getTranslationUnitDecl()) { in ActOnStartOfFunctionDef()
11325 if (Context.getTranslationUnitDecl()->containsDecl(D)) in ActOnStartOfFunctionDef()
11326 Context.getTranslationUnitDecl()->removeDecl(D); in ActOnStartOfFunctionDef()
11328 D->setLexicalDeclContext(CurContext); in ActOnStartOfFunctionDef()
11331 // If the decl has a non-null name, make accessible in the current scope. in ActOnStartOfFunctionDef()
11332 if (!D->getName().empty()) in ActOnStartOfFunctionDef()
11338 for (auto *EI : ED->enumerators()) in ActOnStartOfFunctionDef()
11345 if (const FunctionProtoType *FPT = FD->getType()->getAs<FunctionProtoType>()) in ActOnStartOfFunctionDef()
11346 ResolveExceptionSpec(D->getLocation(), FPT); in ActOnStartOfFunctionDef()
11348 // dllimport cannot be applied to non-inline function definitions. in ActOnStartOfFunctionDef()
11349 if (FD->hasAttr<DLLImportAttr>() && !FD->isInlined() && in ActOnStartOfFunctionDef()
11350 !FD->isTemplateInstantiation()) { in ActOnStartOfFunctionDef()
11351 assert(!FD->hasAttr<DLLExportAttr>()); in ActOnStartOfFunctionDef()
11352 Diag(FD->getLocation(), diag::err_attribute_dllimport_function_definition); in ActOnStartOfFunctionDef()
11353 FD->setInvalidDecl(); in ActOnStartOfFunctionDef()
11359 if (getCurLexicalContext()->isObjCContainer() && in ActOnStartOfFunctionDef()
11360 getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl && in ActOnStartOfFunctionDef()
11361 getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation) in ActOnStartOfFunctionDef()
11362 Diag(FD->getLocation(), diag::warn_function_def_in_objc_container); in ActOnStartOfFunctionDef()
11380 ReturnStmt **Returns = Scope->Returns.data(); in computeNRVO()
11382 for (unsigned I = 0, E = Scope->Returns.size(); I != E; ++I) { in computeNRVO()
11383 if (const VarDecl *NRVOCandidate = Returns[I]->getNRVOCandidate()) { in computeNRVO()
11384 if (!NRVOCandidate->isNRVOVariable()) in computeNRVO()
11385 Returns[I]->setNRVOCandidate(nullptr); in computeNRVO()
11398 // If the placeholder introduces a non-deduced trailing return type, in canDelayFunctionBody()
11401 const auto &Outer = D.getTypeObject(D.getNumTypeObjects() - 1); in canDelayFunctionBody()
11405 return Ty.isNull() || !Ty->isUndeducedType(); in canDelayFunctionBody()
11420 if (const FunctionDecl *FD = D->getAsFunction()) in canSkipFunctionBody()
11421 if (FD->isConstexpr() || FD->getReturnType()->isUndeducedType()) in canSkipFunctionBody()
11428 FD->setHasSkippedBody(); in ActOnSkippedFunctionBody()
11430 MD->setHasSkippedBody(); in ActOnSkippedFunctionBody()
11440 FunctionDecl *FD = dcl ? dcl->getAsFunction() : nullptr; in ActOnFinishFunctionBody()
11445 if (getLangOpts().Coroutines && !getCurFunction()->CoroutineStmts.empty()) in ActOnFinishFunctionBody()
11449 FD->setBody(Body); in ActOnFinishFunctionBody()
11452 if (!FD->isInvalidDecl() && Body && !FD->isDependentContext() && in ActOnFinishFunctionBody()
11453 FD->getReturnType()->isUndeducedType()) { in ActOnFinishFunctionBody()
11457 if (!FD->getReturnType()->getAs<AutoType>()) { in ActOnFinishFunctionBody()
11458 Diag(dcl->getLocation(), diag::err_auto_fn_no_return_but_not_auto) in ActOnFinishFunctionBody()
11459 << FD->getReturnType(); in ActOnFinishFunctionBody()
11460 FD->setInvalidDecl(); in ActOnFinishFunctionBody()
11472 if (LSI->HasImplicitReturnType) { in ActOnFinishFunctionBody()
11476 // [...] if there are no return statements in the compound-statement in ActOnFinishFunctionBody()
11479 LSI->ReturnType.isNull() ? Context.VoidTy : LSI->ReturnType; in ActOnFinishFunctionBody()
11483 FD->getType()->getAs<FunctionProtoType>(); in ActOnFinishFunctionBody()
11484 FD->setType(Context.getFunctionType(RetType, Proto->getParamTypes(), in ActOnFinishFunctionBody()
11485 Proto->getExtProtoInfo())); in ActOnFinishFunctionBody()
11492 if (!FD->isFirstDecl() && FD->getPreviousDecl()->isUsed()) { in ActOnFinishFunctionBody()
11493 if (!FD->isExternallyVisible()) in ActOnFinishFunctionBody()
11495 else if (FD->isInlined() && in ActOnFinishFunctionBody()
11497 (!FD->getPreviousDecl()->hasAttr<GNUInlineAttr>())) in ActOnFinishFunctionBody()
11503 if (FD->hasImplicitReturnZero() || FD->hasAttr<NakedAttr>()) in ActOnFinishFunctionBody()
11507 // defined at class scope, warn about this non-standard construct. in ActOnFinishFunctionBody()
11508 if (getLangOpts().MicrosoftExt && FD->isPure() && FD->isCanonicalDecl()) in ActOnFinishFunctionBody()
11509 Diag(FD->getLocation(), diag::ext_pure_function_definition); in ActOnFinishFunctionBody()
11511 if (!FD->isInvalidDecl()) { in ActOnFinishFunctionBody()
11513 if (!FD->isDeleted() && !FD->isDefaulted()) in ActOnFinishFunctionBody()
11514 DiagnoseUnusedParameters(FD->parameters()); in ActOnFinishFunctionBody()
11515 DiagnoseSizeOfParametersAndReturnValue(FD->parameters(), in ActOnFinishFunctionBody()
11516 FD->getReturnType(), FD); in ActOnFinishFunctionBody()
11520 MarkVTableUsed(FD->getLocation(), Constructor->getParent()); in ActOnFinishFunctionBody()
11522 MarkVTableUsed(FD->getLocation(), Destructor->getParent()); in ActOnFinishFunctionBody()
11527 if (getLangOpts().CPlusPlus && FD->getReturnType()->isRecordType() && in ActOnFinishFunctionBody()
11528 !FD->isDependentContext()) in ActOnFinishFunctionBody()
11532 // GNU warning -Wmissing-prototypes: in ActOnFinishFunctionBody()
11539 Diag(FD->getLocation(), diag::warn_missing_prototype) << FD; in ActOnFinishFunctionBody()
11543 // but that could be a zero-parameter prototype in ActOnFinishFunctionBody()
11545 PossibleZeroParamPrototype->getTypeSourceInfo()) { in ActOnFinishFunctionBody()
11546 TypeLoc TL = TI->getTypeLoc(); in ActOnFinishFunctionBody()
11548 Diag(PossibleZeroParamPrototype->getLocation(), in ActOnFinishFunctionBody()
11558 if (MD->isOutOfLine() && (MD = MD->getCanonicalDecl()) && in ActOnFinishFunctionBody()
11559 MD->isVirtual() && in ActOnFinishFunctionBody()
11560 (KeyFunction = Context.getCurrentKeyFunction(MD->getParent())) && in ActOnFinishFunctionBody()
11561 MD == KeyFunction->getCanonicalDecl()) { in ActOnFinishFunctionBody()
11562 // Update the key-function state if necessary for this ABI. in ActOnFinishFunctionBody()
11563 if (FD->isInlined() && in ActOnFinishFunctionBody()
11567 // If the newly-chosen key function is already defined, then we in ActOnFinishFunctionBody()
11569 KeyFunction = Context.getCurrentKeyFunction(MD->getParent()); in ActOnFinishFunctionBody()
11571 if (KeyFunction && KeyFunction->isDefined(Definition)) in ActOnFinishFunctionBody()
11572 MarkVTableUsed(Definition->getLocation(), MD->getParent(), true); in ActOnFinishFunctionBody()
11575 MarkVTableUsed(FD->getLocation(), MD->getParent(), true); in ActOnFinishFunctionBody()
11580 assert((FD == getCurFunctionDecl() || getCurLambda()->CallOperator == FD) && in ActOnFinishFunctionBody()
11584 MD->setBody(Body); in ActOnFinishFunctionBody()
11585 if (!MD->isInvalidDecl()) { in ActOnFinishFunctionBody()
11586 DiagnoseUnusedParameters(MD->parameters()); in ActOnFinishFunctionBody()
11587 DiagnoseSizeOfParametersAndReturnValue(MD->parameters(), in ActOnFinishFunctionBody()
11588 MD->getReturnType(), MD); in ActOnFinishFunctionBody()
11593 if (getCurFunction()->ObjCShouldCallSuper) { in ActOnFinishFunctionBody()
11594 Diag(MD->getLocEnd(), diag::warn_objc_missing_super_call) in ActOnFinishFunctionBody()
11595 << MD->getSelector().getAsString(); in ActOnFinishFunctionBody()
11596 getCurFunction()->ObjCShouldCallSuper = false; in ActOnFinishFunctionBody()
11598 if (getCurFunction()->ObjCWarnForNoDesignatedInitChain) { in ActOnFinishFunctionBody()
11601 MD->isDesignatedInitializerForTheInterface(&InitMethod); in ActOnFinishFunctionBody()
11606 auto IFace = MD->getClassInterface(); in ActOnFinishFunctionBody()
11609 auto SuperD = IFace->getSuperClass(); in ActOnFinishFunctionBody()
11612 return SuperD->getIdentifier() == in ActOnFinishFunctionBody()
11613 NSAPIObj->getNSClassId(NSAPI::ClassId_NSObject); in ActOnFinishFunctionBody()
11615 // Don't issue this warning for unavailable inits or direct subclasses in ActOnFinishFunctionBody()
11617 if (!MD->isUnavailable() && !superIsNSObject(MD)) { in ActOnFinishFunctionBody()
11618 Diag(MD->getLocation(), in ActOnFinishFunctionBody()
11620 Diag(InitMethod->getLocation(), in ActOnFinishFunctionBody()
11623 getCurFunction()->ObjCWarnForNoDesignatedInitChain = false; in ActOnFinishFunctionBody()
11625 if (getCurFunction()->ObjCWarnForNoInitDelegation) { in ActOnFinishFunctionBody()
11626 // Don't issue this warning for unavaialable inits. in ActOnFinishFunctionBody()
11627 if (!MD->isUnavailable()) in ActOnFinishFunctionBody()
11628 Diag(MD->getLocation(), in ActOnFinishFunctionBody()
11630 getCurFunction()->ObjCWarnForNoInitDelegation = false; in ActOnFinishFunctionBody()
11636 assert(!getCurFunction()->ObjCShouldCallSuper && in ActOnFinishFunctionBody()
11640 // Verify and clean out per-function state. in ActOnFinishFunctionBody()
11641 if (Body && (!FD || !FD->isDefaulted())) { in ActOnFinishFunctionBody()
11642 // C++ constructors that have function-try-blocks can't have return in ActOnFinishFunctionBody()
11649 if (getCurFunction()->NeedsScopeChecking() && in ActOnFinishFunctionBody()
11654 if (!Destructor->getParent()->isDependentType()) in ActOnFinishFunctionBody()
11657 MarkBaseAndMemberDestructorsReferenced(Destructor->getLocation(), in ActOnFinishFunctionBody()
11658 Destructor->getParent()); in ActOnFinishFunctionBody()
11670 // Since the body is valid, issue any analysis-based warnings that are in ActOnFinishFunctionBody()
11675 if (!IsInstantiation && FD && FD->isConstexpr() && !FD->isInvalidDecl() && in ActOnFinishFunctionBody()
11678 FD->setInvalidDecl(); in ActOnFinishFunctionBody()
11680 if (FD && FD->hasAttr<NakedAttr>()) { in ActOnFinishFunctionBody()
11681 for (const Stmt *S : Body->children()) { in ActOnFinishFunctionBody()
11683 Diag(S->getLocStart(), diag::err_non_asm_stmt_in_naked_function); in ActOnFinishFunctionBody()
11684 Diag(FD->getAttr<NakedAttr>()->getLocation(), diag::note_attribute); in ActOnFinishFunctionBody()
11685 FD->setInvalidDecl(); in ActOnFinishFunctionBody()
11696 "Leftover expressions for odr-use checking"); in ActOnFinishFunctionBody()
11719 D = TD->getTemplatedDecl(); in ActOnFinishDelayedAttribute()
11723 if (Method->isStatic()) in ActOnFinishDelayedAttribute()
11727 /// ImplicitlyDefineFunction - An undeclared identifier was used in a function
11732 // function, see whether there was a locally-scoped declaration of in ImplicitlyDefineFunction()
11734 // (non-visible) declaration, and complain about it. in ImplicitlyDefineFunction()
11737 Diag(ExternCPrev->getLocation(), diag::note_previous_declaration); in ImplicitlyDefineFunction()
11800 // Insert this function into translation-unit scope. in ImplicitlyDefineFunction()
11806 FD->setImplicit(); in ImplicitlyDefineFunction()
11818 /// These attributes can apply both to implicitly-declared builtins
11819 /// (like __builtin___printf_chk) or to library-declared functions
11822 /// We need to check for duplicate attributes both here and where user-written
11825 if (FD->isInvalidDecl()) in AddKnownFunctionAttributes()
11828 // If this is a built-in function, map its builtin attributes to in AddKnownFunctionAttributes()
11830 if (unsigned BuiltinID = FD->getBuiltinID()) { in AddKnownFunctionAttributes()
11831 // Handle printf-formatting attributes. in AddKnownFunctionAttributes()
11835 if (!FD->hasAttr<FormatAttr>()) { in AddKnownFunctionAttributes()
11837 unsigned int NumParams = FD->getNumParams(); in AddKnownFunctionAttributes()
11839 FD->getParamDecl(FormatIdx)->getType()->isObjCObjectPointerType()) in AddKnownFunctionAttributes()
11841 FD->addAttr(FormatAttr::CreateImplicit(Context, in AddKnownFunctionAttributes()
11845 FD->getLocation())); in AddKnownFunctionAttributes()
11850 if (!FD->hasAttr<FormatAttr>()) in AddKnownFunctionAttributes()
11851 FD->addAttr(FormatAttr::CreateImplicit(Context, in AddKnownFunctionAttributes()
11855 FD->getLocation())); in AddKnownFunctionAttributes()
11863 if (!FD->hasAttr<ConstAttr>()) in AddKnownFunctionAttributes()
11864 FD->addAttr(ConstAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
11868 !FD->hasAttr<ReturnsTwiceAttr>()) in AddKnownFunctionAttributes()
11869 FD->addAttr(ReturnsTwiceAttr::CreateImplicit(Context, in AddKnownFunctionAttributes()
11870 FD->getLocation())); in AddKnownFunctionAttributes()
11871 if (Context.BuiltinInfo.isNoThrow(BuiltinID) && !FD->hasAttr<NoThrowAttr>()) in AddKnownFunctionAttributes()
11872 FD->addAttr(NoThrowAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
11873 if (Context.BuiltinInfo.isPure(BuiltinID) && !FD->hasAttr<PureAttr>()) in AddKnownFunctionAttributes()
11874 FD->addAttr(PureAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
11875 if (Context.BuiltinInfo.isConst(BuiltinID) && !FD->hasAttr<ConstAttr>()) in AddKnownFunctionAttributes()
11876 FD->addAttr(ConstAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
11878 !FD->hasAttr<CUDADeviceAttr>() && !FD->hasAttr<CUDAHostAttr>()) { in AddKnownFunctionAttributes()
11884 FD->addAttr(CUDADeviceAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
11886 FD->addAttr(CUDAHostAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
11894 FD->isExternC() && !FD->hasAttr<NoThrowAttr>()) { in AddKnownFunctionAttributes()
11895 const auto *FPT = FD->getType()->getAs<FunctionProtoType>(); in AddKnownFunctionAttributes()
11896 if (!FPT || FPT->getExceptionSpecType() == EST_None) in AddKnownFunctionAttributes()
11897 FD->addAttr(NoThrowAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
11900 IdentifierInfo *Name = FD->getIdentifier(); in AddKnownFunctionAttributes()
11904 FD->getDeclContext()->isTranslationUnit()) || in AddKnownFunctionAttributes()
11905 (isa<LinkageSpecDecl>(FD->getDeclContext()) && in AddKnownFunctionAttributes()
11906 cast<LinkageSpecDecl>(FD->getDeclContext())->getLanguage() == in AddKnownFunctionAttributes()
11908 // Okay: this could be a libc/libm/Objective-C function we know in AddKnownFunctionAttributes()
11913 if (Name->isStr("asprintf") || Name->isStr("vasprintf")) { in AddKnownFunctionAttributes()
11915 // target-specific builtins, perhaps? in AddKnownFunctionAttributes()
11916 if (!FD->hasAttr<FormatAttr>()) in AddKnownFunctionAttributes()
11917 FD->addAttr(FormatAttr::CreateImplicit(Context, in AddKnownFunctionAttributes()
11919 Name->isStr("vasprintf") ? 0 : 3, in AddKnownFunctionAttributes()
11920 FD->getLocation())); in AddKnownFunctionAttributes()
11923 if (Name->isStr("__CFStringMakeConstantString")) { in AddKnownFunctionAttributes()
11925 // but builds that use -fno-constant-cfstrings don't go through that. in AddKnownFunctionAttributes()
11926 if (!FD->hasAttr<FormatArgAttr>()) in AddKnownFunctionAttributes()
11927 FD->addAttr(FormatArgAttr::CreateImplicit(Context, 1, in AddKnownFunctionAttributes()
11928 FD->getLocation())); in AddKnownFunctionAttributes()
11951 NewTD->setInvalidDecl(); in ParseTypedefDecl()
11956 if (CurContext->isFunctionOrMethod()) in ParseTypedefDecl()
11957 Diag(NewTD->getLocation(), diag::err_module_private_local) in ParseTypedefDecl()
11958 << 2 << NewTD->getDeclName() in ParseTypedefDecl()
11962 NewTD->setModulePrivate(); in ParseTypedefDecl()
11967 // enum), the first typedef-name declared by the declaration in ParseTypedefDecl()
11991 SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc(); in CheckEnumUnderlyingType()
11992 QualType T = TI->getType(); in CheckEnumUnderlyingType()
11994 if (T->isDependentType()) in CheckEnumUnderlyingType()
11997 if (const BuiltinType *BT = T->getAs<BuiltinType>()) in CheckEnumUnderlyingType()
11998 if (BT->isInteger()) in CheckEnumUnderlyingType()
12012 if (IsScoped != Prev->isScoped()) { in CheckEnumRedeclaration()
12014 << Prev->isScoped(); in CheckEnumRedeclaration()
12015 Diag(Prev->getLocation(), diag::note_previous_declaration); in CheckEnumRedeclaration()
12019 if (IsFixed && Prev->isFixed()) { in CheckEnumRedeclaration()
12020 if (!EnumUnderlyingTy->isDependentType() && in CheckEnumRedeclaration()
12021 !Prev->getIntegerType()->isDependentType() && in CheckEnumRedeclaration()
12023 Prev->getIntegerType())) { in CheckEnumRedeclaration()
12026 << EnumUnderlyingTy << Prev->getIntegerType(); in CheckEnumRedeclaration()
12027 Diag(Prev->getLocation(), diag::note_previous_declaration) in CheckEnumRedeclaration()
12028 << Prev->getIntegerTypeRange(); in CheckEnumRedeclaration()
12031 } else if (IsFixed && !Prev->isFixed() && EnumUnderlyingIsImplicit) { in CheckEnumRedeclaration()
12033 } else if (!IsFixed && Prev->isFixed() && !Prev->getIntegerTypeSourceInfo()) { in CheckEnumRedeclaration()
12035 } else if (IsFixed != Prev->isFixed()) { in CheckEnumRedeclaration()
12037 << Prev->isFixed(); in CheckEnumRedeclaration()
12038 Diag(Prev->getLocation(), diag::note_previous_declaration); in CheckEnumRedeclaration()
12059 /// \brief Determine if tag kind is a class-key compatible with
12077 // The class-key or enum keyword present in the in isAcceptableTagRedeclaration()
12078 // elaborated-type-specifier shall agree in kind with the in isAcceptableTagRedeclaration()
12079 // declaration to which the name in the elaborated-type-specifier in isAcceptableTagRedeclaration()
12081 // elaborated-type-specifier that declares a class-name or in isAcceptableTagRedeclaration()
12084 // elaborated-type-specifier, the enum keyword shall be used to in isAcceptableTagRedeclaration()
12085 // refer to an enumeration (7.2), the union class-key shall be in isAcceptableTagRedeclaration()
12087 // struct class-key shall be used to refer to a class (clause 9) in isAcceptableTagRedeclaration()
12088 // declared using the class or struct class-key. in isAcceptableTagRedeclaration()
12089 TagTypeKind OldTag = Previous->getTagKind(); in isAcceptableTagRedeclaration()
12098 isTemplate = Record->getDescribedClassTemplate(); in isAcceptableTagRedeclaration()
12101 // In a template instantiation, do not offer fix-its for tag mismatches in isAcceptableTagRedeclaration()
12110 // On definitions, check previous tags and issue a fix-it for each in isAcceptableTagRedeclaration()
12112 if (Previous->getDefinition()) { in isAcceptableTagRedeclaration()
12113 // Don't suggest fix-its for redefinitions. in isAcceptableTagRedeclaration()
12118 for (auto I : Previous->redecls()) { in isAcceptableTagRedeclaration()
12119 if (I->getTagKind() != NewTag) { in isAcceptableTagRedeclaration()
12124 << getRedeclDiagFromTagKind(I->getTagKind()); in isAcceptableTagRedeclaration()
12126 Diag(I->getInnerLocStart(), diag::note_struct_class_suggestion) in isAcceptableTagRedeclaration()
12128 << FixItHint::CreateReplacement(I->getInnerLocStart(), in isAcceptableTagRedeclaration()
12137 // with previous tag type, give a warning, but no fix-it. in isAcceptableTagRedeclaration()
12138 const TagDecl *Redecl = Previous->getDefinition() ? in isAcceptableTagRedeclaration()
12139 Previous->getDefinition() : Previous; in isAcceptableTagRedeclaration()
12140 if (Redecl->getTagKind() == NewTag) { in isAcceptableTagRedeclaration()
12147 Diag(Redecl->getLocation(), diag::note_previous_use); in isAcceptableTagRedeclaration()
12149 // If there is a previous definition, suggest a fix-it. in isAcceptableTagRedeclaration()
12150 if (Previous->getDefinition()) { in isAcceptableTagRedeclaration()
12152 << getRedeclDiagFromTagKind(Redecl->getTagKind()) in isAcceptableTagRedeclaration()
12154 TypeWithKeyword::getTagTypeKindName(Redecl->getTagKind())); in isAcceptableTagRedeclaration()
12177 DeclContext *DC = ND->getDeclContext()->getRedeclContext(); in createFriendTagNNSFixIt()
12178 for (; !DC->isTranslationUnit(); DC = DC->getParent()) { in createFriendTagNNSFixIt()
12182 if (!Namespace || Namespace->isAnonymousNamespace()) in createFriendTagNNSFixIt()
12184 IdentifierInfo *II = Namespace->getIdentifier(); in createFriendTagNNSFixIt()
12196 if (DC->isTranslationUnit()) in createFriendTagNNSFixIt()
12200 OS << II->getName() << "::"; in createFriendTagNNSFixIt()
12207 /// using-declaration).
12210 OldDC = OldDC->getRedeclContext(); in isAcceptableTagRedeclContext()
12211 NewDC = NewDC->getRedeclContext(); in isAcceptableTagRedeclContext()
12213 if (OldDC->Equals(NewDC)) in isAcceptableTagRedeclContext()
12219 (OldDC->Encloses(NewDC) || NewDC->Encloses(OldDC))) in isAcceptableTagRedeclContext()
12229 while (!DC->isFileContext() && !DC->isFunctionOrMethod()) in getTagInjectionContext()
12230 DC = DC->getParent(); in getTagInjectionContext()
12238 while (S->isClassScope() || in getTagInjectionScope()
12240 S->isFunctionPrototypeScope()) || in getTagInjectionScope()
12241 ((S->getFlags() & Scope::DeclScope) == 0) || in getTagInjectionScope()
12242 (S->getEntity() && S->getEntity()->isTransparentContext())) in getTagInjectionScope()
12243 S = S->getParent(); in getTagInjectionScope()
12248 /// former case, Name will be non-null. In the later case, Name will be null.
12252 /// \param IsTypeSpecifier \c true if this is a type-specifier (or
12253 /// trailing-type-specifier) other than one in an alias-declaration.
12255 /// \param SkipBody If non-null, will be set to indicate if the caller should
12284 // for non-C++ cases. in ActOnTag()
12296 if (TemplateParams->size() > 0) { in ActOnTag()
12309 TemplateParameterLists.size()-1, in ActOnTag()
12315 Diag(TemplateParams->getTemplateLoc(), diag::err_template_tag_noparams) in ActOnTag()
12334 // C++0x 7.2p2: The type-specifier-seq of an enum-base shall name an in ActOnTag()
12335 // integral type; any cv-qualification is ignored. in ActOnTag()
12344 if (DiagnoseUnexpandedParameterPack(TI->getTypeLoc().getBeginLoc(), TI, in ActOnTag()
12367 // We have a nested-name tag ('struct foo::bar'). in ActOnTag()
12396 // Look-up name inside 'foo::'. in ActOnTag()
12404 // nested-name-specifier refers to the current instantiation, in ActOnTag()
12407 // this as a dependent elaborated-type-specifier. in ActOnTag()
12408 // But this only makes any sense for reference-like lookups. in ActOnTag()
12426 // -- every member of class T that is itself a type in ActOnTag()
12445 if (!ND->getDeclContext()->getRedeclContext()->Equals( in ActOnTag()
12446 SearchDC->getRedeclContext())) in ActOnTag()
12454 // a template-id and the declaration is a function or an in ActOnTag()
12455 // elaborated-type-specifier, the lookup to determine whether in ActOnTag()
12466 DeclContext *EnclosingNS = SearchDC->getEnclosingNamespaceContext(); in ActOnTag()
12471 DeclContext *DC = ND->getDeclContext()->getRedeclContext(); in ActOnTag()
12472 if (DC->isFileContext() && in ActOnTag()
12473 !EnclosingNS->Encloses(ND->getDeclContext())) { in ActOnTag()
12501 SearchDC = SearchDC->getParent(); in ActOnTag()
12506 Previous.getFoundDecl()->isTemplateParameter()) { in ActOnTag()
12514 DC->Equals(getStdNamespace()) && Name->isStr("bad_alloc")) { in ActOnTag()
12537 // -- for an elaborated-type-specifier of the form in ActOnTag()
12539 // class-key identifier in ActOnTag()
12541 // if the elaborated-type-specifier is used in the in ActOnTag()
12542 // decl-specifier-seq or parameter-declaration-clause of a in ActOnTag()
12544 // declared as a class-name in the namespace that contains in ActOnTag()
12547 // non-class, non-function-prototype scope that contains the in ActOnTag()
12571 // If a friend declaration in a non-local class first declares a in ActOnTag()
12574 SearchDC = SearchDC->getEnclosingNamespaceContext(); in ActOnTag()
12581 // type declared by an elaborated-type-specifier. In C that is not correct in ActOnTag()
12593 if (Previous.empty() && SkipBody && SkipBody->Previous) in ActOnTag()
12594 Previous.addDecl(SkipBody->Previous); in ActOnTag()
12605 // This is also okay for elaborated-type-specifiers, which is in ActOnTag()
12607 // okay according to the likely resolution of an open issue; in ActOnTag()
12608 // see http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#407 in ActOnTag()
12611 if (const TagType *TT = TD->getUnderlyingType()->getAs<TagType>()) { in ActOnTag()
12612 TagDecl *Tag = TT->getDecl(); in ActOnTag()
12613 if (Tag->getDeclName() == Name && in ActOnTag()
12614 Tag->getDeclContext()->getRedeclContext() in ActOnTag()
12615 ->Equals(TD->getDeclContext()->getRedeclContext())) { in ActOnTag()
12633 *this, OldTag->getDeclContext(), SearchDC))) { in ActOnTag()
12635 Diag(Shadow->getTargetDecl()->getLocation(), in ActOnTag()
12637 Diag(Shadow->getUsingDecl()->getLocation(), diag::note_using_decl) in ActOnTag()
12658 = (PrevTagDecl->getTagKind() != TTK_Enum && in ActOnTag()
12664 PrevTagDecl->getKindName()); in ActOnTag()
12667 Diag(PrevTagDecl->getLocation(), diag::note_previous_use); in ActOnTag()
12670 Kind = PrevTagDecl->getTagKind(); in ActOnTag()
12679 if (Kind == TTK_Enum && PrevTagDecl->getTagKind() == TTK_Enum) { in ActOnTag()
12682 // If this is an elaborated-type-specifier for a scoped enumeration, in ActOnTag()
12687 << PrevEnum->isScoped() in ActOnTag()
12694 EnumUnderlyingTy = TI->getType().getUnqualifiedType(); in ActOnTag()
12708 // A member shall not be declared twice in the member-specification, in ActOnTag()
12711 if (TUK == TUK_Declaration && PrevDecl->isCXXClassMember() && in ActOnTag()
12712 S->isDeclScope(PrevDecl)) { in ActOnTag()
12714 Diag(PrevTagDecl->getLocation(), diag::note_previous_declaration); in ActOnTag()
12725 (PrevTagDecl->getFriendObjectKind() == in ActOnTag()
12728 PrevDecl->getLocation()) != in ActOnTag()
12738 if (!getTagInjectionContext(CurContext)->getRedeclContext() in ActOnTag()
12739 ->Equals(PrevDecl->getDeclContext()->getRedeclContext())) in ActOnTag()
12751 if (NamedDecl *Def = PrevTagDecl->getDefinition()) { in ActOnTag()
12759 RD->getTemplateSpecializationKind() != in ActOnTag()
12763 ED->getTemplateSpecializationKind() != in ActOnTag()
12775 SkipBody->ShouldSkip = true; in ActOnTag()
12780 // visible elsewhere, so merely issue a warning. in ActOnTag()
12781 if (!getLangOpts().CPlusPlus && S->containedInPrototypeScope()) in ActOnTag()
12785 Diag(Def->getLocation(), diag::note_previous_definition); in ActOnTag()
12796 auto *TD = Context.getTagDeclType(PrevTagDecl)->getAsTagDecl(); in ActOnTag()
12797 if (TD->isBeingDefined()) { in ActOnTag()
12799 Diag(PrevTagDecl->getLocation(), in ActOnTag()
12815 SearchDC = PrevTagDecl->getDeclContext(); in ActOnTag()
12830 // is non-NULL, it's a definition of the tag declared by in ActOnTag()
12837 // Use a better diagnostic if an elaborated-type-specifier in ActOnTag()
12839 // (non-redeclaration) lookup. in ActOnTag()
12847 Diag(PrevDecl->getLocation(), diag::note_declared_at); in ActOnTag()
12862 Diag(PrevDecl->getLocation(), diag::note_previous_decl) << PrevDecl; in ActOnTag()
12871 << Name << Kind << TND->getUnderlyingType(); in ActOnTag()
12872 Diag(PrevDecl->getLocation(), diag::note_previous_decl) << PrevDecl; in ActOnTag()
12878 // issue an error and recover by making this tag be anonymous. in ActOnTag()
12880 Diag(PrevDecl->getLocation(), diag::note_previous_definition); in ActOnTag()
12918 cast<EnumDecl>(New)->isFixed()) { in ActOnTag()
12919 // C++0x: 7.2p2: opaque-enum-declaration. in ActOnTag()
12922 else if (PrevDecl && (Def = cast<EnumDecl>(PrevDecl)->getDefinition())) { in ActOnTag()
12925 Diag(Def->getLocation(), diag::note_previous_definition); in ActOnTag()
12934 // If this is a forward-declared reference to an enumeration, make a in ActOnTag()
12945 ED->setIntegerTypeSourceInfo(TI); in ActOnTag()
12947 ED->setIntegerType(QualType(EnumUnderlying.get<const Type*>(), 0)); in ActOnTag()
12948 ED->setPromotionType(ED->getIntegerType()); in ActOnTag()
12960 if (isStdBadAlloc && (!StdBadAlloc || getStdBadAlloc()->isImplicit())) in ActOnTag()
12968 // A type-specifier-seq shall not define a class or enumeration [...]. in ActOnTag()
12970 Diag(New->getLocation(), diag::err_type_defined_in_type_specifier) in ActOnTag()
12979 // nested-name-specifier against the current context. We don't do this in ActOnTag()
12988 New->setQualifierInfo(SS.getWithLocInContext(Context)); in ActOnTag()
12990 New->setTemplateParameterListsInfo(Context, TemplateParameterLists); in ActOnTag()
13015 Diag(New->getLocation(), diag::err_module_private_specialization) in ActOnTag()
13021 else if (!SearchDC->isFunctionOrMethod()) in ActOnTag()
13022 New->setModulePrivate(); in ActOnTag()
13034 getNonFieldDeclScope(S)->isFunctionPrototypeScope()) { in ActOnTag()
13050 New->setInvalidDecl(); in ActOnTag()
13057 New->setLexicalDeclContext(CurContext); in ActOnTag()
13064 New->setObjectOfFriendDecl(getLangOpts().MSVCCompat); in ActOnTag()
13067 if (!Invalid && SearchDC->isRecord()) in ActOnTag()
13071 New->startDefinition(); in ActOnTag()
13078 New->setAccess(PrevDecl->getAccess()); in ActOnTag()
13080 DeclContext *DC = New->getDeclContext()->getRedeclContext(); in ActOnTag()
13081 DC->makeDeclVisibleInContext(New); in ActOnTag()
13089 SearchDC->makeDeclVisibleInContext(New); in ActOnTag()
13091 CurContext->addDecl(New); in ActOnTag()
13095 if (IdentifierInfo *II = New->getIdentifier()) in ActOnTag()
13096 if (!New->isInvalidDecl() && in ActOnTag()
13097 New->getDeclContext()->getRedeclContext()->isTranslationUnit() && in ActOnTag()
13098 II->isStr("FILE")) in ActOnTag()
13130 "ActOnObjCContainerStartDefinition - Not ObjCContainerDecl"); in ActOnObjCContainerStartDefinition()
13145 FieldCollector->StartClass(); in ActOnStartCXXMemberDeclarations()
13147 if (!Record->getIdentifier()) in ActOnStartCXXMemberDeclarations()
13151 Record->addAttr(new (Context) in ActOnStartCXXMemberDeclarations()
13155 // [...] The class-name is also inserted into the scope of the in ActOnStartCXXMemberDeclarations()
13156 // class itself; this is known as the injected-class-name. For in ActOnStartCXXMemberDeclarations()
13157 // purposes of access checking, the injected-class-name is treated in ActOnStartCXXMemberDeclarations()
13160 = CXXRecordDecl::Create(Context, Record->getTagKind(), CurContext, in ActOnStartCXXMemberDeclarations()
13161 Record->getLocStart(), Record->getLocation(), in ActOnStartCXXMemberDeclarations()
13162 Record->getIdentifier(), in ActOnStartCXXMemberDeclarations()
13166 InjectedClassName->setImplicit(); in ActOnStartCXXMemberDeclarations()
13167 InjectedClassName->setAccess(AS_public); in ActOnStartCXXMemberDeclarations()
13168 if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) in ActOnStartCXXMemberDeclarations()
13169 InjectedClassName->setDescribedClassTemplate(Template); in ActOnStartCXXMemberDeclarations()
13171 assert(InjectedClassName->isInjectedClassName() && in ActOnStartCXXMemberDeclarations()
13172 "Broken injected-class-name"); in ActOnStartCXXMemberDeclarations()
13179 Tag->setRBraceLoc(RBraceLoc); in ActOnTagFinishDefinition()
13182 if (Tag->isBeingDefined()) { in ActOnTagFinishDefinition()
13183 assert(Tag->isInvalidDecl() && "We should already have completed it"); in ActOnTagFinishDefinition()
13185 RD->completeDefinition(); in ActOnTagFinishDefinition()
13189 FieldCollector->FinishClass(); in ActOnTagFinishDefinition()
13194 if (getCurLexicalContext()->isObjCContainer() && in ActOnTagFinishDefinition()
13195 Tag->getDeclContext()->isFileContext()) in ActOnTagFinishDefinition()
13196 Tag->setTopLevelDeclInObjCContainer(); in ActOnTagFinishDefinition()
13199 if (!Tag->isInvalidDecl()) in ActOnTagFinishDefinition()
13222 Tag->setInvalidDecl(); in ActOnTagDefinitionError()
13225 if (Tag->isBeingDefined()) { in ActOnTagDefinitionError()
13227 RD->completeDefinition(); in ActOnTagDefinitionError()
13246 // C99 6.7.2.1p4 - verify the field type. in VerifyBitField()
13247 // C++ 9.6p3: A bit-field shall have integral or enumeration type. in VerifyBitField()
13248 if (!FieldTy->isDependentType() && !FieldTy->isIntegralOrEnumerationType()) { in VerifyBitField()
13254 << FieldName << FieldTy << BitWidth->getSourceRange(); in VerifyBitField()
13256 << FieldTy << BitWidth->getSourceRange(); in VerifyBitField()
13261 // If the bit-width is type- or value-dependent, don't try to check in VerifyBitField()
13263 if (BitWidth->isValueDependent() || BitWidth->isTypeDependent()) in VerifyBitField()
13275 // Zero-width bitfield is ok for anonymous field. in VerifyBitField()
13287 if (!FieldTy->isDependentType()) { in VerifyBitField()
13292 // Over-wide bitfields are an error in C or when using the MSVC bitfield in VerifyBitField()
13315 if (BitfieldIsOverwide && !FieldTy->isBooleanType()) { in VerifyBitField()
13329 /// ActOnField - Each field of a C struct/union is passed into this in order
13339 /// HandleField - Analyze a field of a C struct or a C++ data member.
13351 QualType T = TInfo->getType(); in HandleField()
13369 // OpenCL v1.2 s6.9b,r & OpenCL v2.0 s6.12.5 - The following types cannot be in HandleField()
13371 if (LangOpts.OpenCL && (T->isEventT() || T->isImageType() || in HandleField()
13372 T->isSamplerT() || T->isBlockPointerType())) { in HandleField()
13408 if (PrevDecl && PrevDecl->isTemplateParameter()) { in HandleField()
13425 if (NewFD->isInvalidDecl()) in HandleField()
13426 Record->setInvalidDecl(); in HandleField()
13429 NewFD->setModulePrivate(); in HandleField()
13431 if (NewFD->isInvalidDecl() && PrevDecl) { in HandleField()
13437 Record->addDecl(NewFD); in HandleField()
13442 /// \brief Build a new FieldDecl and check its well-formedness.
13462 if (D) InvalidDecl = D->isInvalidType(); in CheckFieldDecl()
13472 if (!EltTy->isDependentType()) { in CheckFieldDecl()
13475 Record->setInvalidDecl(); in CheckFieldDecl()
13479 EltTy->isIncompleteType(&Def); in CheckFieldDecl()
13480 if (Def && Def->isInvalidDecl()) { in CheckFieldDecl()
13481 Record->setInvalidDecl(); in CheckFieldDecl()
13495 if (!InvalidDecl && T->isVariablyModifiedType()) { in CheckFieldDecl()
13506 T = FixedTInfo->getType(); in CheckFieldDecl()
13528 // If this is declared as a bit-field, check the bit-field. in CheckFieldDecl()
13530 BitWidth = VerifyBitField(Loc, II, T, Record->isMsStruct(Context), BitWidth, in CheckFieldDecl()
13542 if (T->isReferenceType()) in CheckFieldDecl()
13550 if (D && D->getDeclSpec().getStorageClassSpecLoc().isValid()) in CheckFieldDecl()
13551 ErrLoc = D->getDeclSpec().getStorageClassSpecLoc(); in CheckFieldDecl()
13562 // brace-or-equal-initializer. in CheckFieldDecl()
13569 NewFD->setInvalidDecl(); in CheckFieldDecl()
13573 Diag(PrevDecl->getLocation(), diag::note_previous_declaration); in CheckFieldDecl()
13574 NewFD->setInvalidDecl(); in CheckFieldDecl()
13578 if (Record->isUnion()) { in CheckFieldDecl()
13579 if (const RecordType *RT = EltTy->getAs<RecordType>()) { in CheckFieldDecl()
13580 CXXRecordDecl* RDecl = cast<CXXRecordDecl>(RT->getDecl()); in CheckFieldDecl()
13581 if (RDecl->getDefinition()) { in CheckFieldDecl()
13582 // C++ [class.union]p1: An object of a class with a non-trivial in CheckFieldDecl()
13583 // constructor, a non-trivial copy constructor, a non-trivial in CheckFieldDecl()
13584 // destructor, or a non-trivial copy assignment operator in CheckFieldDecl()
13588 NewFD->setInvalidDecl(); in CheckFieldDecl()
13593 // the program is ill-formed, except when compiling with MSVC extensions in CheckFieldDecl()
13595 if (EltTy->isReferenceType()) { in CheckFieldDecl()
13596 Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ? in CheckFieldDecl()
13599 << NewFD->getDeclName() << EltTy; in CheckFieldDecl()
13601 NewFD->setInvalidDecl(); in CheckFieldDecl()
13612 if (NewFD->hasAttrs()) in CheckFieldDecl()
13616 // In auto-retain/release, infer strong retension for fields of in CheckFieldDecl()
13619 NewFD->setInvalidDecl(); in CheckFieldDecl()
13624 NewFD->setAccess(AS); in CheckFieldDecl()
13632 if (FD->isInvalidDecl() || FD->getType()->isDependentType()) in CheckNontrivialField()
13635 QualType EltTy = Context.getBaseElementType(FD->getType()); in CheckNontrivialField()
13636 if (const RecordType *RT = EltTy->getAs<RecordType>()) { in CheckNontrivialField()
13637 CXXRecordDecl *RDecl = cast<CXXRecordDecl>(RT->getDecl()); in CheckNontrivialField()
13638 if (RDecl->getDefinition()) { in CheckNontrivialField()
13644 // We're required to check for any non-trivial constructors. Since the in CheckNontrivialField()
13646 // user-declared constructors, we just need to check that there is a in CheckNontrivialField()
13649 if (RDecl->hasNonTrivialCopyConstructor()) in CheckNontrivialField()
13651 else if (!RDecl->hasTrivialDefaultConstructor()) in CheckNontrivialField()
13653 else if (RDecl->hasNonTrivialCopyAssignment()) in CheckNontrivialField()
13655 else if (RDecl->hasNonTrivialDestructor()) in CheckNontrivialField()
13660 getLangOpts().ObjCAutoRefCount && RDecl->hasObjectMember()) { in CheckNontrivialField()
13661 // Objective-C++ ARC: it is an error to have a non-trivial field of in CheckNontrivialField()
13662 // a union. However, system headers in Objective-C programs in CheckNontrivialField()
13663 // occasionally have Objective-C lifetime objects within unions, in CheckNontrivialField()
13666 SourceLocation Loc = FD->getLocation(); in CheckNontrivialField()
13668 if (!FD->hasAttr<UnavailableAttr>()) in CheckNontrivialField()
13669 FD->addAttr(UnavailableAttr::CreateImplicit(Context, "", in CheckNontrivialField()
13675 Diag(FD->getLocation(), getLangOpts().CPlusPlus11 ? in CheckNontrivialField()
13678 << FD->getParent()->isUnion() << FD->getDeclName() << member; in CheckNontrivialField()
13688 /// TranslateIvarVisibility - Translate visibility from a token ID to an
13701 /// ActOnIvar - Each ivar field of an objective-c class is passed into this
13717 QualType T = TInfo->getType(); in ActOnIvar()
13730 if (T->isReferenceType()) { in ActOnIvar()
13736 else if (T->isVariablyModifiedType()) { in ActOnIvar()
13747 if (!EnclosingDecl || EnclosingDecl->isInvalidDecl()) in ActOnIvar()
13754 EnclosingContext = IMPDecl->getClassInterface(); in ActOnIvar()
13762 if (LangOpts.ObjCRuntime.isFragile() || !CDecl->IsClassExtension()) { in ActOnIvar()
13763 Diag(Loc, diag::err_misplaced_ivar) << CDecl->IsClassExtension(); in ActOnIvar()
13781 Diag(PrevDecl->getLocation(), diag::note_previous_declaration); in ActOnIvar()
13782 NewID->setInvalidDecl(); in ActOnIvar()
13790 NewID->setInvalidDecl(); in ActOnIvar()
13794 NewID->setInvalidDecl(); in ActOnIvar()
13797 NewID->setModulePrivate(); in ActOnIvar()
13802 S->AddDecl(NewID); in ActOnIvar()
13807 !NewID->isInvalidDecl() && isa<ObjCInterfaceDecl>(EnclosingDecl)) in ActOnIvar()
13813 /// ActOnLastBitfield - This routine handles synthesized bitfields rules for
13822 Decl *ivarDecl = AllIvarDecls[AllIvarDecls.size()-1]; in ActOnLastBitfield()
13825 if (!Ivar->isBitField() || Ivar->getBitWidthValue(Context) == 0) in ActOnLastBitfield()
13830 if (!CD->IsClassExtension()) in ActOnLastBitfield()
13856 // If this is an Objective-C @implementation or category and we have in ActOnFields()
13861 switch (DC->getKind()) { in ActOnFields()
13864 Context.ResetObjCLayout(cast<ObjCCategoryDecl>(DC)->getClassInterface()); in ActOnFields()
13868 ResetObjCLayout(cast<ObjCImplementationDecl>(DC)->getClassInterface()); in ActOnFields()
13879 for (const auto *I : Record->decls()) { in ActOnFields()
13881 if (IFD->getDeclName()) in ActOnFields()
13895 const Type *FDTy = FD->getType().getTypePtr(); in ActOnFields()
13897 if (!FD->isAnonymousStructOrUnion()) { in ActOnFields()
13904 if (FD->isInvalidDecl()) { in ActOnFields()
13905 EnclosingDecl->setInvalidDecl(); in ActOnFields()
13919 if (FDTy->isFunctionType()) { in ActOnFields()
13921 Diag(FD->getLocation(), diag::err_field_declared_as_function) in ActOnFields()
13922 << FD->getDeclName(); in ActOnFields()
13923 FD->setInvalidDecl(); in ActOnFields()
13924 EnclosingDecl->setInvalidDecl(); in ActOnFields()
13926 } else if (FDTy->isIncompleteArrayType() && Record && in ActOnFields()
13927 ((i + 1 == Fields.end() && !Record->isUnion()) || in ActOnFields()
13930 (i + 1 == Fields.end() || Record->isUnion())))) { in ActOnFields()
13936 if (Record->isUnion()) in ActOnFields()
13950 Diag(FD->getLocation(), DiagID) << FD->getDeclName() in ActOnFields()
13951 << Record->getTagKind(); in ActOnFields()
13958 if (RD->getNumVBases() != 0) in ActOnFields()
13959 Diag(FD->getLocation(), diag::err_flexible_array_virtual_base) in ActOnFields()
13960 << FD->getDeclName() << Record->getTagKind(); in ActOnFields()
13962 Diag(FD->getLocation(), diag::ext_c99_flexible_array_member) in ActOnFields()
13963 << FD->getDeclName() << Record->getTagKind(); in ActOnFields()
13965 // If the element type has a non-trivial destructor, we would not in ActOnFields()
13970 QualType BaseElem = Context.getBaseElementType(FD->getType()); in ActOnFields()
13971 if (!BaseElem->isDependentType() && BaseElem.isDestructedType()) { in ActOnFields()
13972 Diag(FD->getLocation(), diag::err_flexible_array_has_nontrivial_dtor) in ActOnFields()
13973 << FD->getDeclName() << FD->getType(); in ActOnFields()
13974 FD->setInvalidDecl(); in ActOnFields()
13975 EnclosingDecl->setInvalidDecl(); in ActOnFields()
13979 Record->setHasFlexibleArrayMember(true); in ActOnFields()
13980 } else if (!FDTy->isDependentType() && in ActOnFields()
13981 RequireCompleteType(FD->getLocation(), FD->getType(), in ActOnFields()
13984 FD->setInvalidDecl(); in ActOnFields()
13985 EnclosingDecl->setInvalidDecl(); in ActOnFields()
13987 } else if (const RecordType *FDTTy = FDTy->getAs<RecordType>()) { in ActOnFields()
13988 if (Record && FDTTy->getDecl()->hasFlexibleArrayMember()) { in ActOnFields()
13991 Record->setHasFlexibleArrayMember(true); in ActOnFields()
13992 if (!Record->isUnion()) { in ActOnFields()
13997 Diag(FD->getLocation(), diag::ext_variable_sized_type_in_struct) in ActOnFields()
13998 << FD->getDeclName() << FD->getType(); in ActOnFields()
14002 Diag(FD->getLocation(), diag::ext_flexible_array_in_struct) in ActOnFields()
14003 << FD->getDeclName(); in ActOnFields()
14008 RequireNonAbstractType(FD->getLocation(), FD->getType(), in ActOnFields()
14012 FD->setInvalidDecl(); in ActOnFields()
14014 if (Record && FDTTy->getDecl()->hasObjectMember()) in ActOnFields()
14015 Record->setHasObjectMember(true); in ActOnFields()
14016 if (Record && FDTTy->getDecl()->hasVolatileMember()) in ActOnFields()
14017 Record->setHasVolatileMember(true); in ActOnFields()
14018 } else if (FDTy->isObjCObjectType()) { in ActOnFields()
14019 /// A field cannot be an Objective-c object in ActOnFields()
14020 Diag(FD->getLocation(), diag::err_statically_allocated_object) in ActOnFields()
14021 << FixItHint::CreateInsertion(FD->getLocation(), "*"); in ActOnFields()
14022 QualType T = Context.getObjCObjectPointerType(FD->getType()); in ActOnFields()
14023 FD->setType(T); in ActOnFields()
14025 (!getLangOpts().CPlusPlus || Record->isUnion())) { in ActOnFields()
14031 QualType T = FD->getType(); in ActOnFields()
14034 SourceLocation loc = FD->getLocation(); in ActOnFields()
14036 if (!FD->hasAttr<UnavailableAttr>()) { in ActOnFields()
14037 FD->addAttr(UnavailableAttr::CreateImplicit(Context, "", in ActOnFields()
14041 Diag(FD->getLocation(), diag::err_arc_objc_object_in_tag) in ActOnFields()
14042 << T->isBlockPointerType() << Record->getTagKind(); in ActOnFields()
14048 Record && !Record->hasObjectMember()) { in ActOnFields()
14049 if (FD->getType()->isObjCObjectPointerType() || in ActOnFields()
14050 FD->getType().isObjCGCStrong()) in ActOnFields()
14051 Record->setHasObjectMember(true); in ActOnFields()
14052 else if (Context.getAsArrayType(FD->getType())) { in ActOnFields()
14053 QualType BaseType = Context.getBaseElementType(FD->getType()); in ActOnFields()
14054 if (BaseType->isRecordType() && in ActOnFields()
14055 BaseType->getAs<RecordType>()->getDecl()->hasObjectMember()) in ActOnFields()
14056 Record->setHasObjectMember(true); in ActOnFields()
14057 else if (BaseType->isObjCObjectPointerType() || in ActOnFields()
14059 Record->setHasObjectMember(true); in ActOnFields()
14062 if (Record && FD->getType().isVolatileQualified()) in ActOnFields()
14063 Record->setHasVolatileMember(true); in ActOnFields()
14065 if (FD->getIdentifier()) in ActOnFields()
14073 if (!CXXRecord->isInvalidDecl()) { in ActOnFields()
14074 // Set access bits correctly on the directly-declared conversions. in ActOnFields()
14076 I = CXXRecord->conversion_begin(), in ActOnFields()
14077 E = CXXRecord->conversion_end(); I != E; ++I) in ActOnFields()
14078 I.setAccess((*I)->getAccess()); in ActOnFields()
14081 if (!CXXRecord->isDependentType()) { in ActOnFields()
14082 if (CXXRecord->hasUserDeclaredDestructor()) { in ActOnFields()
14083 // Adjust user-defined destructor exception spec. in ActOnFields()
14086 CXXRecord->getDestructor()); in ActOnFields()
14089 if (!CXXRecord->isInvalidDecl()) { in ActOnFields()
14090 // Add any implicitly-declared members to this class. in ActOnFields()
14096 if (CXXRecord->getNumVBases()) { in ActOnFields()
14098 CXXRecord->getFinalOverriders(FinalOverriders); in ActOnFields()
14103 for (OverridingMethods::iterator SO = M->second.begin(), in ActOnFields()
14104 SOEnd = M->second.end(); in ActOnFields()
14106 assert(SO->second.size() > 0 && in ActOnFields()
14108 if (SO->second.size() == 1) in ActOnFields()
14114 // program is ill-formed. in ActOnFields()
14115 Diag(Record->getLocation(), diag::err_multiple_final_overriders) in ActOnFields()
14116 << (const NamedDecl *)M->first << Record; in ActOnFields()
14117 Diag(M->first->getLocation(), in ActOnFields()
14120 OM = SO->second.begin(), in ActOnFields()
14121 OMEnd = SO->second.end(); in ActOnFields()
14123 Diag(OM->Method->getLocation(), diag::note_final_overrider) in ActOnFields()
14124 << (const NamedDecl *)M->first << OM->Method->getParent(); in ActOnFields()
14126 Record->setInvalidDecl(); in ActOnFields()
14129 CXXRecord->completeDefinition(&FinalOverriders); in ActOnFields()
14137 Record->completeDefinition(); in ActOnFields()
14139 if (Record->hasAttrs()) { in ActOnFields()
14142 if (const MSInheritanceAttr *IA = Record->getAttr<MSInheritanceAttr>()) in ActOnFields()
14144 IA->getRange(), IA->getBestCase(), in ActOnFields()
14145 IA->getSemanticSpelling()); in ActOnFields()
14158 CXXRecord->getLexicalDeclContext()->isExternCContext() && in ActOnFields()
14159 !CXXRecord->isDependentType() && in ActOnFields()
14160 CXXRecord->isCLike(); in ActOnFields()
14166 for (RecordDecl::field_iterator I = Record->field_begin(), in ActOnFields()
14167 E = Record->field_end(); in ActOnFields()
14170 if (I->isUnnamedBitfield()) { in ActOnFields()
14171 if (I->getBitWidthValue(Context) > 0) in ActOnFields()
14175 QualType FieldType = I->getType(); in ActOnFields()
14176 if (FieldType->isIncompleteType() || in ActOnFields()
14189 << IsEmpty << Record->isUnion() << (NonBitFields > 1); in ActOnFields()
14197 << Record->isUnion(); in ActOnFields()
14204 ID->setEndOfDefinitionLoc(RBrac); in ActOnFields()
14207 ClsFields[i]->setLexicalDeclContext(ID); in ActOnFields()
14208 ID->addDecl(ClsFields[i]); in ActOnFields()
14212 if (ID->getSuperClass()) in ActOnFields()
14213 DiagnoseDuplicateIvars(ID, ID->getSuperClass()); in ActOnFields()
14216 assert(IMPDecl && "ActOnFields - missing ObjCImplementationDecl"); in ActOnFields()
14220 ClsFields[I]->setLexicalDeclContext(IMPDecl); in ActOnFields()
14222 IMPDecl->setIvarLBraceLoc(LBrac); in ActOnFields()
14223 IMPDecl->setIvarRBraceLoc(RBrac); in ActOnFields()
14229 // CDecl->setLocEnd(RBrac); in ActOnFields()
14232 ObjCInterfaceDecl *IDecl = CDecl->getClassInterface(); in ActOnFields()
14236 IDecl->getIvarDecl(ClsFields[i]->getIdentifier())) { in ActOnFields()
14237 Diag(ClsFields[i]->getLocation(), in ActOnFields()
14239 Diag(ClsIvar->getLocation(), diag::note_previous_definition); in ActOnFields()
14242 for (const auto *Ext : IDecl->known_extensions()) { in ActOnFields()
14244 = Ext->getIvarDecl(ClsFields[i]->getIdentifier())) { in ActOnFields()
14245 Diag(ClsFields[i]->getLocation(), in ActOnFields()
14247 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition); in ActOnFields()
14252 ClsFields[i]->setLexicalDeclContext(CDecl); in ActOnFields()
14253 CDecl->addDecl(ClsFields[i]); in ActOnFields()
14255 CDecl->setIvarLBraceLoc(LBrac); in ActOnFields()
14256 CDecl->setIvarRBraceLoc(RBrac); in ActOnFields()
14269 assert(T->isIntegralType(Context) && "Integral type required!"); in isRepresentableIntegerValue()
14273 if (T->isSignedIntegerOrEnumerationType()) in isRepresentableIntegerValue()
14274 --BitWidth; in isRepresentableIntegerValue()
14285 assert(T->isIntegralType(Context) && "Integral type required!"); in getNextLargerIntegralType()
14296 QualType *Types = T->isSignedIntegerOrEnumerationType()? SignedIntegralTypes in getNextLargerIntegralType()
14321 if (Enum->isDependentType() || Val->isTypeDependent()) in CheckEnumConstant()
14325 if (getLangOpts().CPlusPlus11 && Enum->isFixed() && in CheckEnumConstant()
14328 // constant-expression in the enumerator-definition shall be a converted in CheckEnumConstant()
14330 EltTy = Enum->getIntegerType(); in CheckEnumConstant()
14338 } else if (!Val->isValueDependent() && in CheckEnumConstant()
14343 if (Enum->isFixed()) { in CheckEnumConstant()
14344 EltTy = Enum->getIntegerType(); in CheckEnumConstant()
14346 // In Obj-C and Microsoft mode, require the enumeration value to be in CheckEnumConstant()
14348 // we perform a non-narrowing conversion as part of converted constant in CheckEnumConstant()
14358 EltTy->isBooleanType() ? in CheckEnumConstant()
14365 // - If an initializer is specified for an enumerator, the in CheckEnumConstant()
14367 EltTy = Val->getType(); in CheckEnumConstant()
14377 << EnumVal.toString(10) << Val->getSourceRange() in CheckEnumConstant()
14379 else if (!Context.hasSameType(Val->getType(), Context.IntTy)) { in CheckEnumConstant()
14383 EltTy = Val->getType(); in CheckEnumConstant()
14390 if (Enum->isDependentType()) in CheckEnumConstant()
14396 // - If no initializer is specified for the first enumerator, the in CheckEnumConstant()
14401 if (Enum->isFixed()) { in CheckEnumConstant()
14402 EltTy = Enum->getIntegerType(); in CheckEnumConstant()
14409 EnumVal = LastEnumConst->getInitVal(); in CheckEnumConstant()
14411 EltTy = LastEnumConst->getType(); in CheckEnumConstant()
14414 if (EnumVal < LastEnumConst->getInitVal()) { in CheckEnumConstant()
14419 // - Otherwise the type of the initializing value is the same as in CheckEnumConstant()
14424 // exists, the program is ill-formed. in CheckEnumConstant()
14426 if (T.isNull() || Enum->isFixed()) { in CheckEnumConstant()
14429 EnumVal = LastEnumConst->getInitVal(); in CheckEnumConstant()
14432 if (Enum->isFixed()) in CheckEnumConstant()
14433 // When the underlying type is fixed, this is ill-formed. in CheckEnumConstant()
14447 EnumVal = LastEnumConst->getInitVal(); in CheckEnumConstant()
14448 EnumVal.setIsSigned(EltTy->isSignedIntegerOrEnumerationType()); in CheckEnumConstant()
14468 if (!EltTy->isDependentType()) { in CheckEnumConstant()
14472 EnumVal.setIsSigned(EltTy->isSignedIntegerOrEnumerationType()); in CheckEnumConstant()
14494 EnumDecl *PrevED = cast<EnumDecl>(PrevECD->getDeclContext()); in shouldSkipAnonEnumBody()
14496 if (!PrevED->getDeclName() && !hasVisibleDefinition(PrevED, &Hidden)) { in shouldSkipAnonEnumBody()
14521 if (PrevDecl && PrevDecl->isTemplateParameter()) { in ActOnEnumConstant()
14531 // - every enumerator of every member of class T that is an unscoped in ActOnEnumConstant()
14533 if (!TheEnumDecl->isScoped()) in ActOnEnumConstant()
14534 DiagnoseClassNameShadow(TheEnumDecl->getDeclContext(), in ActOnEnumConstant()
14553 Diag(PrevDecl->getLocation(), diag::note_previous_definition); in ActOnEnumConstant()
14562 New->setAccess(TheEnumDecl->getAccess()); in ActOnEnumConstant()
14574 // Element2 = Element1 - 1
14577 Expr *InitExpr = ECD->getInitExpr(); in ValidDuplicateEnum()
14580 InitExpr = InitExpr->IgnoreImpCasts(); in ValidDuplicateEnum()
14583 if (!BO->isAdditiveOp()) in ValidDuplicateEnum()
14585 IntegerLiteral *IL = dyn_cast<IntegerLiteral>(BO->getRHS()); in ValidDuplicateEnum()
14588 if (IL->getValue() != 1) in ValidDuplicateEnum()
14591 InitExpr = BO->getLHS(); in ValidDuplicateEnum()
14599 EnumConstantDecl *EnumConstant = dyn_cast<EnumConstantDecl>(DRE->getDecl()); in ValidDuplicateEnum()
14603 if (cast<EnumDecl>(TagDecl::castFromDeclContext(ECD->getDeclContext())) != in ValidDuplicateEnum()
14641 if (S.Diags.isIgnored(diag::warn_duplicate_enum_values, Enum->getLocation())) in CheckForDuplicateEnumValues()
14644 if (!Enum->getIdentifier()) in CheckForDuplicateEnumValues()
14648 if (Enum->getNumPositiveBits() > 63 || Enum->getNumNegativeBits() > 64) in CheckForDuplicateEnumValues()
14667 // this constant. Skip this enum since it may be ill-formed. in CheckForDuplicateEnumValues()
14672 if (ECD->getInitExpr()) in CheckForDuplicateEnumValues()
14675 DupKey Key = GetDupKey(ECD->getInitVal()); in CheckForDuplicateEnumValues()
14689 DupKey Key = GetDupKey(ECD->getInitVal()); in CheckForDuplicateEnumValues()
14702 Vec->push_back(D); in CheckForDuplicateEnumValues()
14703 Vec->push_back(ECD); in CheckForDuplicateEnumValues()
14716 if (*Vec->begin() == ECD) in CheckForDuplicateEnumValues()
14719 Vec->push_back(ECD); in CheckForDuplicateEnumValues()
14727 assert(Vec->size() > 1 && "ECDVector should have at least 2 elements."); in CheckForDuplicateEnumValues()
14730 ECDVector::iterator I = Vec->begin(); in CheckForDuplicateEnumValues()
14731 S.Diag((*I)->getLocation(), diag::warn_duplicate_enum_values) in CheckForDuplicateEnumValues()
14732 << (*I)->getName() << (*I)->getInitVal().toString(10) in CheckForDuplicateEnumValues()
14733 << (*I)->getSourceRange(); in CheckForDuplicateEnumValues()
14738 for (ECDVector::iterator E = Vec->end(); I != E; ++I) in CheckForDuplicateEnumValues()
14739 S.Diag((*I)->getLocation(), diag::note_duplicate_element) in CheckForDuplicateEnumValues()
14740 << (*I)->getName() << (*I)->getInitVal().toString(10) in CheckForDuplicateEnumValues()
14741 << (*I)->getSourceRange(); in CheckForDuplicateEnumValues()
14748 assert(ED->hasAttr<FlagEnumAttr>() && "looking for value in non-flag enum"); in IsValueInFlagEnum()
14749 assert(ED->isCompleteDefinition() && "expected enum definition"); in IsValueInFlagEnum()
14752 llvm::APInt &FlagBits = R.first->second; in IsValueInFlagEnum()
14755 for (auto *E : ED->enumerators()) { in IsValueInFlagEnum()
14756 const auto &EVal = E->getInitVal(); in IsValueInFlagEnum()
14757 // Only single-bit enumerators introduce new flag values. in IsValueInFlagEnum()
14785 if (Enum->isDependentType()) { in ActOnEnumBody()
14791 ECD->setType(EnumType); in ActOnEnumBody()
14794 Enum->completeDefinition(Context.DependentTy, Context.DependentTy, 0, 0); in ActOnEnumBody()
14818 const llvm::APSInt &InitVal = ECD->getInitVal(); in ActOnEnumBody()
14830 AllElementsInt = ECD->getType() == Context.IntTy; in ActOnEnumBody()
14848 bool Packed = Enum->hasAttr<PackedAttr>(); in ActOnEnumBody()
14849 // -fshort-enums is the equivalent to specifying the packed attribute on all in ActOnEnumBody()
14854 if (Enum->isFixed()) { in ActOnEnumBody()
14855 BestType = Enum->getIntegerType(); in ActOnEnumBody()
14856 if (BestType->isPromotableIntegerType()) in ActOnEnumBody()
14886 Diag(Enum->getLocation(), diag::ext_enum_too_large); in ActOnEnumBody()
14939 llvm::APSInt InitVal = ECD->getInitVal(); in ActOnEnumBody()
14947 !Enum->isFixed() && in ActOnEnumBody()
14952 } else if (ECD->getType() == BestType) { in ActOnEnumBody()
14956 // enum-specifier, each enumerator has the type of its in ActOnEnumBody()
14958 ECD->setType(EnumType); in ActOnEnumBody()
14963 NewSign = BestType->isSignedIntegerOrEnumerationType(); in ActOnEnumBody()
14969 ECD->setInitVal(InitVal); in ActOnEnumBody()
14972 if (ECD->getInitExpr() && in ActOnEnumBody()
14973 !Context.hasSameType(NewTy, ECD->getInitExpr()->getType())) in ActOnEnumBody()
14974 ECD->setInitExpr(ImplicitCastExpr::Create(Context, NewTy, in ActOnEnumBody()
14976 ECD->getInitExpr(), in ActOnEnumBody()
14981 // enum-specifier, each enumerator has the type of its in ActOnEnumBody()
14983 ECD->setType(EnumType); in ActOnEnumBody()
14985 ECD->setType(NewTy); in ActOnEnumBody()
14988 Enum->completeDefinition(BestType, BestPromotionType, in ActOnEnumBody()
14993 if (Enum->hasAttr<FlagEnumAttr>()) { in ActOnEnumBody()
14998 llvm::APSInt InitVal = ECD->getInitVal(); in ActOnEnumBody()
15001 Diag(ECD->getLocation(), diag::warn_flag_enum_constant_out_of_range) in ActOnEnumBody()
15007 if (Enum->hasAttrs()) in ActOnEnumBody()
15019 CurContext->addDecl(New); in ActOnFileScopeAsmDecl()
15029 switch (LSD->getLanguage()) { in checkModuleImportContext()
15032 ExternCLoc = LSD->getLocStart(); in checkModuleImportContext()
15037 DC = LSD->getParent(); in checkModuleImportContext()
15041 DC = DC->getParent(); in checkModuleImportContext()
15047 << M->getFullModuleName() << DC; in checkModuleImportContext()
15048 S.Diag(cast<Decl>(DC)->getLocStart(), in checkModuleImportContext()
15050 } else if (!M->IsExternC && ExternCLoc.isValid()) { in checkModuleImportContext()
15052 << M->getFullModuleName(); in checkModuleImportContext()
15075 // of the same top-level module. Until we do, make it an error rather than in ActOnModuleImport()
15077 if (Mod->getTopLevelModuleName() == getLangOpts().CurrentModule) in ActOnModuleImport()
15081 << Mod->getFullModuleName() << getLangOpts().CurrentModule; in ActOnModuleImport()
15090 ModCheck = ModCheck->Parent; in ActOnModuleImport()
15099 Context.getTranslationUnitDecl()->addDecl(Import); in ActOnModuleImport()
15121 getLangOpts().CurrentModule != Mod->getTopLevelModuleName()); in ActOnModuleInclude()
15130 TU->addDecl(ImportD); in ActOnModuleInclude()
15169 TU->addDecl(ImportD); in createImplicitModuleImportForErrorRecovery()
15185 AsmLabelAttr::CreateImplicit(Context, AliasName->getName(), AliasNameLoc); in ActOnPragmaRedefineExtname()
15190 // already exists, add a label attribute to it. in ActOnPragmaRedefineExtname()
15193 PrevDecl->addAttr(Attr); in ActOnPragmaRedefineExtname()
15195 Diag(PrevDecl->getLocation(), diag::warn_redefine_extname_not_applied) in ActOnPragmaRedefineExtname()
15197 // Otherwise, add a label atttibute to ExtnameUndeclaredIdentifiers. in ActOnPragmaRedefineExtname()
15208 PrevDecl->addAttr(WeakAttr::CreateImplicit(Context, PragmaLoc)); in ActOnPragmaWeakID()
15226 if (!PrevDecl->hasAttr<AliasAttr>()) in ActOnPragmaWeakAlias()
15244 // If we are within an Objective-C method, we should consult in getCurContextAvailability()
15250 AvailabilityResult R = MD->getAvailability(); in getCurContextAvailability()
15253 D = MD->getClassInterface(); in getCurContextAvailability()
15255 // If we are within an Objective-c @implementation, it in getCurContextAvailability()
15259 D = ID->getClassInterface(); in getCurContextAvailability()
15262 return D ? D->getAvailability() : AR_Available; in getCurContextAvailability()