diff options
Diffstat (limited to 'lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 803 |
1 files changed, 400 insertions, 403 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 1c7157c2c0..64dc41e31a 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -38,13 +38,13 @@ namespace { /// contains any ill-formed subexpressions. For example, this will /// diagnose the use of local variables or parameters within the /// default argument expression. - class VISIBILITY_HIDDEN CheckDefaultArgumentVisitor + class VISIBILITY_HIDDEN CheckDefaultArgumentVisitor : public StmtVisitor<CheckDefaultArgumentVisitor, bool> { Expr *DefaultArg; Sema *S; public: - CheckDefaultArgumentVisitor(Expr *defarg, Sema *s) + CheckDefaultArgumentVisitor(Expr *defarg, Sema *s) : DefaultArg(defarg), S(s) {} bool VisitExpr(Expr *Node); @@ -55,7 +55,7 @@ namespace { /// VisitExpr - Visit all of the children of this expression. bool CheckDefaultArgumentVisitor::VisitExpr(Expr *Node) { bool IsInvalid = false; - for (Stmt::child_iterator I = Node->child_begin(), + for (Stmt::child_iterator I = Node->child_begin(), E = Node->child_end(); I != E; ++I) IsInvalid |= Visit(*I); return IsInvalid; @@ -75,7 +75,7 @@ namespace { // evaluated. Parameters of a function declared before a default // argument expression are in scope and can hide namespace and // class member names. - return S->Diag(DRE->getSourceRange().getBegin(), + return S->Diag(DRE->getSourceRange().getBegin(), diag::err_param_default_argument_references_param) << Param->getDeclName() << DefaultArg->getSourceRange(); } else if (VarDecl *VDecl = dyn_cast<VarDecl>(Decl)) { @@ -83,7 +83,7 @@ namespace { // Local variables shall not be used in default argument // expressions. if (VDecl->isBlockVarDecl()) - return S->Diag(DRE->getSourceRange().getBegin(), + return S->Diag(DRE->getSourceRange().getBegin(), diag::err_param_default_argument_references_local) << VDecl->getDeclName() << DefaultArg->getSourceRange(); } @@ -104,8 +104,7 @@ namespace { bool Sema::SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg, - SourceLocation EqualLoc) -{ + SourceLocation EqualLoc) { QualType ParamType = Param->getType(); if (RequireCompleteType(Param->getLocation(), Param->getType(), @@ -115,24 +114,24 @@ Sema::SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg, } Expr *Arg = (Expr *)DefaultArg.get(); - + // C++ [dcl.fct.default]p5 // A default argument expression is implicitly converted (clause // 4) to the parameter type. The default argument expression has // the same semantic constraints as the initializer expression in // a declaration of a variable of the parameter type, using the // copy-initialization semantics (8.5). - if (CheckInitializerTypes(Arg, ParamType, EqualLoc, + if (CheckInitializerTypes(Arg, ParamType, EqualLoc, Param->getDeclName(), /*DirectInit=*/false)) return true; Arg = MaybeCreateCXXExprWithTemporaries(Arg, /*DestroyTemps=*/false); - + // Okay: add the default argument to the parameter Param->setDefaultArg(Arg); - + DefaultArg.release(); - + return false; } @@ -140,11 +139,11 @@ Sema::SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg, /// provided for a function parameter is well-formed. If so, attach it /// to the parameter declaration. void -Sema::ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, +Sema::ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, ExprArg defarg) { if (!param || !defarg.get()) return; - + ParmVarDecl *Param = cast<ParmVarDecl>(param.getAs<Decl>()); UnparsedDefaultArgLocs.erase(Param); @@ -165,7 +164,7 @@ Sema::ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, Param->setInvalidDecl(); return; } - + SetParamDefaultArgument(Param, move(DefaultArg), EqualLoc); } @@ -173,16 +172,16 @@ Sema::ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, /// argument for a function parameter, but we can't parse it yet /// because we're inside a class definition. Note that this default /// argument will be parsed later. -void Sema::ActOnParamUnparsedDefaultArgument(DeclPtrTy param, +void Sema::ActOnParamUnparsedDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, SourceLocation ArgLoc) { if (!param) return; - + ParmVarDecl *Param = cast<ParmVarDecl>(param.getAs<Decl>()); if (Param) Param->setUnparsedDefaultArg(); - + UnparsedDefaultArgLocs[Param] = ArgLoc; } @@ -191,11 +190,11 @@ void Sema::ActOnParamUnparsedDefaultArgument(DeclPtrTy param, void Sema::ActOnParamDefaultArgumentError(DeclPtrTy param) { if (!param) return; - + ParmVarDecl *Param = cast<ParmVarDecl>(param.getAs<Decl>()); - + Param->setInvalidDecl(); - + UnparsedDefaultArgLocs.erase(Param); } @@ -258,8 +257,8 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old) { ParmVarDecl *OldParam = Old->getParamDecl(p); ParmVarDecl *NewParam = New->getParamDecl(p); - if(OldParam->getDefaultArg() && NewParam->getDefaultArg()) { - Diag(NewParam->getLocation(), + if (OldParam->getDefaultArg() && NewParam->getDefaultArg()) { + Diag(NewParam->getLocation(), diag::err_param_default_argument_redefinition) << NewParam->getDefaultArg()->getSourceRange(); Diag(OldParam->getLocation(), diag::note_previous_definition); @@ -300,19 +299,19 @@ void Sema::CheckCXXDefaultArguments(FunctionDecl *FD) { // declarations. A default argument shall not be redefined // by a later declaration (not even to the same value). unsigned LastMissingDefaultArg = 0; - for(; p < NumParams; ++p) { + for (; p < NumParams; ++p) { ParmVarDecl *Param = FD->getParamDecl(p); if (!Param->hasDefaultArg()) { if (Param->isInvalidDecl()) /* We already complained about this parameter. */; else if (Param->getIdentifier()) - Diag(Param->getLocation(), + Diag(Param->getLocation(), diag::err_param_default_argument_missing_name) << Param->getIdentifier(); else - Diag(Param->getLocation(), + Diag(Param->getLocation(), diag::err_param_default_argument_missing); - + LastMissingDefaultArg = p; } } @@ -352,7 +351,7 @@ bool Sema::isCurrentClassName(const IdentifierInfo &II, Scope *, return false; } -/// \brief Check the validity of a C++ base class specifier. +/// \brief Check the validity of a C++ base class specifier. /// /// \returns a new CXXBaseSpecifier if well-formed, emits diagnostics /// and returns NULL otherwise. @@ -360,7 +359,7 @@ CXXBaseSpecifier * Sema::CheckBaseSpecifier(CXXRecordDecl *Class, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, - QualType BaseType, + QualType BaseType, SourceLocation BaseLoc) { // C++ [class.union]p1: // A union shall not have base classes. @@ -371,7 +370,7 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class, } if (BaseType->isDependentType()) - return new (Context) CXXBaseSpecifier(SpecifierRange, Virtual, + return new (Context) CXXBaseSpecifier(SpecifierRange, Virtual, Class->getTagKind() == RecordDecl::TK_class, Access, BaseType); @@ -391,7 +390,7 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class, // C++ [class.derived]p2: // The class-name in a base-specifier shall not be an incompletely // defined class. - if (RequireCompleteType(BaseLoc, BaseType, + if (RequireCompleteType(BaseLoc, BaseType, PDiag(diag::err_incomplete_base_class) << SpecifierRange)) return 0; @@ -433,7 +432,7 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class, Class->setEmpty(false); } else { // C++ [class.ctor]p5: - // A constructor is trivial if all the direct base classes of its + // A constructor is trivial if all the direct base classes of its // class have trivial constructors. if (!cast<CXXRecordDecl>(BaseDecl)->hasTrivialConstructor()) Class->setHasTrivialConstructor(false); @@ -456,20 +455,20 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class, // have trivial destructors. if (!cast<CXXRecordDecl>(BaseDecl)->hasTrivialDestructor()) Class->setHasTrivialDestructor(false); - + // Create the base specifier. // FIXME: Allocate via ASTContext? - return new (Context) CXXBaseSpecifier(SpecifierRange, Virtual, - Class->getTagKind() == RecordDecl::TK_class, + return new (Context) CXXBaseSpecifier(SpecifierRange, Virtual, + Class->getTagKind() == RecordDecl::TK_class, Access, BaseType); } /// ActOnBaseSpecifier - Parsed a base specifier. A base specifier is /// one entry in the base class list of a class specifier, for -/// example: -/// class foo : public bar, virtual private baz { +/// example: +/// class foo : public bar, virtual private baz { /// 'public bar' and 'virtual private baz' are each base-specifiers. -Sema::BaseResult +Sema::BaseResult Sema::ActOnBaseSpecifier(DeclPtrTy classdecl, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, TypeTy *basetype, SourceLocation BaseLoc) { @@ -483,7 +482,7 @@ Sema::ActOnBaseSpecifier(DeclPtrTy classdecl, SourceRange SpecifierRange, Virtual, Access, BaseType, BaseLoc)) return BaseSpec; - + return true; } @@ -504,7 +503,7 @@ bool Sema::AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, unsigned NumGoodBases = 0; bool Invalid = false; for (unsigned idx = 0; idx < NumBases; ++idx) { - QualType NewBaseType + QualType NewBaseType = Context.getCanonicalType(Bases[idx]->getType()); NewBaseType = NewBaseType.getUnqualifiedType(); @@ -543,7 +542,7 @@ bool Sema::AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, /// ActOnBaseSpecifiers - Attach the given base specifiers to the /// class, after checking whether there are any duplicate base /// classes. -void Sema::ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases, +void Sema::ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases, unsigned NumBases) { if (!ClassDecl || !Bases || !NumBases) return; @@ -592,7 +591,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, Diag(DS.getStorageClassSpecLoc(), diag::err_mutable_function); else Diag(DS.getThreadSpecLoc(), diag::err_mutable_function); - + // FIXME: It would be nicer if the keyword was ignored only for this // declarator. Otherwise we could get follow-up errors. D.getMutableDeclSpec().ClearStorageClassSpecs(); @@ -670,17 +669,17 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, // A function typedef ("typedef int f(); f a;"). // C++ 9.6p3: A bit-field shall have integral or enumeration type. Diag(Loc, diag::err_not_integral_type_bitfield) - << Name << cast<ValueDecl>(Member)->getType() + << Name << cast<ValueDecl>(Member)->getType() << BitWidth->getSourceRange(); } - + DeleteExpr(BitWidth); BitWidth = 0; Member->setInvalidDecl(); } Member->setAccess(AS); - + // If we have declared a member function template, set the access of the // templated declaration as well. if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(Member)) @@ -702,7 +701,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, } /// ActOnMemInitializer - Handle a C++ member initializer. -Sema::MemInitResult +Sema::MemInitResult Sema::ActOnMemInitializer(DeclPtrTy ConstructorD, Scope *S, const CXXScopeSpec &SS, @@ -715,10 +714,10 @@ Sema::ActOnMemInitializer(DeclPtrTy ConstructorD, SourceLocation RParenLoc) { if (!ConstructorD) return true; - + AdjustDeclIfTemplate(ConstructorD); - - CXXConstructorDecl *Constructor + + CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(ConstructorD.getAs<Decl>()); if (!Constructor) { // The user wrote a constructor initializer on a function that is @@ -743,7 +742,7 @@ Sema::ActOnMemInitializer(DeclPtrTy ConstructorD, if (!SS.getScopeRep() && !TemplateTypeTy) { // Look for a member, first. FieldDecl *Member = 0; - DeclContext::lookup_result Result + DeclContext::lookup_result Result = ClassDecl->lookup(MemberOrBase); if (Result.first != Result.second) Member = dyn_cast<FieldDecl>(*Result.first); @@ -755,12 +754,12 @@ Sema::ActOnMemInitializer(DeclPtrTy ConstructorD, RParenLoc); } // It didn't name a member, so see if it names a class. - TypeTy *BaseTy = TemplateTypeTy ? TemplateTypeTy + TypeTy *BaseTy = TemplateTypeTy ? TemplateTypeTy : getTypeName(*MemberOrBase, IdLoc, S, &SS); if (!BaseTy) return Diag(IdLoc, diag::err_mem_init_not_member_or_class) << MemberOrBase << SourceRange(IdLoc, RParenLoc); - + QualType BaseType = GetTypeFromParser(BaseTy); return BuildBaseInitializer(BaseType, (Expr **)Args, NumArgs, IdLoc, @@ -784,10 +783,10 @@ Sema::BuildMemberInitializer(FieldDecl *Member, Expr **Args, } else if (FieldType->getAs<RecordType>()) { if (!HasDependentArg) C = PerformInitializationByConstructor( - FieldType, (Expr **)Args, NumArgs, IdLoc, + FieldType, (Expr **)Args, NumArgs, IdLoc, SourceRange(IdLoc, RParenLoc), Member->getDeclName(), IK_Direct); } else if (NumArgs != 1 && NumArgs != 0) { - return Diag(IdLoc, diag::err_mem_initializer_mismatch) + return Diag(IdLoc, diag::err_mem_initializer_mismatch) << Member->getDeclName() << SourceRange(IdLoc, RParenLoc); } else if (!HasDependentArg) { Expr *NewExp; @@ -807,7 +806,7 @@ Sema::BuildMemberInitializer(FieldDecl *Member, Expr **Args, Args[0] = NewExp; } // FIXME: Perform direct initialization of the member. - return new (Context) CXXBaseOrMemberInitializer(Member, (Expr **)Args, + return new (Context) CXXBaseOrMemberInitializer(Member, (Expr **)Args, NumArgs, C, IdLoc, RParenLoc); } @@ -830,12 +829,12 @@ Sema::BuildBaseInitializer(QualType BaseType, Expr **Args, // of that class, the mem-initializer is ill-formed. A // mem-initializer-list can initialize a base class using any // name that denotes that base class type. - + // First, check for a direct base class. const CXXBaseSpecifier *DirectBaseSpec = 0; for (CXXRecordDecl::base_class_const_iterator Base = ClassDecl->bases_begin(); Base != ClassDecl->bases_end(); ++Base) { - if (Context.getCanonicalType(BaseType).getUnqualifiedType() == + if (Context.getCanonicalType(BaseType).getUnqualifiedType() == Context.getCanonicalType(Base->getType()).getUnqualifiedType()) { // We found a direct base of this type. That's what we're // initializing. @@ -843,7 +842,7 @@ Sema::BuildBaseInitializer(QualType BaseType, Expr **Args, break; } } - + // Check for a virtual base class. // FIXME: We might be able to short-circuit this if we know in advance that // there are no virtual bases. @@ -854,7 +853,7 @@ Sema::BuildBaseInitializer(QualType BaseType, Expr **Args, BasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, /*DetectVirtual=*/false); if (IsDerivedFrom(Context.getTypeDeclType(ClassDecl), BaseType, Paths)) { - for (BasePaths::paths_iterator Path = Paths.begin(); + for (BasePaths::paths_iterator Path = Paths.begin(); Path != Paths.end(); ++Path) { if (Path->back().Base->isVirtual()) { VirtualBaseSpec = Path->back().Base; @@ -886,11 +885,11 @@ Sema::BuildBaseInitializer(QualType BaseType, Expr **Args, DeclarationName Name = Context.DeclarationNames.getCXXConstructorName( Context.getCanonicalType(BaseType)); C = PerformInitializationByConstructor(BaseType, (Expr **)Args, NumArgs, - IdLoc, SourceRange(IdLoc, RParenLoc), + IdLoc, SourceRange(IdLoc, RParenLoc), Name, IK_Direct); } - return new (Context) CXXBaseOrMemberInitializer(BaseType, (Expr **)Args, + return new (Context) CXXBaseOrMemberInitializer(BaseType, (Expr **)Args, NumArgs, C, IdLoc, RParenLoc); } @@ -898,7 +897,7 @@ void Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, CXXBaseOrMemberInitializer **Initializers, unsigned NumInitializers, - llvm::SmallVectorImpl<CXXBaseSpecifier *>& Bases, + llvm::SmallVectorImpl<CXXBaseSpecifier *>& Bases, llvm::SmallVectorImpl<FieldDecl *>&Fields) { // We need to build the initializer AST according to order of construction // and not what user specified in the Initializers list. @@ -906,7 +905,7 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, llvm::SmallVector<CXXBaseOrMemberInitializer*, 32> AllToInit; llvm::DenseMap<const void *, CXXBaseOrMemberInitializer*> AllBaseFields; bool HasDependentBaseInit = false; - + for (unsigned i = 0; i < NumInitializers; i++) { CXXBaseOrMemberInitializer *Member = Initializers[i]; if (Member->isBaseInitializer()) { @@ -917,13 +916,13 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, AllBaseFields[Member->getMember()] = Member; } } - + if (HasDependentBaseInit) { // FIXME. This does not preserve the ordering of the initializers. // Try (with -Wreorder) // template<class X> struct A {}; - // template<class X> struct B : A<X> { - // B() : x1(10), A<X>() {} + // template<class X> struct B : A<X> { + // B() : x1(10), A<X>() {} // int x1; // }; // B<int> x; @@ -931,7 +930,7 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, // while preserving user-declared initializer list. When this routine is // called during instantiatiation process, this routine will rebuild the // oderdered initializer list correctly. - + // If we have a dependent base initialization, we can't determine the // association between initializers and bases; just dump the known // initializers into the list, and don't try to deal with other bases. @@ -947,9 +946,9 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, E = ClassDecl->vbases_end(); VBase != E; ++VBase) { if (VBase->getType()->isDependentType()) continue; - if (CXXBaseOrMemberInitializer *Value = + if (CXXBaseOrMemberInitializer *Value = AllBaseFields.lookup(VBase->getType()->getAs<RecordType>())) { - CXXRecordDecl *BaseDecl = + CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(VBase->getType()->getAs<RecordType>()->getDecl()); assert(BaseDecl && "setBaseOrMemberInitializers - BaseDecl null"); if (CXXConstructorDecl *Ctor = BaseDecl->getDefaultConstructor(Context)) @@ -957,7 +956,7 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, AllToInit.push_back(Value); } else { - CXXRecordDecl *VBaseDecl = + CXXRecordDecl *VBaseDecl = cast<CXXRecordDecl>(VBase->getType()->getAs<RecordType>()->getDecl()); assert(VBaseDecl && "setBaseOrMemberInitializers - VBaseDecl null"); CXXConstructorDecl *Ctor = VBaseDecl->getDefaultConstructor(Context); @@ -966,7 +965,7 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, else MarkDeclarationReferenced(Constructor->getLocation(), Ctor); - CXXBaseOrMemberInitializer *Member = + CXXBaseOrMemberInitializer *Member = new (Context) CXXBaseOrMemberInitializer(VBase->getType(), 0, 0, Ctor, SourceLocation(), @@ -974,7 +973,7 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, AllToInit.push_back(Member); } } - + for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), E = ClassDecl->bases_end(); Base != E; ++Base) { @@ -984,9 +983,9 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, // Skip dependent types. if (Base->getType()->isDependentType()) continue; - if (CXXBaseOrMemberInitializer *Value = + if (CXXBaseOrMemberInitializer *Value = AllBaseFields.lookup(Base->getType()->getAs<RecordType>())) { - CXXRecordDecl *BaseDecl = + CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); assert(BaseDecl && "setBaseOrMemberInitializers - BaseDecl null"); if (CXXConstructorDecl *Ctor = BaseDecl->getDefaultConstructor(Context)) @@ -994,7 +993,7 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, AllToInit.push_back(Value); } else { - CXXRecordDecl *BaseDecl = + CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); assert(BaseDecl && "setBaseOrMemberInitializers - BaseDecl null"); CXXConstructorDecl *Ctor = BaseDecl->getDefaultConstructor(Context); @@ -1003,7 +1002,7 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, else MarkDeclarationReferenced(Constructor->getLocation(), Ctor); - CXXBaseOrMemberInitializer *Member = + CXXBaseOrMemberInitializer *Member = new (Context) CXXBaseOrMemberInitializer(Base->getType(), 0, 0, BaseDecl->getDefaultConstructor(Context), SourceLocation(), @@ -1012,16 +1011,16 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, } } } - + // non-static data members. for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), E = ClassDecl->field_end(); Field != E; ++Field) { if ((*Field)->isAnonymousStructOrUnion()) { - if (const RecordType *FieldClassType = + if (const RecordType *FieldClassType = Field->getType()->getAs<RecordType>()) { CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(FieldClassType->getDecl()); - for(RecordDecl::field_iterator FA = FieldClassDecl->field_begin(), + for (RecordDecl::field_iterator FA = FieldClassDecl->field_begin(), EA = FieldClassDecl->field_end(); FA != EA; FA++) { if (CXXBaseOrMemberInitializer *Value = AllBaseFields.lookup(*FA)) { // 'Member' is the anonymous union field and 'AnonUnionMember' is @@ -1041,21 +1040,21 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, if (const RecordType* RT = FT->getAs<RecordType>()) { CXXRecordDecl *FieldRecDecl = cast<CXXRecordDecl>(RT->getDecl()); assert(FieldRecDecl && "setBaseOrMemberInitializers - BaseDecl null"); - if (CXXConstructorDecl *Ctor = + if (CXXConstructorDecl *Ctor = FieldRecDecl->getDefaultConstructor(Context)) MarkDeclarationReferenced(Value->getSourceLocation(), Ctor); } AllToInit.push_back(Value); continue; } - + QualType FT = Context.getBaseElementType((*Field)->getType()); if (const RecordType* RT = FT->getAs<RecordType>()) { CXXConstructorDecl *Ctor = cast<CXXRecordDecl>(RT->getDecl())->getDefaultConstructor(Context); if (!Ctor && !FT->isDependentType()) Fields.push_back(*Field); - CXXBaseOrMemberInitializer *Member = + CXXBaseOrMemberInitializer *Member = new (Context) CXXBaseOrMemberInitializer((*Field), 0, 0, Ctor, SourceLocation(), @@ -1080,13 +1079,13 @@ Sema::setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, Diag((*Field)->getLocation(), diag::note_declared_at); } } - + NumInitializers = AllToInit.size(); if (NumInitializers > 0) { Constructor->setNumBaseOrMemberInitializers(NumInitializers); CXXBaseOrMemberInitializer **baseOrMemberInitializers = new (Context) CXXBaseOrMemberInitializer*[NumInitializers]; - + Constructor->setBaseOrMemberInitializers(baseOrMemberInitializers); for (unsigned Idx = 0; Idx < NumInitializers; ++Idx) baseOrMemberInitializers[Idx] = AllToInit[Idx]; @@ -1101,14 +1100,14 @@ Sema::BuildBaseOrMemberInitializers(ASTContext &C, ) { llvm::SmallVector<CXXBaseSpecifier *, 4>Bases; llvm::SmallVector<FieldDecl *, 4>Members; - - setBaseOrMemberInitializers(Constructor, + + setBaseOrMemberInitializers(Constructor, Initializers, NumInitializers, Bases, Members); for (unsigned int i = 0; i < Bases.size(); i++) - Diag(Bases[i]->getSourceRange().getBegin(), + Diag(Bases[i]->getSourceRange().getBegin(), diag::err_missing_default_constructor) << 0 << Bases[i]->getType(); for (unsigned int i = 0; i < Members.size(); i++) - Diag(Members[i]->getLocation(), diag::err_missing_default_constructor) + Diag(Members[i]->getLocation(), diag::err_missing_default_constructor) << 1 << Members[i]->getType(); } @@ -1124,20 +1123,20 @@ static void *GetKeyForTopLevelField(FieldDecl *Field) { static void *GetKeyForBase(QualType BaseType) { if (const RecordType *RT = BaseType->getAs<RecordType>()) return (void *)RT; - + assert(0 && "Unexpected base type!"); return 0; } -static void *GetKeyForMember(CXXBaseOrMemberInitializer *Member, +static void *GetKeyForMember(CXXBaseOrMemberInitializer *Member, bool MemberMaybeAnon = false) { // For fields injected into the class via declaration of an anonymous union, // use its anonymous union class declaration as the unique key. if (Member->isMemberInitializer()) { FieldDecl *Field = Member->getMember(); - + // After BuildBaseOrMemberInitializers call, Field is the anonymous union - // data member of the class. Data member used in the initializer list is + // data member of the class. Data member used in the initializer list is // in AnonUnionMember field. if (MemberMaybeAnon && Field->isAnonymousStructOrUnion()) Field = Member->getAnonUnionMember(); @@ -1148,31 +1147,31 @@ static void *GetKeyForMember(CXXBaseOrMemberInitializer *Member, } return static_cast<void *>(Field); } - + return GetKeyForBase(QualType(Member->getBaseClass(), 0)); } -void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl, +void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl, SourceLocation ColonLoc, MemInitTy **MemInits, unsigned NumMemInits) { if (!ConstructorDecl) return; AdjustDeclIfTemplate(ConstructorDecl); - - CXXConstructorDecl *Constructor + + CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(ConstructorDecl.getAs<Decl>()); - + if (!Constructor) { Diag(ColonLoc, diag::err_only_constructors_take_base_inits); return; } - + if (!Constructor->isDependentContext()) { llvm::DenseMap<void*, CXXBaseOrMemberInitializer *>Members; bool err = false; for (unsigned i = 0; i < NumMemInits; i++) { - CXXBaseOrMemberInitializer *Member = + CXXBaseOrMemberInitializer *Member = static_cast<CXXBaseOrMemberInitializer*>(MemInits[i]); void *KeyToMember = GetKeyForMember(Member); CXXBaseOrMemberInitializer *&PrevMember = Members[KeyToMember]; @@ -1181,13 +1180,13 @@ void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl, continue; } if (FieldDecl *Field = Member->getMember()) - Diag(Member->getSourceLocation(), + Diag(Member->getSourceLocation(), diag::error_multiple_mem_initialization) << Field->getNameAsString(); else { Type *BaseClass = Member->getBaseClass(); assert(BaseClass && "ActOnMemInitializers - neither field or base"); - Diag(Member->getSourceLocation(), + Diag(Member->getSourceLocation(), diag::error_multiple_base_initialization) << BaseClass->getDesugaredType(true); } @@ -1195,28 +1194,28 @@ void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl, << 0; err = true; } - + if (err) return; } - + BuildBaseOrMemberInitializers(Context, Constructor, - reinterpret_cast<CXXBaseOrMemberInitializer **>(MemInits), + reinterpret_cast<CXXBaseOrMemberInitializer **>(MemInits), NumMemInits); - + if (Constructor->isDependentContext()) return; - - if (Diags.getDiagnosticLevel(diag::warn_base_initialized) == + + if (Diags.getDiagnosticLevel(diag::warn_base_initialized) == Diagnostic::Ignored && - Diags.getDiagnosticLevel(diag::warn_field_initialized) == + Diags.getDiagnosticLevel(diag::warn_field_initialized) == Diagnostic::Ignored) return; - + // Also issue warning if order of ctor-initializer list does not match order // of 1) base class declarations and 2) order of non-static data members. llvm::SmallVector<const void*, 32> AllBaseOrMembers; - + CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Constructor->getDeclContext()); // Push virtual bases before others. @@ -1224,7 +1223,7 @@ void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl, ClassDecl->vbases_begin(), E = ClassDecl->vbases_end(); VBase != E; ++VBase) AllBaseOrMembers.push_back(GetKeyForBase(VBase->getType())); - + for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), E = ClassDecl->bases_end(); Base != E; ++Base) { // Virtuals are alread in the virtual base list and are constructed @@ -1233,16 +1232,16 @@ void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl, continue; AllBaseOrMembers.push_back(GetKeyForBase(Base->getType())); } - + for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), E = ClassDecl->field_end(); Field != E; ++Field) AllBaseOrMembers.push_back(GetKeyForTopLevelField(*Field)); - + int Last = AllBaseOrMembers.size(); int curIndex = 0; CXXBaseOrMemberInitializer *PrevMember = 0; for (unsigned i = 0; i < NumMemInits; i++) { - CXXBaseOrMemberInitializer *Member = + CXXBaseOrMemberInitializer *Member = static_cast<CXXBaseOrMemberInitializer*>(MemInits[i]); void *MemberInCtorList = GetKeyForMember(Member, true); @@ -1257,27 +1256,27 @@ void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl, // Diagnostics is for an initialized base class. Type *BaseClass = PrevMember->getBaseClass(); Diag(PrevMember->getSourceLocation(), - diag::warn_base_initialized) + diag::warn_base_initialized) << BaseClass->getDesugaredType(true); } else { FieldDecl *Field = PrevMember->getMember(); Diag(PrevMember->getSourceLocation(), - diag::warn_field_initialized) + diag::warn_field_initialized) << Field->getNameAsString(); } // Also the note! if (FieldDecl *Field = Member->getMember()) - Diag(Member->getSourceLocation(), + Diag(Member->getSourceLocation(), diag::note_fieldorbase_initialized_here) << 0 << Field->getNameAsString(); else { Type *BaseClass = Member->getBaseClass(); - Diag(Member->getSourceLocation(), + Diag(Member->getSourceLocation(), diag::note_fieldorbase_initialized_here) << 1 << BaseClass->getDesugaredType(true); } for (curIndex = 0; curIndex < Last; curIndex++) - if (MemberInCtorList == AllBaseOrMembers[curIndex]) + if (MemberInCtorList == AllBaseOrMembers[curIndex]) break; } PrevMember = Member; @@ -1288,7 +1287,7 @@ void Sema::computeBaseOrMembersToDestroy(CXXDestructorDecl *Destructor) { CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Destructor->getDeclContext()); llvm::SmallVector<uintptr_t, 32> AllToDestruct; - + for (CXXRecordDecl::base_class_iterator VBase = ClassDecl->vbases_begin(), E = ClassDecl->vbases_end(); VBase != E; ++VBase) { if (VBase->getType()->isDependentType()) @@ -1299,11 +1298,11 @@ Sema::computeBaseOrMembersToDestroy(CXXDestructorDecl *Destructor) { if (BaseClassDecl->hasTrivialDestructor()) continue; if (const CXXDestructorDecl *Dtor = BaseClassDecl->getDestructor(Context)) - MarkDeclarationReferenced(Destructor->getLocation(), + MarkDeclarationReferenced(Destructor->getLocation(), const_cast<CXXDestructorDecl*>(Dtor)); - - uintptr_t Member = - reinterpret_cast<uintptr_t>(VBase->getType().getTypePtr()) + + uintptr_t Member = + reinterpret_cast<uintptr_t>(VBase->getType().getTypePtr()) | CXXDestructorDecl::VBASE; AllToDestruct.push_back(Member); } @@ -1320,37 +1319,37 @@ Sema::computeBaseOrMembersToDestroy(CXXDestructorDecl *Destructor) { if (BaseClassDecl->hasTrivialDestructor()) continue; if (const CXXDestructorDecl *Dtor = BaseClassDecl->getDestructor(Context)) - MarkDeclarationReferenced(Destructor->getLocation(), + MarkDeclarationReferenced(Destructor->getLocation(), const_cast<CXXDestructorDecl*>(Dtor)); - uintptr_t Member = - reinterpret_cast<uintptr_t>(Base->getType().getTypePtr()) + uintptr_t Member = + reinterpret_cast<uintptr_t>(Base->getType().getTypePtr()) | CXXDestructorDecl::DRCTNONVBASE; AllToDestruct.push_back(Member); } - + // non-static data members. for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), E = ClassDecl->field_end(); Field != E; ++Field) { QualType FieldType = Context.getBaseElementType((*Field)->getType()); - + if (const RecordType* RT = FieldType->getAs<RecordType>()) { // Skip over virtual bases which have trivial destructors. CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getDecl()); if (FieldClassDecl->hasTrivialDestructor()) continue; - if (const CXXDestructorDecl *Dtor = + if (const CXXDestructorDecl *Dtor = FieldClassDecl->getDestructor(Context)) - MarkDeclarationReferenced(Destructor->getLocation(), + MarkDeclarationReferenced(Destructor->getLocation(), const_cast<CXXDestructorDecl*>(Dtor)); uintptr_t Member = reinterpret_cast<uintptr_t>(*Field); AllToDestruct.push_back(Member); } } - + unsigned NumDestructions = AllToDestruct.size(); if (NumDestructions > 0) { Destructor->setNumBaseOrMemberDestructions(NumDestructions); - uintptr_t *BaseOrMemberDestructions = + uintptr_t *BaseOrMemberDestructions = new (Context) uintptr_t [NumDestructions]; // Insert in reverse order. for (int Idx = NumDestructions-1, i=0 ; Idx >= 0; --Idx) @@ -1362,10 +1361,10 @@ Sema::computeBaseOrMembersToDestroy(CXXDestructorDecl *Destructor) { void Sema::ActOnDefaultCtorInitializers(DeclPtrTy CDtorDecl) { if (!CDtorDecl) return; - + AdjustDeclIfTemplate(CDtorDecl); - - if (CXXConstructorDecl *Constructor + + if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(CDtorDecl.getAs<Decl>())) BuildBaseOrMemberInitializers(Context, Constructor, @@ -1383,31 +1382,31 @@ namespace { private: MethodList Methods; - + void Collect(const CXXRecordDecl* RD, MethodList& Methods); - + public: - PureVirtualMethodCollector(ASTContext &Ctx, const CXXRecordDecl* RD) + PureVirtualMethodCollector(ASTContext &Ctx, const CXXRecordDecl* RD) : Context(Ctx) { - + MethodList List; Collect(RD, List); - + // Copy the temporary list to methods, and make sure to ignore any // null entries. for (size_t i = 0, e = List.size(); i != e; ++i) { if (List[i]) Methods.push_back(List[i]); - } + } } - + bool empty() const { return Methods.empty(); } - + MethodList::const_iterator methods_begin() { return Methods.begin(); } MethodList::const_iterator methods_end() { return Methods.end(); } }; - - void PureVirtualMethodCollector::Collect(const CXXRecordDecl* RD, + + void PureVirtualMethodCollector::Collect(const CXXRecordDecl* RD, MethodList& Methods) { // First, collect the pure virtual methods for the base classes. for (CXXRecordDecl::base_class_const_iterator Base = RD->bases_begin(), @@ -1418,14 +1417,14 @@ namespace { Collect(BaseDecl, Methods); } } - + // Next, zero out any pure virtual methods that this class overrides. typedef llvm::SmallPtrSet<const CXXMethodDecl*, 4> MethodSetTy; - + MethodSetTy OverriddenMethods; size_t MethodsSize = Methods.size(); - for (RecordDecl::decl_iterator i = RD->decls_begin(), e = RD->decls_end(); + for (RecordDecl::decl_iterator i = RD->decls_begin(), e = RD->decls_end(); i != e; ++i) { // Traverse the record, looking for methods. if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(*i)) { @@ -1434,7 +1433,7 @@ namespace { Methods.push_back(MD); continue; } - + // Otherwise, record all the overridden methods in our set. for (CXXMethodDecl::method_iterator I = MD->begin_overridden_methods(), E = MD->end_overridden_methods(); I != E; ++I) { @@ -1443,19 +1442,19 @@ namespace { } } } - - // Now go through the methods and zero out all the ones we know are + + // Now go through the methods and zero out all the ones we know are // overridden. for (size_t i = 0, e = MethodsSize; i != e; ++i) { if (OverriddenMethods.count(Methods[i])) Methods[i] = 0; } - + } } -bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T, +bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, AbstractDiagSelID SelID, const CXXRecordDecl *CurrentRD) { if (SelID == -1) @@ -1464,71 +1463,71 @@ bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T, else return RequireNonAbstractType(Loc, T, PDiag(DiagID) << SelID, CurrentRD); -} - +} + bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T, const PartialDiagnostic &PD, const CXXRecordDecl *CurrentRD) { if (!getLangOptions().CPlusPlus) return false; - + if (const ArrayType *AT = Context.getAsArrayType(T)) return RequireNonAbstractType(Loc, AT->getElementType(), PD, CurrentRD); - + if (const PointerType *PT = T->getAs<PointerType>()) { // Find the innermost pointer type. while (const PointerType *T = PT->getPointeeType()->getAs<PointerType>()) PT = T; - + if (const ArrayType *AT = Context.getAsArrayType(PT->getPointeeType())) return RequireNonAbstractType(Loc, AT->getElementType(), PD, CurrentRD); } - + const RecordType *RT = T->getAs<RecordType>(); if (!RT) return false; - + const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()); if (!RD) return false; if (CurrentRD && CurrentRD != RD) return false; - + if (!RD->isAbstract()) return false; - + Diag(Loc, PD) << RD->getDeclName(); - + // Check if we've already emitted the list of pure virtual functions for this // class. if (PureVirtualClassDiagSet && PureVirtualClassDiagSet->count(RD)) return true; - + PureVirtualMethodCollector Collector(Context, RD); - - for (PureVirtualMethodCollector::MethodList::const_iterator I = + + for (PureVirtualMethodCollector::MethodList::const_iterator I = Collector.methods_begin(), E = Collector.methods_end(); I != E; ++I) { const CXXMethodDecl *MD = *I; - - Diag(MD->getLocation(), diag::note_pure_virtual_function) << + + Diag(MD->getLocation(), diag::note_pure_virtual_function) << MD->getDeclName(); } if (!PureVirtualClassDiagSet) PureVirtualClassDiagSet.reset(new RecordDeclSetTy); PureVirtualClassDiagSet->insert(RD); - + return true; } namespace { - class VISIBILITY_HIDDEN AbstractClassUsageDiagnoser + class VISIBILITY_HIDDEN AbstractClassUsageDiagnoser : public DeclVisitor<AbstractClassUsageDiagnoser, bool> { Sema &SemaRef; CXXRecordDecl *AbstractClass; - + bool VisitDeclContext(const DeclContext *DC) { bool Invalid = false; @@ -1538,7 +1537,7 @@ namespace { return Invalid; } - + public: AbstractClassUsageDiagnoser(Sema& SemaRef, CXXRecordDecl *ac) : SemaRef(SemaRef), AbstractClass(ac) { @@ -1549,36 +1548,36 @@ namespace { if (FD->isThisDeclarationADefinition()) { // No need to do the check if we're in a definition, because it requires // that the return/param types are complete. - // because that requires + // because that requires return VisitDeclContext(FD); } - + // Check the return type. QualType RTy = FD->getType()->getAsFunctionType()->getResultType(); - bool Invalid = + bool Invalid = SemaRef.RequireNonAbstractType(FD->getLocation(), RTy, diag::err_abstract_type_in_decl, Sema::AbstractReturnType, AbstractClass); - for (FunctionDecl::param_const_iterator I = FD->param_begin(), + for (FunctionDecl::param_const_iterator I = FD->param_begin(), E = FD->param_end(); I != E; ++I) { const ParmVarDecl *VD = *I; - Invalid |= + Invalid |= SemaRef.RequireNonAbstractType(VD->getLocation(), - VD->getOriginalType(), - diag::err_abstract_type_in_decl, + VD->getOriginalType(), + diag::err_abstract_type_in_decl, Sema::AbstractParamType, AbstractClass); } return Invalid; } - + bool VisitDecl(const Decl* D) { if (const DeclContext *DC = dyn_cast<DeclContext>(D)) return VisitDeclContext(DC); - + return false; } }; @@ -1590,7 +1589,7 @@ void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, SourceLocation RBrac) { if (!TagDecl) return; - + AdjustDeclIfTemplate(TagDecl); ActOnFields(S, RLoc, TagDecl, (DeclPtrTy*)FieldCollector->getCurFields(), @@ -1601,13 +1600,13 @@ void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, // Collect all the pure virtual methods and see if this is an abstract // class after all. PureVirtualMethodCollector Collector(Context, RD); - if (!Collector.empty()) + if (!Collector.empty()) RD->setAbstract(true); } - - if (RD->isAbstract()) + + if (RD->isAbstract()) AbstractClassUsageDiagnoser(*this, RD); - + if (!RD->isDependentType()) AddImplicitlyDeclaredMembersToClass(RD); } @@ -1618,7 +1617,7 @@ void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, /// [special]p1). This routine can only be executed just before the /// definition of the class is complete. void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { - CanQualType ClassType + CanQualType ClassType = Context.getCanonicalType(Context.getTypeDeclType(ClassDecl)); // FIXME: Implicit declarations have exception specifications, which are @@ -1631,9 +1630,9 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { // user-declared constructor for class X, a default constructor is // implicitly declared. An implicitly-declared default constructor // is an inline public member of its class. - DeclarationName Name + DeclarationName Name = Context.DeclarationNames.getCXXConstructorName(ClassType); - CXXConstructorDecl *DefaultCon = + CXXConstructorDecl *DefaultCon = CXXConstructorDecl::Create(Context, ClassDecl, ClassDecl->getLocation(), Name, Context.getFunctionType(Context.VoidTy, @@ -1669,7 +1668,7 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { HasConstCopyConstructor && Base != ClassDecl->bases_end(); ++Base) { const CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); - HasConstCopyConstructor + HasConstCopyConstructor = BaseClassDecl->hasConstCopyConstructor(Context); } @@ -1684,9 +1683,9 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { if (const ArrayType *Array = Context.getAsArrayType(FieldType)) FieldType = Array->getElementType(); if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) { - const CXXRecordDecl *FieldClassDecl + const CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(FieldClassType->getDecl()); - HasConstCopyConstructor + HasConstCopyConstructor = FieldClassDecl->hasConstCopyConstructor(Context); } } @@ -1702,7 +1701,7 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { // An implicitly-declared copy constructor is an inline public // member of its class. - DeclarationName Name + DeclarationName Name = Context.DeclarationNames.getCXXConstructorName(ClassType); CXXConstructorDecl *CopyConstructor = CXXConstructorDecl::Create(Context, ClassDecl, @@ -1753,7 +1752,7 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { const CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); const CXXMethodDecl *MD = 0; - HasConstCopyAssignment = BaseClassDecl->hasConstCopyAssignment(Context, + HasConstCopyAssignment = BaseClassDecl->hasConstCopyAssignment(Context, MD); } @@ -1818,9 +1817,9 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { // If a class has no user-declared destructor, a destructor is // declared implicitly. An implicitly-declared destructor is an // inline public member of its class. - DeclarationName Name + DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(ClassType); - CXXDestructorDecl *Destructor + CXXDestructorDecl *Destructor = CXXDestructorDecl::Create(Context, ClassDecl, ClassDecl->getLocation(), Name, Context.getFunctionType(Context.VoidTy, @@ -1862,12 +1861,12 @@ void Sema::ActOnReenterTemplateScope(Scope *S, DeclPtrTy TemplateD) { void Sema::ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclPtrTy MethodD) { if (!MethodD) return; - + AdjustDeclIfTemplate(MethodD); - + CXXScopeSpec SS; FunctionDecl *Method = cast<FunctionDecl>(MethodD.getAs<Decl>()); - QualType ClassTy + QualType ClassTy = Context.getTypeDeclType(cast<RecordDecl>(Method->getDeclContext())); SS.setScopeRep( NestedNameSpecifier::Create(Context, 0, false, ClassTy.getTypePtr())); @@ -1882,7 +1881,7 @@ void Sema::ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclPtrTy MethodD) { void Sema::ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy ParamD) { if (!ParamD) return; - + ParmVarDecl *Param = cast<ParmVarDecl>(ParamD.getAs<Decl>()); // If this parameter has an unparsed default argument, clear it out @@ -1904,12 +1903,12 @@ void Sema::ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy ParamD) { void Sema::ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclPtrTy MethodD) { if (!MethodD) return; - + AdjustDeclIfTemplate(MethodD); - + FunctionDecl *Method = cast<FunctionDecl>(MethodD.getAs<Decl>()); CXXScopeSpec SS; - QualType ClassTy + QualType ClassTy = Context.getTypeDeclType(cast<RecordDecl>(Method->getDeclContext())); SS.setScopeRep( NestedNameSpecifier::Create(Context, 0, false, ClassTy.getTypePtr())); @@ -1957,7 +1956,7 @@ QualType Sema::CheckConstructorDeclarator(Declarator &D, QualType R, D.setInvalidType(); SC = FunctionDecl::None; } - + DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun; if (FTI.TypeQuals != 0) { if (FTI.TypeQuals & QualType::Const) @@ -1970,7 +1969,7 @@ QualType Sema::CheckConstructorDeclarator(Declarator &D, QualType R, Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_constructor) << "restrict" << SourceRange(D.getIdentifierLoc()); } - + // Rebuild the function type "R" without any type qualifiers (in // case any of the errors above fired) and with "void" as the // return type, since constructors don't have return types. We @@ -1986,7 +1985,7 @@ QualType Sema::CheckConstructorDeclarator(Declarator &D, QualType R, /// well-formedness, issuing any diagnostics required. Returns true if /// the constructor declarator is invalid. void Sema::CheckConstructor(CXXConstructorDecl *Constructor) { - CXXRecordDecl *ClassDecl + CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Constructor->getDeclContext()); if (!ClassDecl) return Constructor->setInvalidDecl(); @@ -1997,8 +1996,8 @@ void Sema::CheckConstructor(CXXConstructorDecl *Constructor) { // either there are no other parameters or else all other // parameters have default arguments. if (!Constructor->isInvalidDecl() && - ((Constructor->getNumParams() == 1) || - (Constructor->getNumParams() > 1 && + ((Constructor->getNumParams() == 1) || + (Constructor->getNumParams() > 1 && Constructor->getParamDecl(1)->hasDefaultArg()))) { QualType ParamType = Constructor->getParamDecl(0)->getType(); QualType ClassTy = Context.getTagDeclType(ClassDecl); @@ -2009,12 +2008,12 @@ void Sema::CheckConstructor(CXXConstructorDecl *Constructor) { Constructor->setInvalidDecl(); } } - + // Notify the class that we've added a constructor. ClassDecl->addedConstructor(Context, Constructor); } -static inline bool +static inline bool FTIHasSingleVoidArgument(DeclaratorChunk::FunctionTypeInfo &FTI) { return (FTI.NumArgs == 1 && !FTI.isVariadic && FTI.ArgInfo[0].Ident == 0 && FTI.ArgInfo[0].Param && @@ -2070,7 +2069,7 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D, << SourceRange(D.getDeclSpec().getTypeSpecTypeLoc()) << SourceRange(D.getIdentifierLoc()); } - + DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun; if (FTI.TypeQuals != 0 && !D.isInvalidType()) { if (FTI.TypeQuals & QualType::Const) @@ -2094,7 +2093,7 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D, D.setInvalidType(); } - // Make sure the destructor isn't variadic. + // Make sure the destructor isn't variadic. if (FTI.isVariadic) { Diag(D.getIdentifierLoc(), diag::err_destructor_variadic); D.setInvalidType(); @@ -2119,7 +2118,7 @@ void Sema::CheckConversionDeclarator(Declarator &D, QualType &R, // C++ [class.conv.fct]p1: // Neither parameter types nor return type can be specified. The // type of a conversion function (8.3.5) is "function taking no - // parameter returning conversion-type-id." + // parameter returning conversion-type-id." if (SC == FunctionDecl::Static) { if (!D.isInvalidType()) Diag(D.getIdentifierLoc(), diag::err_conv_function_not_member) @@ -2151,7 +2150,7 @@ void Sema::CheckConversionDeclarator(Declarator &D, QualType &R, D.setInvalidType(); } - // Make sure the conversion function isn't variadic. + // Make sure the conversion function isn't variadic. if (R->getAsFunctionProtoType()->isVariadic() && !D.isInvalidType()) { Diag(D.getIdentifierLoc(), diag::err_conv_function_variadic); D.setInvalidType(); @@ -2173,13 +2172,13 @@ void Sema::CheckConversionDeclarator(Declarator &D, QualType &R, // Rebuild the function type "R" without any parameters (in case any // of the errors above fired) and with the conversion type as the - // return type. - R = Context.getFunctionType(ConvType, 0, 0, false, + // return type. + R = Context.getFunctionType(ConvType, 0, 0, false, R->getAsFunctionProtoType()->getTypeQuals()); // C++0x explicit conversion operators. if (D.getDeclSpec().isExplicitSpecified() && !getLangOptions().CPlusPlus0x) - Diag(D.getDeclSpec().getExplicitSpecLoc(), + Diag(D.getDeclSpec().getExplicitSpecLoc(), diag::warn_explicit_conversion_functions) << SourceRange(D.getDeclSpec().getExplicitSpecLoc()); } @@ -2204,7 +2203,7 @@ Sema::DeclPtrTy Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) { // or to (possibly cv-qualified) void. // FIXME: Suppress this warning if the conversion function ends up being a // virtual function that overrides a virtual function in a base class. - QualType ClassType + QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType(ClassDecl)); if (const ReferenceType *ConvTypeRef = ConvType->getAs<ReferenceType>()) ConvType = ConvTypeRef->getPointeeType(); @@ -2223,11 +2222,11 @@ Sema::DeclPtrTy Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) { if (Conversion->getPreviousDeclaration()) { const NamedDecl *ExpectedPrevDecl = Conversion->getPreviousDeclaration(); - if (FunctionTemplateDecl *ConversionTemplate + if (FunctionTemplateDecl *ConversionTemplate = Conversion->getDescribedFunctionTemplate()) ExpectedPrevDecl = ConversionTemplate->getPreviousDeclaration(); OverloadedFunctionDecl *Conversions = ClassDecl->getConversionFunctions(); - for (OverloadedFunctionDecl::function_iterator + for (OverloadedFunctionDecl::function_iterator Conv = Conversions->function_begin(), ConvEnd = Conversions->function_end(); Conv != ConvEnd; ++Conv) { @@ -2237,7 +2236,7 @@ Sema::DeclPtrTy Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) { } } assert(Conversion->isInvalidDecl() && "Conversion should not get here."); - } else if (FunctionTemplateDecl *ConversionTemplate + } else if (FunctionTemplateDecl *ConversionTemplate = Conversion->getDescribedFunctionTemplate()) ClassDecl->addConversionFunction(Context, ConversionTemplate); else if (!Conversion->getPrimaryTemplate()) // ignore specializations @@ -2272,7 +2271,7 @@ Sema::DeclPtrTy Sema::ActOnStartNamespaceDef(Scope *NamespcScope, NamedDecl *PrevDecl = LookupName(DeclRegionScope, II, LookupOrdinaryName, true); - + if (NamespaceDecl *OrigNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl)) { // This is an extended namespace definition. // Attach this namespace decl to the chain of extended namespace @@ -2280,7 +2279,7 @@ Sema::DeclPtrTy Sema::ActOnStartNamespaceDef(Scope *NamespcScope, OrigNS->setNextNamespace(Namespc); Namespc->setOriginalNamespace(OrigNS->getOriginalNamespace()); - // Remove the previous declaration from the scope. + // Remove the previous declaration from the scope. if (DeclRegionScope->isDeclScope(DeclPtrTy::make(OrigNS))) { IdResolver.RemoveDecl(OrigNS); DeclRegionScope->RemoveDecl(DeclPtrTy::make(OrigNS)); @@ -2292,7 +2291,7 @@ Sema::DeclPtrTy Sema::ActOnStartNamespaceDef(Scope *NamespcScope, Diag(PrevDecl->getLocation(), diag::note_previous_definition); Namespc->setInvalidDecl(); // Continue on to push Namespc as current DeclContext and return it. - } + } PushOnScopeChains(Namespc, DeclRegionScope); } else { @@ -2357,9 +2356,9 @@ Sema::DeclPtrTy Sema::ActOnUsingDirective(Scope *S, while (CommonAncestor && !CommonAncestor->Encloses(CurContext)) CommonAncestor = CommonAncestor->getParent(); - UDir = UsingDirectiveDecl::Create(Context, + UDir = UsingDirectiveDecl::Create(Context, CurContext, UsingLoc, - NamespcLoc, + NamespcLoc, SS.getRange(), (NestedNameSpecifier *)SS.getScopeRep(), IdentLoc, @@ -2399,20 +2398,20 @@ Sema::DeclPtrTy Sema::ActOnUsingDeclaration(Scope *S, bool IsTypeName) { assert((TargetName || Op) && "Invalid TargetName."); assert(S->getFlags() & Scope::DeclScope && "Invalid Scope."); - + DeclarationName Name; if (TargetName) Name = TargetName; else Name = Context.DeclarationNames.getCXXOperatorName(Op); - - NamedDecl *UD = BuildUsingDeclaration(UsingLoc, SS, IdentLoc, + + NamedDecl *UD = BuildUsingDeclaration(UsingLoc, SS, IdentLoc, Name, AttrList, IsTypeName); if (UD) { PushOnScopeChains(UD, S); UD->setAccess(AS); } - + return DeclPtrTy::make(UD); } @@ -2427,13 +2426,13 @@ NamedDecl *Sema::BuildUsingDeclaration(SourceLocation UsingLoc, // FIXME: We ignore attributes for now. delete AttrList; - + if (SS.isEmpty()) { Diag(IdentLoc, diag::err_using_requires_qualname); return 0; } - - NestedNameSpecifier *NNS = + + NestedNameSpecifier *NNS = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); if (isUnknownSpecialization(SS)) { @@ -2441,15 +2440,15 @@ NamedDecl *Sema::BuildUsingDeclaration(SourceLocation UsingLoc, SS.getRange(), NNS, IdentLoc, Name, IsTypeName); } - + DeclContext *LookupContext = 0; - + if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(CurContext)) { // C++0x N2914 [namespace.udecl]p3: // A using-declaration used as a member-declaration shall refer to a member // of a base class of the class being defined, shall refer to a member of an // anonymous union that is a member of a base class of the class being - // defined, or shall refer to an enumerator for an enumeration type that is + // defined, or shall refer to an enumerator for an enumeration type that is // a member of a base class of the class being defined. const Type *Ty = NNS->getAsType(); if (!Ty || !IsDerivedFrom(Context.getTagDeclType(RD), QualType(Ty, 0))) { @@ -2469,7 +2468,7 @@ NamedDecl *Sema::BuildUsingDeclaration(SourceLocation UsingLoc, << SS.getRange(); return 0; } - + // C++0x N2914 [namespace.udecl]p9: // In a using-declaration, a prefix :: refers to the global namespace. if (NNS->getKind() == NestedNameSpecifier::Global) @@ -2480,16 +2479,16 @@ NamedDecl *Sema::BuildUsingDeclaration(SourceLocation UsingLoc, // Lookup target name. - LookupResult R = LookupQualifiedName(LookupContext, + LookupResult R = LookupQualifiedName(LookupContext, Name, LookupOrdinaryName); - + if (!R) { DiagnoseMissingMember(IdentLoc, Name, NNS, SS.getRange()); return 0; } NamedDecl *ND = R.getAsDecl(); - + if (IsTypeName && !isa<TypeDecl>(ND)) { Diag(IdentLoc, diag::err_using_typename_non_type); return 0; @@ -2502,7 +2501,7 @@ NamedDecl *Sema::BuildUsingDeclaration(SourceLocation UsingLoc, << SS.getRange(); return 0; } - + return UsingDecl::Create(Context, CurContext, IdentLoc, SS.getRange(), ND->getLocation(), UsingLoc, ND, NNS, IsTypeName); } @@ -2515,26 +2514,26 @@ static inline NamespaceDecl *getNamespaceDecl(NamedDecl *D) { return dyn_cast_or_null<NamespaceDecl>(D); } -Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S, +Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S, SourceLocation NamespaceLoc, SourceLocation AliasLoc, IdentifierInfo *Alias, const CXXScopeSpec &SS, SourceLocation IdentLoc, IdentifierInfo *Ident) { - + // Lookup the namespace name. LookupResult R = LookupParsedName(S, &SS, Ident, LookupNamespaceName, false); // Check if we have a previous declaration with the same name. if (NamedDecl *PrevDecl = LookupName(S, Alias, LookupOrdinaryName, true)) { if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(PrevDecl)) { - // We already have an alias with the same name that points to the same + // We already have an alias with the same name that points to the same // namespace, so don't create a new one. if (!R.isAmbiguous() && AD->getNamespace() == getNamespaceDecl(R)) return DeclPtrTy(); } - + unsigned DiagID = isa<NamespaceDecl>(PrevDecl) ? diag::err_redefinition : diag::err_redefinition_different_kind; Diag(AliasLoc, DiagID) << Alias; @@ -2546,18 +2545,18 @@ Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S, DiagnoseAmbiguousLookup(R, Ident, IdentLoc); return DeclPtrTy(); } - + if (!R) { Diag(NamespaceLoc, diag::err_expected_namespace_name) << SS.getRange(); return DeclPtrTy(); } - + NamespaceAliasDecl *AliasDecl = - NamespaceAliasDecl::Create(Context, CurContext, NamespaceLoc, AliasLoc, - Alias, SS.getRange(), + NamespaceAliasDecl::Create(Context, CurContext, NamespaceLoc, AliasLoc, + Alias, SS.getRange(), (NestedNameSpecifier *)SS.getScopeRep(), IdentLoc, R); - + CurContext->addDecl(AliasDecl); return DeclPtrTy::make(AliasDecl); } @@ -2567,11 +2566,11 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, assert((Constructor->isImplicit() && Constructor->isDefaultConstructor() && !Constructor->isUsed()) && "DefineImplicitDefaultConstructor - call it for implicit default ctor"); - + CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Constructor->getDeclContext()); assert(ClassDecl && "DefineImplicitDefaultConstructor - invalid constructor"); - // Before the implicitly-declared default constructor for a class is + // Before the implicitly-declared default constructor for a class is // implicitly defined, all the implicitly-declared default constructors // for its base class and its non-static data members shall have been // implicitly defined. @@ -2581,14 +2580,14 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); if (!BaseClassDecl->hasTrivialConstructor()) { - if (CXXConstructorDecl *BaseCtor = + if (CXXConstructorDecl *BaseCtor = BaseClassDecl->getDefaultConstructor(Context)) MarkDeclarationReferenced(CurrentLocation, BaseCtor); else { - Diag(CurrentLocation, diag::err_defining_default_ctor) - << Context.getTagDeclType(ClassDecl) << 1 + Diag(CurrentLocation, diag::err_defining_default_ctor) + << Context.getTagDeclType(ClassDecl) << 1 << Context.getTagDeclType(BaseClassDecl); - Diag(BaseClassDecl->getLocation(), diag::note_previous_class_decl) + Diag(BaseClassDecl->getLocation(), diag::note_previous_class_decl) << Context.getTagDeclType(BaseClassDecl); err = true; } @@ -2603,25 +2602,25 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(FieldClassType->getDecl()); if (!FieldClassDecl->hasTrivialConstructor()) { - if (CXXConstructorDecl *FieldCtor = + if (CXXConstructorDecl *FieldCtor = FieldClassDecl->getDefaultConstructor(Context)) MarkDeclarationReferenced(CurrentLocation, FieldCtor); else { - Diag(CurrentLocation, diag::err_defining_default_ctor) + Diag(CurrentLocation, diag::err_defining_default_ctor) << Context.getTagDeclType(ClassDecl) << 0 << Context.getTagDeclType(FieldClassDecl); - Diag(FieldClassDecl->getLocation(), diag::note_previous_class_decl) + Diag(FieldClassDecl->getLocation(), diag::note_previous_class_decl) << Context.getTagDeclType(FieldClassDecl); err = true; } } } else if (FieldType->isReferenceType()) { - Diag(CurrentLocation, diag::err_unintialized_member) + Diag(CurrentLocation, diag::err_unintialized_member) << Context.getTagDeclType(ClassDecl) << 0 << Field->getDeclName(); Diag((*Field)->getLocation(), diag::note_declared_at); err = true; } else if (FieldType.isConstQualified()) { - Diag(CurrentLocation, diag::err_unintialized_member) + Diag(CurrentLocation, diag::err_unintialized_member) << Context.getTagDeclType(ClassDecl) << 1 << Field->getDeclName(); Diag((*Field)->getLocation(), diag::note_declared_at); err = true; @@ -2637,12 +2636,12 @@ void Sema::DefineImplicitDestructor(SourceLocation CurrentLocation, CXXDestructorDecl *Destructor) { assert((Destructor->isImplicit() && !Destructor->isUsed()) && "DefineImplicitDestructor - call it for implicit default dtor"); - + CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Destructor->getDeclContext()); assert(ClassDecl && "DefineImplicitDestructor - invalid destructor"); // C++ [class.dtor] p5 - // Before the implicitly-declared default destructor for a class is + // Before the implicitly-declared default destructor for a class is // implicitly defined, all the implicitly-declared default destructors // for its base class and its non-static data members shall have been // implicitly defined. @@ -2651,15 +2650,15 @@ void Sema::DefineImplicitDestructor(SourceLocation CurrentLocation, CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); if (!BaseClassDecl->hasTrivialDestructor()) { - if (CXXDestructorDecl *BaseDtor = + if (CXXDestructorDecl *BaseDtor = const_cast<CXXDestructorDecl*>(BaseClassDecl->getDestructor(Context))) MarkDeclarationReferenced(CurrentLocation, BaseDtor); else - assert(false && + assert(false && "DefineImplicitDestructor - missing dtor in a base class"); } } - + for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), E = ClassDecl->field_end(); Field != E; ++Field) { QualType FieldType = Context.getCanonicalType((*Field)->getType()); @@ -2669,12 +2668,12 @@ void Sema::DefineImplicitDestructor(SourceLocation CurrentLocation, CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(FieldClassType->getDecl()); if (!FieldClassDecl->hasTrivialDestructor()) { - if (CXXDestructorDecl *FieldDtor = + if (CXXDestructorDecl *FieldDtor = const_cast<CXXDestructorDecl*>( FieldClassDecl->getDestructor(Context))) MarkDeclarationReferenced(CurrentLocation, FieldDtor); else - assert(false && + assert(false && "DefineImplicitDestructor - missing dtor in class of a data member"); } } @@ -2688,10 +2687,10 @@ void Sema::DefineImplicitOverloadedAssign(SourceLocation CurrentLocation, MethodDecl->getOverloadedOperator() == OO_Equal && !MethodDecl->isUsed()) && "DefineImplicitOverloadedAssign - call it for implicit assignment op"); - + CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(MethodDecl->getDeclContext()); - + // C++[class.copy] p12 // Before the implicitly-declared copy assignment operator for a class is // implicitly defined, all implicitly-declared copy assignment operators @@ -2702,7 +2701,7 @@ void Sema::DefineImplicitOverloadedAssign(SourceLocation CurrentLocation, E = ClassDecl->bases_end(); Base != E; ++Base) { CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); - if (CXXMethodDecl *BaseAssignOpMethod = + if (CXXMethodDecl *BaseAssignOpMethod = getAssignOperatorMethod(MethodDecl->getParamDecl(0), BaseClassDecl)) MarkDeclarationReferenced(CurrentLocation, BaseAssignOpMethod); } @@ -2714,17 +2713,17 @@ void Sema::DefineImplicitOverloadedAssign(SourceLocation CurrentLocation, if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) { CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(FieldClassType->getDecl()); - if (CXXMethodDecl *FieldAssignOpMethod = + if (CXXMethodDecl *FieldAssignOpMethod = getAssignOperatorMethod(MethodDecl->getParamDecl(0), FieldClassDecl)) MarkDeclarationReferenced(CurrentLocation, FieldAssignOpMethod); } else if (FieldType->isReferenceType()) { - Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign) + Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign) << Context.getTagDeclType(ClassDecl) << 0 << Field->getDeclName(); Diag(Field->getLocation(), diag::note_declared_at); Diag(CurrentLocation, diag::note_first_required_here); err = true; } else if (FieldType.isConstQualified()) { - Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign) + Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign) << Context.getTagDeclType(ClassDecl) << 1 << Field->getDeclName(); Diag(Field->getLocation(), diag::note_declared_at); Diag(CurrentLocation, diag::note_first_required_here); @@ -2732,7 +2731,7 @@ void Sema::DefineImplicitOverloadedAssign(SourceLocation CurrentLocation, } } if (!err) - MethodDecl->setUsed(); + MethodDecl->setUsed(); } CXXMethodDecl * @@ -2741,24 +2740,24 @@ Sema::getAssignOperatorMethod(ParmVarDecl *ParmDecl, QualType LHSType = Context.getTypeDeclType(ClassDecl); QualType RHSType(LHSType); // If class's assignment operator argument is const/volatile qualified, - // look for operator = (const/volatile B&). Otherwise, look for + // look for operator = (const/volatile B&). Otherwise, look for // operator = (B&). if (ParmDecl->getType().isConstQualified()) RHSType.addConst(); if (ParmDecl->getType().isVolatileQualified()) RHSType.addVolatile(); - ExprOwningPtr<Expr> LHS(this, new (Context) DeclRefExpr(ParmDecl, - LHSType, + ExprOwningPtr<Expr> LHS(this, new (Context) DeclRefExpr(ParmDecl, + LHSType, SourceLocation())); - ExprOwningPtr<Expr> RHS(this, new (Context) DeclRefExpr(ParmDecl, - RHSType, + ExprOwningPtr<Expr> RHS(this, new (Context) DeclRefExpr(ParmDecl, + RHSType, SourceLocation())); Expr *Args[2] = { &*LHS, &*RHS }; OverloadCandidateSet CandidateSet; - AddMemberOperatorCandidates(clang::OO_Equal, SourceLocation(), Args, 2, + AddMemberOperatorCandidates(clang::OO_Equal, SourceLocation(), Args, 2, CandidateSet); OverloadCandidateSet::iterator Best; - if (BestViableFunction(CandidateSet, + if (BestViableFunction(CandidateSet, ClassDecl->getLocation(), Best) == OR_Success) return cast<CXXMethodDecl>(Best->Function); assert(false && @@ -2769,16 +2768,16 @@ Sema::getAssignOperatorMethod(ParmVarDecl *ParmDecl, void Sema::DefineImplicitCopyConstructor(SourceLocation CurrentLocation, CXXConstructorDecl *CopyConstructor, unsigned TypeQuals) { - assert((CopyConstructor->isImplicit() && + assert((CopyConstructor->isImplicit() && CopyConstructor->isCopyConstructor(Context, TypeQuals) && !CopyConstructor->isUsed()) && "DefineImplicitCopyConstructor - call it for implicit copy ctor"); - + CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(CopyConstructor->getDeclContext()); assert(ClassDecl && "DefineImplicitCopyConstructor - invalid constructor"); // C++ [class.copy] p209 - // Before the implicitly-declared copy constructor for a class is + // Before the implicitly-declared copy constructor for a class is // implicitly defined, all the implicitly-declared copy constructors // for its base class and its non-static data members shall have been // implicitly defined. @@ -2786,7 +2785,7 @@ void Sema::DefineImplicitCopyConstructor(SourceLocation CurrentLocation, Base != ClassDecl->bases_end(); ++Base) { CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); - if (CXXConstructorDecl *BaseCopyCtor = + if (CXXConstructorDecl *BaseCopyCtor = BaseClassDecl->getCopyConstructor(Context, TypeQuals)) MarkDeclarationReferenced(CurrentLocation, BaseCopyCtor); } @@ -2799,7 +2798,7 @@ void Sema::DefineImplicitCopyConstructor(SourceLocation CurrentLocation, if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) { CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(FieldClassType->getDecl()); - if (CXXConstructorDecl *FieldCopyCtor = + if (CXXConstructorDecl *FieldCopyCtor = FieldClassDecl->getCopyConstructor(Context, TypeQuals)) MarkDeclarationReferenced(CurrentLocation, FieldCopyCtor); } @@ -2809,28 +2808,28 @@ void Sema::DefineImplicitCopyConstructor(SourceLocation CurrentLocation, Sema::OwningExprResult Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, - CXXConstructorDecl *Constructor, + CXXConstructorDecl *Constructor, MultiExprArg ExprArgs) { bool Elidable = false; - + // [class.copy]p15: - // Whenever a temporary class object is copied using a copy constructor, and - // this object and the copy have the same cv-unqualified type, an + // Whenever a temporary class object is copied using a copy constructor, and + // this object and the copy have the same cv-unqualified type, an // implementation is permitted to treat the original and the copy as two // different ways of referring to the same object and not perform a copy at //all, even if the class copy constructor or destructor have side effects. - + // FIXME: Is this enough? if (Constructor->isCopyConstructor(Context) && ExprArgs.size() == 1) { Expr *E = ((Expr **)ExprArgs.get())[0]; while (CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) E = BE->getSubExpr(); - + if (isa<CallExpr>(E) || isa<CXXTemporaryObjectExpr>(E)) Elidable = true; } - - return BuildCXXConstructExpr(ConstructLoc, DeclInitType, Constructor, + + return BuildCXXConstructExpr(ConstructLoc, DeclInitType, Constructor, Elidable, move(ExprArgs)); } @@ -2839,52 +2838,52 @@ CheckConstructArgumentTypes(Sema &SemaRef, SourceLocation ConstructLoc, CXXConstructExpr *E) { CXXConstructorDecl *Ctor = E->getConstructor(); const FunctionProtoType *Proto = Ctor->getType()->getAsFunctionProtoType(); - + unsigned NumArgs = E->getNumArgs(); unsigned NumArgsInProto = Proto->getNumArgs(); unsigned NumRequiredArgs = Ctor->getMinRequiredArguments(); - + for (unsigned i = 0; i != NumArgsInProto; ++i) { QualType ProtoArgType = Proto->getArgType(i); Expr *Arg; - + if (i < NumRequiredArgs) { Arg = E->getArg(i); - + // Pass the argument. // FIXME: Do this. } else { // Build a default argument. ParmVarDecl *Param = Ctor->getParamDecl(i); - - Sema::OwningExprResult ArgExpr = + + Sema::OwningExprResult ArgExpr = SemaRef.BuildCXXDefaultArgExpr(ConstructLoc, Ctor, Param); if (ArgExpr.isInvalid()) return true; Arg = ArgExpr.takeAs<Expr>(); } - + E->setArg(i, Arg); } // If this is a variadic call, handle args passed through "...". if (Proto->isVariadic()) { bool Invalid = false; - + // Promote the arguments (C99 6.5.2.2p7). for (unsigned i = NumArgsInProto; i != NumArgs; i++) { Expr *Arg = E->getArg(i); - Invalid |= - SemaRef.DefaultVariadicArgumentPromotion(Arg, + Invalid |= + SemaRef.DefaultVariadicArgumentPromotion(Arg, Sema::VariadicConstructor); E->setArg(i, Arg); } - + return Invalid; } - + return false; } @@ -2896,15 +2895,15 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, MultiExprArg ExprArgs) { unsigned NumExprs = ExprArgs.size(); Expr **Exprs = (Expr **)ExprArgs.release(); - - ExprOwningPtr<CXXConstructExpr> Temp(this, - CXXConstructExpr::Create(Context, - DeclInitType, - Constructor, + + ExprOwningPtr<CXXConstructExpr> Temp(this, + CXXConstructExpr::Create(Context, + DeclInitType, + Constructor, Elidable, Exprs, NumExprs)); - + if (CheckConstructArgumentTypes(*this, ConstructLoc, Temp.get())) return ExprError(); @@ -2912,16 +2911,16 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, } Sema::OwningExprResult -Sema::BuildCXXTemporaryObjectExpr(CXXConstructorDecl *Constructor, - QualType Ty, - SourceLocation TyBeginLoc, +Sema::BuildCXXTemporaryObjectExpr(CXXConstructorDecl *Constructor, + QualType Ty, + SourceLocation TyBeginLoc, MultiExprArg Args, SourceLocation RParenLoc) { - CXXTemporaryObjectExpr *E - = new (Context) CXXTemporaryObjectExpr(Context, Constructor, Ty, TyBeginLoc, + CXXTemporaryObjectExpr *E + = new (Context) CXXTemporaryObjectExpr(Context, Constructor, Ty, TyBeginLoc, (Expr **)Args.get(), Args.size(), RParenLoc); - + ExprOwningPtr<CXXTemporaryObjectExpr> Temp(this, E); if (CheckConstructArgumentTypes(*this, TyBeginLoc, Temp.get())) @@ -2931,35 +2930,34 @@ Sema::BuildCXXTemporaryObjectExpr(CXXConstructorDecl *Constructor, } -bool Sema::InitializeVarWithConstructor(VarDecl *VD, +bool Sema::InitializeVarWithConstructor(VarDecl *VD, CXXConstructorDecl *Constructor, - QualType DeclInitType, + QualType DeclInitType, MultiExprArg Exprs) { - OwningExprResult TempResult = - BuildCXXConstructExpr(VD->getLocation(), DeclInitType, Constructor, + OwningExprResult TempResult = + BuildCXXConstructExpr(VD->getLocation(), DeclInitType, Constructor, move(Exprs)); if (TempResult.isInvalid()) return true; - + Expr *Temp = TempResult.takeAs<Expr>(); MarkDeclarationReferenced(VD->getLocation(), Constructor); Temp = MaybeCreateCXXExprWithTemporaries(Temp, /*DestroyTemps=*/true); VD->setInit(Context, Temp); - + return false; } -void Sema::FinalizeVarWithDestructor(VarDecl *VD, QualType DeclInitType) -{ +void Sema::FinalizeVarWithDestructor(VarDecl *VD, QualType DeclInitType) { CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>( DeclInitType->getAs<RecordType>()->getDecl()); if (!ClassDecl->hasTrivialDestructor()) - if (CXXDestructorDecl *Destructor = + if (CXXDestructorDecl *Destructor = const_cast<CXXDestructorDecl*>(ClassDecl->getDestructor(Context))) MarkDeclarationReferenced(VD->getLocation(), Destructor); } -/// AddCXXDirectInitializerToDecl - This action is called immediately after +/// AddCXXDirectInitializerToDecl - This action is called immediately after /// ActOnDeclarator, when a C++ direct initializer is present. /// e.g: "int x(1);" void Sema::AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, @@ -2975,7 +2973,7 @@ void Sema::AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, // the initializer. if (RealDecl == 0) return; - + VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl); if (!VDecl) { Diag(RealDecl->getLocation(), diag::err_illegal_initializer); @@ -3000,16 +2998,16 @@ void Sema::AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, Expr::hasAnyTypeDependentArguments((Expr **)Exprs.get(), Exprs.size())) { // Let clients know that initialization was done with a direct initializer. VDecl->setCXXDirectInitializer(true); - + // Store the initialization expressions as a ParenListExpr. unsigned NumExprs = Exprs.size(); - VDecl->setInit(Context, + VDecl->setInit(Context, new (Context) ParenListExpr(Context, LParenLoc, (Expr **)Exprs.release(), NumExprs, RParenLoc)); return; } - + // C++ 8.5p11: // The form of initialization (using parentheses or '=') is generally @@ -3039,7 +3037,7 @@ void Sema::AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, RealDecl->setInvalidDecl(); else { VDecl->setCXXDirectInitializer(true); - if (InitializeVarWithConstructor(VDecl, Constructor, DeclInitType, + if (InitializeVarWithConstructor(VDecl, Constructor, DeclInitType, move(Exprs))) RealDecl->setInvalidDecl(); FinalizeVarWithDestructor(VDecl, DeclInitType); @@ -3086,7 +3084,7 @@ Sema::PerformInitializationByConstructor(QualType ClassType, const RecordType *ClassRec = ClassType->getAs<RecordType>(); assert(ClassRec && "Can only initialize a class type here"); - // C++ [dcl.init]p14: + // C++ [dcl.init]p14: // // If the initialization is direct-initialization, or if it is // copy-initialization where the cv-unqualified version of the @@ -3102,7 +3100,7 @@ Sema::PerformInitializationByConstructor(QualType ClassType, OverloadCandidateSet CandidateSet; // Add constructors to the overload set. - DeclarationName ConstructorName + DeclarationName ConstructorName = Context.DeclarationNames.getCXXConstructorName( Context.getCanonicalType(ClassType.getUnqualifiedType())); DeclContext::lookup_const_iterator Con, ConEnd; @@ -3112,17 +3110,17 @@ Sema::PerformInitializationByConstructor(QualType ClassType, CXXConstructorDecl *Constructor = 0; FunctionTemplateDecl *ConstructorTmpl= dyn_cast<FunctionTemplateDecl>(*Con); if (ConstructorTmpl) - Constructor + Constructor = cast<CXXConstructorDecl>(ConstructorTmpl->getTemplatedDecl()); else Constructor = cast<CXXConstructorDecl>(*Con); if ((Kind == IK_Direct) || - (Kind == IK_Copy && + (Kind == IK_Copy && Constructor->isConvertingConstructor(/*AllowExplicit=*/false)) || (Kind == IK_Default && Constructor->isDefaultConstructor())) { if (ConstructorTmpl) - AddTemplateOverloadCandidate(ConstructorTmpl, false, 0, 0, + AddTemplateOverloadCandidate(ConstructorTmpl, false, 0, 0, Args, NumArgs, CandidateSet); else AddOverloadCandidate(Constructor, Args, NumArgs, CandidateSet); @@ -3137,7 +3135,7 @@ Sema::PerformInitializationByConstructor(QualType ClassType, case OR_Success: // We found a constructor. Return it. return cast<CXXConstructorDecl>(Best->Function); - + case OR_No_Viable_Function: if (InitEntity) Diag(Loc, diag::err_ovl_no_viable_function_in_init) @@ -3147,7 +3145,7 @@ Sema::PerformInitializationByConstructor(QualType ClassType, << ClassType << Range; PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false); return 0; - + case OR_Ambiguous: if (InitEntity) Diag(Loc, diag::err_ovl_ambiguous_init) << InitEntity << Range; @@ -3168,7 +3166,7 @@ Sema::PerformInitializationByConstructor(QualType ClassType, PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/true); return 0; } - + return 0; } @@ -3179,8 +3177,8 @@ Sema::PerformInitializationByConstructor(QualType ClassType, /// reference (C++ [dcl.ref.init]p4). Neither type can be a reference /// type, and the first type (T1) is the pointee type of the reference /// type being initialized. -Sema::ReferenceCompareResult -Sema::CompareReferenceRelationship(QualType T1, QualType T2, +Sema::ReferenceCompareResult +Sema::CompareReferenceRelationship(QualType T1, QualType T2, bool& DerivedToBase) { assert(!T1->isReferenceType() && "T1 must be the pointee type of the reference type"); @@ -3193,7 +3191,7 @@ Sema::CompareReferenceRelationship(QualType T1, QualType T2, // C++ [dcl.init.ref]p4: // Given types "cv1 T1" and "cv2 T2," "cv1 T1" is - // reference-related to "cv2 T2" if T1 is the same type as T2, or + // reference-related to "cv2 T2" if T1 is the same type as T2, or // T1 is a base class of T2. if (UnqualT1 == UnqualT2) DerivedToBase = false; @@ -3236,7 +3234,7 @@ Sema::CompareReferenceRelationship(QualType T1, QualType T2, /// When @p AllowExplicit, we also permit explicit user-defined /// conversion functions. /// When @p ForceRValue, we unconditionally treat the initializer as an rvalue. -bool +bool Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, bool SuppressUserConversions, bool AllowExplicit, bool ForceRValue, @@ -3250,7 +3248,7 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, // to resolve the overloaded function. If all goes well, T2 is the // type of the resulting function. if (Context.getCanonicalType(T2) == Context.OverloadTy) { - FunctionDecl *Fn = ResolveAddressOfOverloadedFunction(Init, DeclType, + FunctionDecl *Fn = ResolveAddressOfOverloadedFunction(Init, DeclType, ICS != 0); if (Fn) { // Since we're performing this reference-initialization for @@ -3271,7 +3269,7 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, bool DerivedToBase = false; Expr::isLvalueResult InitLvalue = ForceRValue ? Expr::LV_InvalidExpression : Init->isLvalue(Context); - ReferenceCompareResult RefRelationship + ReferenceCompareResult RefRelationship = CompareReferenceRelationship(T1, T2, DerivedToBase); // Most paths end in a failed conversion. @@ -3334,7 +3332,7 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, // Perform the conversion. // FIXME: Binding to a subobject of the lvalue is going to require more // AST annotation than this. - ImpCastExprToType(Init, T1, CastExpr::CK_Unknown, /*isLvalue=*/true); + ImpCastExprToType(Init, T1, CastExpr::CK_Unknown, /*isLvalue=*/true); } } @@ -3347,16 +3345,16 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, if (!isRValRef && !SuppressUserConversions && T2->isRecordType() && !RequireCompleteType(SourceLocation(), T2, 0)) { // FIXME: Look for conversions in base classes! - CXXRecordDecl *T2RecordDecl + CXXRecordDecl *T2RecordDecl = dyn_cast<CXXRecordDecl>(T2->getAs<RecordType>()->getDecl()); OverloadCandidateSet CandidateSet; - OverloadedFunctionDecl *Conversions + OverloadedFunctionDecl *Conversions = T2RecordDecl->getConversionFunctions(); - for (OverloadedFunctionDecl::function_iterator Func + for (OverloadedFunctionDecl::function_iterator Func = Conversions->function_begin(); Func != Conversions->function_end(); ++Func) { - FunctionTemplateDecl *ConvTemplate + FunctionTemplateDecl *ConvTemplate = dyn_cast<FunctionTemplateDecl>(*Func); CXXConversionDecl *Conv; if (ConvTemplate) @@ -3369,7 +3367,7 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, if (Conv->getConversionType()->isLValueReferenceType() && (AllowExplicit || !Conv->isExplicit())) { if (ConvTemplate) - AddTemplateConversionCandidate(ConvTemplate, Init, DeclType, + AddTemplateConversionCandidate(ConvTemplate, Init, DeclType, CandidateSet); else AddConversionCandidate(Conv, Init, DeclType, CandidateSet); @@ -3412,7 +3410,7 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, case OR_Ambiguous: assert(false && "Ambiguous reference binding conversions not implemented."); return true; - + case OR_No_Viable_Function: case OR_Deleted: // There was no suitable conversion, or we found a deleted @@ -3420,7 +3418,7 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, break; } } - + if (BindsDirectly) { // C++ [dcl.init.ref]p4: // [...] In all cases where the reference-related or @@ -3434,8 +3432,8 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, // complain about errors, because we should not be checking for // ambiguity (or inaccessibility) unless the reference binding // actually happens. - if (DerivedToBase) - return CheckDerivedToBaseConversion(T2, T1, + if (DerivedToBase) + return CheckDerivedToBaseConversion(T2, T1, Init->getSourceRange().getBegin(), Init->getSourceRange()); else @@ -3535,7 +3533,7 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, // Actually try to convert the initializer to T1. if (ICS) { // C++ [over.ics.ref]p2: - // + // // When a parameter of reference type is not bound directly to // an argument expression, the conversion sequence is the one // required to convert the argument expression to the @@ -3549,12 +3547,12 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, /*AllowExplicit=*/false, /*ForceRValue=*/false, /*InOverloadResolution=*/false); - + // Of course, that's still a reference binding. if (ICS->ConversionKind == ImplicitConversionSequence::StandardConversion) { ICS->Standard.ReferenceBinding = true; ICS->Standard.RRefBinding = isRValRef; - } else if(ICS->ConversionKind == + } else if (ICS->ConversionKind == ImplicitConversionSequence::UserDefinedConversion) { ICS->UserDefined.After.ReferenceBinding = true; ICS->UserDefined.After.RRefBinding = isRValRef; @@ -3574,7 +3572,7 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) { OverloadedOperatorKind Op = FnDecl->getOverloadedOperator(); - // C++ [over.oper]p5: + // C++ [over.oper]p5: // The allocation and deallocation functions, operator new, // operator new[], operator delete and operator delete[], are // described completely in 3.7.3. The attributes and restrictions @@ -3617,13 +3615,13 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) { // An operator function cannot have default arguments (8.3.6), // except where explicitly stated below. // - // Only the function-call operator allows default arguments + // Only the function-call operator allows default arguments // (C++ [over.call]p1). if (Op != OO_Call) { for (FunctionDecl::param_iterator Param = FnDecl->param_begin(); Param != FnDecl->param_end(); ++Param) { if ((*Param)->hasUnparsedDefaultArg()) - return Diag((*Param)->getLocation(), + return Diag((*Param)->getLocation(), diag::err_operator_overload_default_arg) << FnDecl->getDeclName(); else if (Expr *DefArg = (*Param)->getDefaultArg()) @@ -3648,7 +3646,7 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) { // [...] Operator functions cannot have more or fewer parameters // than the number required for the corresponding operator, as // described in the rest of this subclause. - unsigned NumParams = FnDecl->getNumParams() + unsigned NumParams = FnDecl->getNumParams() + (isa<CXXMethodDecl>(FnDecl)? 1 : 0); if (Op != OO_Call && ((NumParams == 1 && !CanBeUnaryOperator) || @@ -3702,7 +3700,7 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) { if (!ParamIsInt) return Diag(LastParam->getLocation(), - diag::err_operator_overload_post_incdec_must_be_int) + diag::err_operator_overload_post_incdec_must_be_int) << LastParam->getType() << (Op == OO_MinusMinus); } @@ -3741,11 +3739,11 @@ Sema::DeclPtrTy Sema::ActOnStartLinkageSpecification(Scope *S, Diag(LangLoc, diag::err_bad_language); return DeclPtrTy(); } - + // FIXME: Add all the various semantics of linkage specifications - + LinkageSpecDecl *D = LinkageSpecDecl::Create(Context, CurContext, - LangLoc, Language, + LangLoc, Language, LBraceLoc.isValid()); CurContext->addDecl(D); PushDeclContext(S, D); @@ -3784,7 +3782,7 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S, QualType ExDeclType, // The exception-declaration shall not denote a pointer or reference to an // incomplete type, other than [cv] void*. // N2844 forbids rvalue references. - if(!ExDeclType->isDependentType() && ExDeclType->isRValueReferenceType()) { + if (!ExDeclType->isDependentType() && ExDeclType->isRValueReferenceType()) { Diag(Loc, diag::err_catch_rvalue_ref) << Range; Invalid = true; } @@ -3796,7 +3794,7 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S, QualType ExDeclType, BaseType = Ptr->getPointeeType(); Mode = 1; DK = diag::err_catch_incomplete_ptr; - } else if(const ReferenceType *Ref = BaseType->getAs<ReferenceType>()) { + } else if (const ReferenceType *Ref = BaseType->getAs<ReferenceType>()) { // For the purpose of error recovery, we treat rvalue refs like lvalue refs. BaseType = Ref->getPointeeType(); Mode = 2; @@ -3806,7 +3804,7 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S, QualType ExDeclType, !BaseType->isDependentType() && RequireCompleteType(Loc, BaseType, DK)) Invalid = true; - if (!Invalid && !ExDeclType->isDependentType() && + if (!Invalid && !ExDeclType->isDependentType() && RequireNonAbstractType(Loc, ExDeclType, diag::err_abstract_type_in_decl, AbstractVariableType)) @@ -3817,7 +3815,7 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S, QualType ExDeclType, // FIXME: Need to check for abstract classes. - VarDecl *ExDecl = VarDecl::Create(Context, CurContext, Loc, + VarDecl *ExDecl = VarDecl::Create(Context, CurContext, Loc, Name, ExDeclType, DInfo, VarDecl::None); if (Invalid) @@ -3857,7 +3855,7 @@ Sema::DeclPtrTy Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) { if (Invalid) ExDecl->setInvalidDecl(); - + // Add the exception declaration into this scope. if (II) PushOnScopeChains(ExDecl, S); @@ -3868,11 +3866,11 @@ Sema::DeclPtrTy Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) { return DeclPtrTy::make(ExDecl); } -Sema::DeclPtrTy Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, +Sema::DeclPtrTy Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, ExprArg assertexpr, ExprArg assertmessageexpr) { Expr *AssertExpr = (Expr *)assertexpr.get(); - StringLiteral *AssertMessage = + StringLiteral *AssertMessage = cast<StringLiteral>((Expr *)assertmessageexpr.get()); if (!AssertExpr->isTypeDependent() && !AssertExpr->isValueDependent()) { @@ -3884,18 +3882,18 @@ Sema::DeclPtrTy Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, } if (Value == 0) { - std::string str(AssertMessage->getStrData(), + std::string str(AssertMessage->getStrData(), AssertMessage->getByteLength()); - Diag(AssertLoc, diag::err_static_assert_failed) + Diag(AssertLoc, diag::err_static_assert_failed) << str << AssertExpr->getSourceRange(); } } - + assertexpr.release(); assertmessageexpr.release(); - Decl *Decl = StaticAssertDecl::Create(Context, CurContext, AssertLoc, + Decl *Decl = StaticAssertDecl::Create(Context, CurContext, AssertLoc, AssertExpr, AssertMessage); - + CurContext->addDecl(Decl); return DeclPtrTy::make(Decl); } @@ -3944,7 +3942,7 @@ Sema::DeclPtrTy Sema::ActOnFriendTypeDecl(Scope *S, }else { Diag(DS.getFriendSpecLoc(), diag::err_unexpected_friend) << DS.getSourceRange(); - return DeclPtrTy(); + return DeclPtrTy(); } } @@ -4160,7 +4158,7 @@ Sema::DeclPtrTy Sema::ActOnFriendFunctionDecl(Scope *S, // Add the function declaration to the appropriate lookup tables, // adjusting the redeclarations list as necessary. We don't // want to do this yet if the friending class is dependent. - // + // // Also update the scope-based lookup if the target context's // lookup context is in lexical scope. if (!CurContext->isDependentContext()) { @@ -4181,7 +4179,7 @@ Sema::DeclPtrTy Sema::ActOnFriendFunctionDecl(Scope *S, void Sema::SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc) { AdjustDeclIfTemplate(dcl); - + Decl *Dcl = dcl.getAs<Decl>(); FunctionDecl *Fn = dyn_cast<FunctionDecl>(Dcl); if (!Fn) { @@ -4218,7 +4216,7 @@ void Sema::DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock) { } } -bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, +bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, const CXXMethodDecl *Old) { QualType NewTy = New->getType()->getAsFunctionType()->getResultType(); QualType OldTy = Old->getType()->getAsFunctionType()->getResultType(); @@ -4226,13 +4224,13 @@ bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, QualType CNewTy = Context.getCanonicalType(NewTy); QualType COldTy = Context.getCanonicalType(OldTy); - if (CNewTy == COldTy && + if (CNewTy == COldTy && CNewTy.getCVRQualifiers() == COldTy.getCVRQualifiers()) return false; - + // Check if the return types are covariant QualType NewClassTy, OldClassTy; - + /// Both types must be pointers or references to classes. if (PointerType *NewPT = dyn_cast<PointerType>(NewTy)) { if (PointerType *OldPT = dyn_cast<PointerType>(OldTy)) { @@ -4245,14 +4243,14 @@ bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, OldClassTy = OldRT->getPointeeType(); } } - + // The return types aren't either both pointers or references to a class type. if (NewClassTy.isNull()) { - Diag(New->getLocation(), + Diag(New->getLocation(), diag::err_different_return_type_for_overriding_virtual_function) << New->getDeclName() << NewTy << OldTy; Diag(Old->getLocation(), diag::note_overridden_virtual_function); - + return true; } @@ -4265,9 +4263,9 @@ bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, Diag(Old->getLocation(), diag::note_overridden_virtual_function); return true; } - + // Check if we the conversion from derived to base is valid. - if (CheckDerivedToBaseConversion(NewClassTy, OldClassTy, + if (CheckDerivedToBaseConversion(NewClassTy, OldClassTy, diag::err_covariant_return_inaccessible_base, diag::err_covariant_return_ambiguous_derived_to_base_conv, // FIXME: Should this point to the return type? @@ -4276,7 +4274,7 @@ bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, return true; } } - + // The qualifiers of the return types must be the same. if (CNewTy.getCVRQualifiers() != COldTy.getCVRQualifiers()) { Diag(New->getLocation(), @@ -4285,7 +4283,7 @@ bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, Diag(Old->getLocation(), diag::note_overridden_virtual_function); return true; }; - + // The new class type must have the same or less qualifiers as the old type. if (NewClassTy.isMoreQualifiedThan(OldClassTy)) { @@ -4295,13 +4293,12 @@ bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, Diag(Old->getLocation(), diag::note_overridden_virtual_function); return true; }; - + return false; } bool Sema::CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, - const CXXMethodDecl *Old) -{ + const CXXMethodDecl *Old) { return CheckExceptionSpecSubset(diag::err_override_exception_spec, diag::note_overridden_virtual_function, Old->getType()->getAsFunctionProtoType(), @@ -4317,7 +4314,7 @@ bool Sema::CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, /// class X. void Sema::ActOnCXXEnterDeclInitializer(Scope *S, DeclPtrTy Dcl) { AdjustDeclIfTemplate(Dcl); - + Decl *D = Dcl.getAs<Decl>(); // If there is no declaration, there was an error parsing it. if (D == 0) @@ -4327,13 +4324,13 @@ void Sema::ActOnCXXEnterDeclInitializer(Scope *S, DeclPtrTy Dcl) { // int foo::bar; if (!D->isOutOfLine()) return; - + // C++ [basic.lookup.unqual]p13 // // A name used in the definition of a static data member of class X // (after the qualified-id of the static member) is looked up as if the name // was used in a member function of X. - + // Change current context into the context of the initializing declaration. EnterDeclaratorContext(S, D->getDeclContext()); } @@ -4342,7 +4339,7 @@ void Sema::ActOnCXXEnterDeclInitializer(Scope *S, DeclPtrTy Dcl) { /// initializer for the declaration 'Dcl'. void Sema::ActOnCXXExitDeclInitializer(Scope *S, DeclPtrTy Dcl) { AdjustDeclIfTemplate(Dcl); - + Decl *D = Dcl.getAs<Decl>(); // If there is no declaration, there was an error parsing it. if (D == 0) |