diff options
author | Mike Stump <mrs@apple.com> | 2009-09-09 15:08:12 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-09-09 15:08:12 +0000 |
commit | 1eb4433ac451dc16f4133a88af2d002ac26c58ef (patch) | |
tree | 07065b80cb7787bb7b9ffcb985196007a57e86f7 /lib/Sema | |
parent | 79d39f92590cf2e91bf81486b02cd1156d13ca54 (diff) |
Remove tabs, and whitespace cleanups.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81346 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
31 files changed, 5238 insertions, 5300 deletions
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp index a36b85a87a..0dbf21961f 100644 --- a/lib/Sema/IdentifierResolver.cpp +++ b/lib/Sema/IdentifierResolver.cpp @@ -32,7 +32,7 @@ class IdentifierResolver::IdDeclInfoMap { // New vectors are added when the current one is full. std::list< std::vector<IdDeclInfo> > IDIVecs; unsigned int CurIndex; - + public: IdDeclInfoMap() : CurIndex(VECTOR_SIZE) {} @@ -75,7 +75,7 @@ void IdentifierResolver::IdDeclInfo::RemoveDecl(NamedDecl *D) { assert(0 && "Didn't find this decl on its identifier's chain!"); } -bool +bool IdentifierResolver::IdDeclInfo::ReplaceDecl(NamedDecl *Old, NamedDecl *New) { for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) { if (Old == *(I-1)) { @@ -108,7 +108,7 @@ bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, if (Ctx->isFunctionOrMethod()) { // Ignore the scopes associated within transparent declaration contexts. - while (S->getEntity() && + while (S->getEntity() && ((DeclContext *)S->getEntity())->isTransparentContext()) S = S->getParent(); @@ -200,14 +200,14 @@ void IdentifierResolver::RemoveDecl(NamedDecl *D) { Name.setFETokenInfo(NULL); return; } - + return toIdDeclInfo(Ptr)->RemoveDecl(D); } bool IdentifierResolver::ReplaceDecl(NamedDecl *Old, NamedDecl *New) { - assert(Old->getDeclName() == New->getDeclName() && + assert(Old->getDeclName() == New->getDeclName() && "Cannot replace a decl with another decl of a different name"); - + DeclarationName Name = Old->getDeclName(); void *Ptr = Name.getFETokenInfo<void>(); @@ -222,7 +222,7 @@ bool IdentifierResolver::ReplaceDecl(NamedDecl *Old, NamedDecl *New) { return false; } - return toIdDeclInfo(Ptr)->ReplaceDecl(Old, New); + return toIdDeclInfo(Ptr)->ReplaceDecl(Old, New); } /// begin - Returns an iterator for decls with name 'Name'. @@ -243,7 +243,7 @@ IdentifierResolver::begin(DeclarationName Name) { return end(); } -void IdentifierResolver::AddDeclToIdentifierChain(IdentifierInfo *II, +void IdentifierResolver::AddDeclToIdentifierChain(IdentifierInfo *II, NamedDecl *D) { void *Ptr = II->getFETokenInfo<void>(); diff --git a/lib/Sema/IdentifierResolver.h b/lib/Sema/IdentifierResolver.h index 0b0e6b388d..65f3256c21 100644 --- a/lib/Sema/IdentifierResolver.h +++ b/lib/Sema/IdentifierResolver.h @@ -99,7 +99,7 @@ public: assert(isIterator() && "Ptr not an iterator!"); return reinterpret_cast<BaseIter>(Ptr & ~0x3); } - + friend class IdentifierResolver; public: iterator() : Ptr(0) {} @@ -110,14 +110,14 @@ public: else return reinterpret_cast<NamedDecl*>(Ptr); } - + bool operator==(const iterator &RHS) const { return Ptr == RHS.Ptr; } bool operator!=(const iterator &RHS) const { return Ptr != RHS.Ptr; } - + // Preincrement. iterator& operator++() { if (!isIterator()) // common case. @@ -127,7 +127,7 @@ public: void *InfoPtr = D->getDeclName().getFETokenInfo<void>(); assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?"); IdDeclInfo *Info = toIdDeclInfo(InfoPtr); - + BaseIter I = getIterator(); if (I != Info->decls_begin()) *this = iterator(I-1); @@ -138,7 +138,7 @@ public: } uintptr_t getAsOpaqueValue() const { return Ptr; } - + static iterator getFromOpaqueValue(uintptr_t P) { iterator Result; Result.Ptr = P; diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp index 853adaa336..a8e31d2cfa 100644 --- a/lib/Sema/JumpDiagnostics.cpp +++ b/lib/Sema/JumpDiagnostics.cpp @@ -28,7 +28,7 @@ namespace { /// class JumpScopeChecker { Sema &S; - + /// GotoScope - This is a record that we use to keep track of all of the /// scopes that are introduced by VLAs and other things that scope jumps like /// gotos. This scope tree has nothing to do with the source scope tree, @@ -38,17 +38,17 @@ class JumpScopeChecker { /// ParentScope - The index in ScopeMap of the parent scope. This is 0 for /// the parent scope is the function body. unsigned ParentScope; - + /// Diag - The diagnostic to emit if there is a jump into this scope. unsigned Diag; - + /// Loc - Location to emit the diagnostic. SourceLocation Loc; - + GotoScope(unsigned parentScope, unsigned diag, SourceLocation L) : ParentScope(parentScope), Diag(diag), Loc(L) {} }; - + llvm::SmallVector<GotoScope, 48> Scopes; llvm::DenseMap<Stmt*, unsigned> LabelAndGotoScopes; llvm::SmallVector<Stmt*, 16> Jumps; @@ -66,15 +66,15 @@ private: JumpScopeChecker::JumpScopeChecker(Stmt *Body, Sema &s) : S(s) { // Add a scope entry for function scope. Scopes.push_back(GotoScope(~0U, ~0U, SourceLocation())); - + // Build information for the top level compound statement, so that we have a // defined scope record for every "goto" and label. BuildScopeInformation(Body, 0); - + // Check that all jumps we saw are kosher. VerifyJumps(); } - + /// GetDiagForGotoScopeDecl - If this decl induces a new goto scope, return a /// diagnostic that should be emitted if control goes over it. If not, return 0. static unsigned GetDiagForGotoScopeDecl(const Decl *D) { @@ -89,7 +89,7 @@ static unsigned GetDiagForGotoScopeDecl(const Decl *D) { if (TD->getUnderlyingType()->isVariablyModifiedType()) return diag::note_protected_by_vla_typedef; } - + return 0; } @@ -99,7 +99,7 @@ static unsigned GetDiagForGotoScopeDecl(const Decl *D) { /// statements, adding any labels or gotos to LabelAndGotoScopes and recursively /// walking the AST as needed. void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) { - + // If we found a label, remember that it is in ParentScope scope. if (isa<LabelStmt>(S) || isa<DefaultStmt>(S) || isa<CaseStmt>(S)) { LabelAndGotoScopes[S] = ParentScope; @@ -110,12 +110,12 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) { LabelAndGotoScopes[S] = ParentScope; Jumps.push_back(S); } - + for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end(); CI != E; ++CI) { Stmt *SubStmt = *CI; if (SubStmt == 0) continue; - + // FIXME: diagnose jumps past initialization: required in C++, warning in C. // goto L; int X = 4; L: ; @@ -131,7 +131,7 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) { Scopes.push_back(GotoScope(ParentScope, Diag, (*I)->getLocation())); ParentScope = Scopes.size()-1; } - + // If the decl has an initializer, walk it with the potentially new // scope we just installed. if (VarDecl *VD = dyn_cast<VarDecl>(*I)) @@ -156,10 +156,10 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) { Scopes.push_back(GotoScope(ParentScope, diag::note_protected_by_objc_catch, AC->getAtCatchLoc())); - // @catches are nested and it isn't + // @catches are nested and it isn't BuildScopeInformation(AC->getCatchBody(), Scopes.size()-1); } - + // Jump from the finally to the try or catch is not valid. if (ObjCAtFinallyStmt *AF = AT->getFinallyStmt()) { Scopes.push_back(GotoScope(ParentScope, @@ -167,17 +167,17 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) { AF->getAtFinallyLoc())); BuildScopeInformation(AF, Scopes.size()-1); } - + continue; } - + // Disallow jumps into the protected statement of an @synchronized, but // allow jumps into the object expression it protects. if (ObjCAtSynchronizedStmt *AS = dyn_cast<ObjCAtSynchronizedStmt>(SubStmt)){ // Recursively walk the AST for the @synchronized object expr, it is // evaluated in the normal scope. BuildScopeInformation(AS->getSynchExpr(), ParentScope); - + // Recursively walk the AST for the @synchronized part, protected by a new // scope. Scopes.push_back(GotoScope(ParentScope, @@ -196,7 +196,7 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) { BuildScopeInformation(TryBlock, Scopes.size()-1); // Jump from the catch into the try is not allowed either. - for(unsigned I = 0, E = TS->getNumHandlers(); I != E; ++I) { + for (unsigned I = 0, E = TS->getNumHandlers(); I != E; ++I) { CXXCatchStmt *CS = TS->getHandler(I); Scopes.push_back(GotoScope(ParentScope, diag::note_protected_by_cxx_catch, @@ -217,14 +217,14 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) { void JumpScopeChecker::VerifyJumps() { while (!Jumps.empty()) { Stmt *Jump = Jumps.pop_back_val(); - - // With a goto, + + // With a goto, if (GotoStmt *GS = dyn_cast<GotoStmt>(Jump)) { CheckJump(GS, GS->getLabel(), GS->getGotoLoc(), diag::err_goto_into_protected_scope); continue; } - + if (SwitchStmt *SS = dyn_cast<SwitchStmt>(Jump)) { for (SwitchCase *SC = SS->getSwitchCaseList(); SC; SC = SC->getNextSwitchCase()) { @@ -236,7 +236,7 @@ void JumpScopeChecker::VerifyJumps() { } unsigned DiagnosticScope; - + // We don't know where an indirect goto goes, require that it be at the // top level of scoping. if (IndirectGotoStmt *IG = dyn_cast<IndirectGotoStmt>(Jump)) { @@ -254,12 +254,12 @@ void JumpScopeChecker::VerifyJumps() { // indirectly jumping to the label. assert(isa<AddrLabelExpr>(Jump) && "Unknown jump type"); LabelStmt *TheLabel = cast<AddrLabelExpr>(Jump)->getLabel(); - + assert(LabelAndGotoScopes.count(TheLabel) && "Referenced label didn't get added to scopes?"); unsigned LabelScope = LabelAndGotoScopes[TheLabel]; if (LabelScope == 0) continue; // Addr of label is ok. - + S.Diag(Jump->getLocStart(), diag::err_addr_of_label_in_protected_scope); DiagnosticScope = LabelScope; } @@ -282,10 +282,10 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, assert(LabelAndGotoScopes.count(To) && "Jump didn't get added to scopes?"); unsigned ToScope = LabelAndGotoScopes[To]; - + // Common case: exactly the same scope, which is fine. if (FromScope == ToScope) return; - + // The only valid mismatch jump case happens when the jump is more deeply // nested inside the jump target. Do a quick scan to see if the jump is valid // because valid code is more common than invalid code. @@ -294,11 +294,11 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, // If we found the jump target, then we're jumping out of our current scope, // which is perfectly fine. if (TestScope == ToScope) return; - + // Otherwise, scan up the hierarchy. TestScope = Scopes[TestScope].ParentScope; } - + // If we get here, then we know we have invalid code. Diagnose the bad jump, // and then emit a note at each VLA being jumped out of. S.Diag(DiagLoc, JumpDiag); @@ -318,7 +318,7 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, FromScopes.pop_back(); ToScopes.pop_back(); } - + // Emit diagnostics for whatever is left in ToScopes. for (unsigned i = 0, e = ToScopes.size(); i != e; ++i) S.Diag(Scopes[ToScopes[i]].Loc, Scopes[ToScopes[i]].Diag); diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp index b6e52570ea..196c1c1b85 100644 --- a/lib/Sema/ParseAST.cpp +++ b/lib/Sema/ParseAST.cpp @@ -43,17 +43,17 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit); Parser P(PP, S); PP.EnterMainSourceFile(); - + // Initialize the parser. P.Initialize(); - + Consumer->Initialize(Ctx); - + if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer)) SC->InitializeSema(S); if (ExternalASTSource *External = Ctx.getExternalSource()) { - if (ExternalSemaSource *ExternalSema = + if (ExternalSemaSource *ExternalSema = dyn_cast<ExternalSemaSource>(External)) ExternalSema->InitializeSema(S); @@ -61,7 +61,7 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, } Parser::DeclGroupPtrTy ADecl; - + while (!P.ParseTopLevelDecl(ADecl)) { // Not end of file. // If we got a null return and something *was* parsed, ignore it. This // is due to a top-level semicolon, an action override, or a parse error @@ -69,7 +69,7 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, if (ADecl) Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>()); }; - + // process any TopLevelDecls generated by #pragma weak for (llvm::SmallVector<Decl*,2>::iterator I = S.WeakTopLevelDecls().begin(), @@ -85,7 +85,7 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, Decl::PrintStats(); Stmt::PrintStats(); Consumer->PrintStats(); - + Decl::CollectingStats(false); Stmt::CollectingStats(false); } diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 2d72c3e1be..b158c85414 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -23,7 +23,7 @@ #include "clang/Basic/TargetInfo.h" using namespace clang; -/// ConvertQualTypeToStringFn - This function is used to pretty print the +/// ConvertQualTypeToStringFn - This function is used to pretty print the /// specified QualType as a string in diagnostics. static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, const char *Modifier, unsigned ModLen, @@ -31,7 +31,7 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, llvm::SmallVectorImpl<char> &Output, void *Cookie) { ASTContext &Context = *static_cast<ASTContext*>(Cookie); - + std::string S; if (Kind == Diagnostic::ak_qualtype) { assert(ModLen == 0 && ArgLen == 0 && @@ -41,7 +41,7 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, // FIXME: Playing with std::string is really slow. S = Ty.getAsString(Context.PrintingPolicy); - + // If this is a sugared type (like a typedef, typeof, etc), then unwrap one // level of the sugar so that the type is more obvious to the user. QualType DesugaredTy = Ty->getDesugaredType(true); @@ -56,13 +56,13 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, // Don't aka just because we saw an elaborated type. (!isa<ElaboratedType>(Ty) || cast<ElaboratedType>(Ty)->getUnderlyingType() != DesugaredTy) && - + // Don't desugar magic Objective-C types. Ty.getUnqualifiedType() != Context.getObjCIdType() && Ty.getUnqualifiedType() != Context.getObjCClassType() && Ty.getUnqualifiedType() != Context.getObjCSelType() && Ty.getUnqualifiedType() != Context.getObjCProtoType() && - + // Not va_list. Ty.getUnqualifiedType() != Context.getBuiltinVaListType()) { S = "'"+S+"' (aka '"; @@ -71,12 +71,12 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, Output.append(S.begin(), S.end()); return; } - + } else if (Kind == Diagnostic::ak_declarationname) { - + DeclarationName N = DeclarationName::getFromOpaqueInteger(Val); S = N.getAsString(); - + if (ModLen == 9 && !memcmp(Modifier, "objcclass", 9) && ArgLen == 0) S = '+' + S; else if (ModLen == 12 && !memcmp(Modifier, "objcinstance", 12) && ArgLen==0) @@ -87,7 +87,7 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, } else if (Kind == Diagnostic::ak_nameddecl) { if (ModLen == 1 && Modifier[0] == 'q' && ArgLen == 0) S = reinterpret_cast<NamedDecl*>(Val)->getQualifiedNameAsString(); - else { + else { assert(ModLen == 0 && ArgLen == 0 && "Invalid modifier for NamedDecl* argument"); S = reinterpret_cast<NamedDecl*>(Val)->getNameAsString(); @@ -95,10 +95,10 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, } else { llvm::raw_string_ostream OS(S); assert(Kind == Diagnostic::ak_nestednamespec); - reinterpret_cast<NestedNameSpecifier*> (Val)->print(OS, + reinterpret_cast<NestedNameSpecifier*> (Val)->print(OS, Context.PrintingPolicy); } - + Output.push_back('\''); Output.append(S.begin(), S.end()); Output.push_back('\''); @@ -107,11 +107,11 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, static inline RecordDecl *CreateStructDecl(ASTContext &C, const char *Name) { if (C.getLangOptions().CPlusPlus) - return CXXRecordDecl::Create(C, TagDecl::TK_struct, + return CXXRecordDecl::Create(C, TagDecl::TK_struct, C.getTranslationUnitDecl(), SourceLocation(), &C.Idents.get(Name)); - return RecordDecl::Create(C, TagDecl::TK_struct, + return RecordDecl::Create(C, TagDecl::TK_struct, C.getTranslationUnitDecl(), SourceLocation(), &C.Idents.get(Name)); } @@ -119,7 +119,7 @@ static inline RecordDecl *CreateStructDecl(ASTContext &C, const char *Name) { void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { TUScope = S; PushDeclContext(S, Context.getTranslationUnitDecl()); - + if (PP.getTargetInfo().getPointerWidth(0) >= 64) { // Install [u]int128_t for 64-bit targets. PushOnScopeChains(TypedefDecl::Create(Context, CurContext, @@ -131,16 +131,16 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { &Context.Idents.get("__uint128_t"), Context.UnsignedInt128Ty), TUScope); } - - + + if (!PP.getLangOptions().ObjC1) return; - + // Built-in ObjC types may already be set by PCHReader (hence isNull checks). if (Context.getObjCSelType().isNull()) { // Synthesize "typedef struct objc_selector *SEL;" RecordDecl *SelTag = CreateStructDecl(Context, "objc_selector"); PushOnScopeChains(SelTag, TUScope); - + QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag)); TypedefDecl *SelTypedef = TypedefDecl::Create(Context, CurContext, SourceLocation(), @@ -154,15 +154,15 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { if (Context.getObjCProtoType().isNull()) { ObjCInterfaceDecl *ProtocolDecl = ObjCInterfaceDecl::Create(Context, CurContext, SourceLocation(), - &Context.Idents.get("Protocol"), + &Context.Idents.get("Protocol"), SourceLocation(), true); Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); PushOnScopeChains(ProtocolDecl, TUScope); } // Create the built-in typedef for 'id'. if (Context.getObjCIdType().isNull()) { - TypedefDecl *IdTypedef = - TypedefDecl::Create( + TypedefDecl *IdTypedef = + TypedefDecl::Create( Context, CurContext, SourceLocation(), &Context.Idents.get("id"), Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy) ); @@ -172,8 +172,8 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { } // Create the built-in typedef for 'Class'. if (Context.getObjCClassType().isNull()) { - TypedefDecl *ClassTypedef = - TypedefDecl::Create( + TypedefDecl *ClassTypedef = + TypedefDecl::Create( Context, CurContext, SourceLocation(), &Context.Idents.get("Class"), Context.getObjCObjectPointerType(Context.ObjCBuiltinClassTy) ); @@ -186,36 +186,36 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, bool CompleteTranslationUnit) : LangOpts(pp.getLangOptions()), PP(pp), Context(ctxt), Consumer(consumer), - Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()), + Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()), ExternalSource(0), CurContext(0), PreDeclaratorDC(0), CurBlock(0), PackContext(0), IdResolver(pp.getLangOptions()), GlobalNewDeleteDeclared(false), ExprEvalContext(PotentiallyEvaluated), CompleteTranslationUnit(CompleteTranslationUnit), NumSFINAEErrors(0), CurrentInstantiationScope(0) { - + StdNamespace = 0; TUScope = 0; if (getLangOptions().CPlusPlus) FieldCollector.reset(new CXXFieldCollector()); - + // Tell diagnostics how to render things from the AST library. PP.getDiagnostics().SetArgToStringFn(ConvertArgToStringFn, &Context); } -/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. +/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. /// If there is already an implicit cast, merge into the existing one. /// If isLvalue, the result of the cast is an lvalue. -void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, +void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, const CastExpr::CastInfo &Info, bool isLvalue) { QualType ExprTy = Context.getCanonicalType(Expr->getType()); QualType TypeTy = Context.getCanonicalType(Ty); - + if (ExprTy == TypeTy) return; - + if (Expr->getType().getTypePtr()->isPointerType() && Ty.getTypePtr()->isPointerType()) { - QualType ExprBaseType = + QualType ExprBaseType = cast<PointerType>(ExprTy.getUnqualifiedType())->getPointeeType(); QualType BaseType = cast<PointerType>(TypeTy.getUnqualifiedType())->getPointeeType(); @@ -224,12 +224,12 @@ void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, << Expr->getSourceRange(); } } - + if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) { ImpCast->setType(Ty); ImpCast->setLvalueCast(isLvalue); - } else - Expr = new (Context) ImplicitCastExpr(Ty, Info, Expr, + } else + Expr = new (Context) ImplicitCastExpr(Ty, Info, Expr, isLvalue); } @@ -250,12 +250,12 @@ void Sema::ActOnEndOfTranslationUnit() { // keep track of the point of instantiation (C++ [temp.point]). This means // that name lookup that occurs within the template instantiation will // always happen at the end of the translation unit, so it will find - // some names that should not be found. Although this is common behavior + // some names that should not be found. Although this is common behavior // for C++ compilers, it is technically wrong. In the future, we either need // to be able to filter the results of name lookup or we need to perform // template instantiations earlier. PerformPendingImplicitInstantiations(); - + // Check for #pragma weak identifiers that were never declared // FIXME: This will cause diagnostics to be emitted in a non-determinstic // order! Iterating over a densemap like this is bad. @@ -263,7 +263,7 @@ void Sema::ActOnEndOfTranslationUnit() { I = WeakUndeclaredIdentifiers.begin(), E = WeakUndeclaredIdentifiers.end(); I != E; ++I) { if (I->second.getUsed()) continue; - + Diag(I->second.getLocation(), diag::warn_weak_identifier_undeclared) << I->first; } @@ -284,29 +284,29 @@ void Sema::ActOnEndOfTranslationUnit() { // translation unit, with an initializer equal to 0. for (unsigned i = 0, e = TentativeDefinitionList.size(); i != e; ++i) { VarDecl *VD = TentativeDefinitions.lookup(TentativeDefinitionList[i]); - + // If the tentative definition was completed, it will be in the list, but // not the map. if (VD == 0 || VD->isInvalidDecl() || !VD->isTentativeDefinition(Context)) continue; - if (const IncompleteArrayType *ArrayT + if (const IncompleteArrayType *ArrayT = Context.getAsIncompleteArrayType(VD->getType())) { - if (RequireCompleteType(VD->getLocation(), + if (RequireCompleteType(VD->getLocation(), ArrayT->getElementType(), diag::err_tentative_def_incomplete_type_arr)) { VD->setInvalidDecl(); continue; } - + // Set the length of the array to 1 (C99 6.9.2p5). Diag(VD->getLocation(), diag::warn_tentative_incomplete_array); llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true); - QualType T + QualType T = Context.getConstantArrayWithoutExprType(ArrayT->getElementType(), One, ArrayType::Normal, 0); VD->setType(T); - } else if (RequireCompleteType(VD->getLocation(), VD->getType(), + } else if (RequireCompleteType(VD->getLocation(), VD->getType(), diag::err_tentative_def_incomplete_type)) VD->setInvalidDecl(); @@ -324,10 +324,10 @@ void Sema::ActOnEndOfTranslationUnit() { DeclContext *Sema::getFunctionLevelDeclContext() { DeclContext *DC = PreDeclaratorDC ? PreDeclaratorDC : CurContext; - + while (isa<BlockDecl>(DC)) DC = DC->getParent(); - + return DC; } @@ -351,7 +351,7 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() { return 0; } -void Sema::DiagnoseMissingMember(SourceLocation MemberLoc, +void Sema::DiagnoseMissingMember(SourceLocation MemberLoc, DeclarationName Member, NestedNameSpecifier *NNS, SourceRange Range) { switch (NNS->getKind()) { @@ -379,17 +379,17 @@ void Sema::DiagnoseMissingMember(SourceLocation MemberLoc, Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() { if (!this->Emit()) return; - + // If this is not a note, and we're in a template instantiation // that is different from the last template instantiation where // we emitted an error, print a template instantiation // backtrace. if (!SemaRef.Diags.isBuiltinNote(DiagID) && !SemaRef.ActiveTemplateInstantiations.empty() && - SemaRef.ActiveTemplateInstantiations.back() + SemaRef.ActiveTemplateInstantiations.back() != SemaRef.LastTemplateInstantiationErrorContext) { SemaRef.PrintInstantiationStack(); - SemaRef.LastTemplateInstantiationErrorContext + SemaRef.LastTemplateInstantiationErrorContext = SemaRef.ActiveTemplateInstantiations.back(); } } @@ -398,7 +398,7 @@ Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation Loc, const PartialDiagnostic& PD) { SemaDiagnosticBuilder Builder(Diag(Loc, PD.getDiagID())); PD.Emit(Builder); - + return Builder; } diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index ee893e2e0d..a73a2b912c 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -100,30 +100,30 @@ struct BlockSemaInfo { bool hasPrototype; bool isVariadic; bool hasBlockDeclRefExprs; - + BlockDecl *TheDecl; - + /// TheScope - This is the scope for the block itself, which contains /// arguments etc. Scope *TheScope; - + /// ReturnType - This will get set to block result type, by looking at /// return types, if any, in the block body. QualType ReturnType; - + /// LabelMap - This is a mapping from label identifiers to the LabelStmt for /// it (which acts like the label decl in some ways). Forward referenced /// labels have a LabelStmt created for them with a null location & SubStmt. llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap; - + /// SwitchStack - This is the current set of active switch statements in the /// block. llvm::SmallVector<SwitchStmt*, 8> SwitchStack; - + /// SavedFunctionNeedsScopeChecking - This is the value of /// CurFunctionNeedsScopeChecking at the point when the block started. bool SavedFunctionNeedsScopeChecking; - + /// PrevBlockInfo - If this is nested inside another block, this points /// to the outer block. BlockSemaInfo *PrevBlockInfo; @@ -138,7 +138,7 @@ struct BlockSemaInfo { class LocInfoType : public Type { enum { // The last number that can fit in Type's TC. - // Avoids conflict with an existing Type class. + // Avoids conflict with an existing Type class. LocInfo = (1 << TypeClassBitSize) - 1 }; @@ -201,13 +201,13 @@ public: /// Note that this should always be accessed through getLabelMap() in order /// to handle blocks properly. llvm::DenseMap<IdentifierInfo*, LabelStmt*> FunctionLabelMap; - + /// FunctionSwitchStack - This is the current set of active switch statements /// in the top level function. Clients should always use getSwitchStack() to /// handle the case when they are in a block. llvm::SmallVector<SwitchStmt*, 8> FunctionSwitchStack; - /// ExprTemporaries - This is the stack of temporaries that are created by + /// ExprTemporaries - This is the stack of temporaries that are created by /// the current full expression. llvm::SmallVector<CXXTemporary*, 8> ExprTemporaries; @@ -216,22 +216,22 @@ public: /// scopes that need to be checked for goto conditions. If a function does /// not contain this, then it need not have the jump checker run on it. bool CurFunctionNeedsScopeChecking; - + /// ExtVectorDecls - This is a list all the extended vector types. This allows /// us to associate a raw vector type with one of the ext_vector type names. /// This is only necessary for issuing pretty diagnostics. llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls; - + /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. llvm::OwningPtr<CXXFieldCollector> FieldCollector; typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; - - /// PureVirtualClassDiagSet - a set of class declarations which we have + + /// PureVirtualClassDiagSet - a set of class declarations which we have /// emitted a list of pure virtual functions. Used to prevent emitting the /// same list more than once. llvm::OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet; - + /// \brief A mapping from external names to the most recent /// locally-scoped external declaration with that name. /// @@ -315,17 +315,17 @@ public: /// The current expression evaluation context. ExpressionEvaluationContext ExprEvalContext; - - typedef std::vector<std::pair<SourceLocation, Decl *> > + + typedef std::vector<std::pair<SourceLocation, Decl *> > PotentiallyReferencedDecls; - + /// A stack of declarations, each element of which is a set of declarations /// that will be marked as referenced if the corresponding potentially /// potentially evaluated expression is potentially evaluated. Each element /// in the stack corresponds to a PotentiallyPotentiallyEvaluated expression /// evaluation context. std::list<PotentiallyReferencedDecls> PotentiallyReferencedDeclStack; - + /// \brief Whether the code handled by Sema should be considered a /// complete translation unit or not. /// @@ -346,11 +346,11 @@ public: /// Instance/Factory Method Pools - allows efficient lookup when typechecking /// messages to "id". We need to maintain a list, since selectors can have - /// differing signatures across classes. In Cocoa, this happens to be + /// differing signatures across classes. In Cocoa, this happens to be /// extremely uncommon (only 1% of selectors are "overloaded"). MethodPool InstanceMethodPool; MethodPool FactoryMethodPool; - + MethodPool::iterator ReadMethodPool(Selector Sel, bool isInstance); /// Private Helper predicate to check for 'self'. @@ -361,7 +361,7 @@ public: ~Sema() { if (PackContext) FreePackedContext(); } - + const LangOptions &getLangOptions() const { return LangOpts; } Diagnostic &getDiagnostics() const { return Diags; } SourceManager &getSourceManager() const { return SourceMgr; } @@ -383,7 +383,7 @@ public: SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { } - explicit SemaDiagnosticBuilder(Sema &SemaRef) + explicit SemaDiagnosticBuilder(Sema &SemaRef) : DiagnosticBuilder(DiagnosticBuilder::Suppress), SemaRef(SemaRef) { } ~SemaDiagnosticBuilder(); @@ -424,7 +424,7 @@ public: llvm::DenseMap<IdentifierInfo*, LabelStmt*> &getLabelMap() { return CurBlock ? CurBlock->LabelMap : FunctionLabelMap; } - + /// getSwitchStack - This is returns the switch stack for the current block or /// function. llvm::SmallVector<SwitchStmt*,8> &getSwitchStack() { @@ -433,7 +433,7 @@ public: /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls llvm::SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; } - + virtual void ActOnComment(SourceRange Comment); //===--------------------------------------------------------------------===// @@ -443,21 +443,21 @@ public: QualType ConvertDeclSpecToType(const DeclSpec &DS, SourceLocation DeclLoc, bool &IsInvalid); void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL); - QualType BuildPointerType(QualType T, unsigned Quals, + QualType BuildPointerType(QualType T, unsigned Quals, SourceLocation Loc, DeclarationName Entity); QualType BuildReferenceType(QualType T, bool LValueRef, unsigned Quals, SourceLocation Loc, DeclarationName Entity); QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, Expr *ArraySize, unsigned Quals, SourceRange Brackets, DeclarationName Entity); - QualType BuildExtVectorType(QualType T, ExprArg ArraySize, + QualType BuildExtVectorType(QualType T, ExprArg ArraySize, SourceLocation AttrLoc); QualType BuildFunctionType(QualType T, QualType *ParamTypes, unsigned NumParamTypes, bool Variadic, unsigned Quals, SourceLocation Loc, DeclarationName Entity); - QualType BuildMemberPointerType(QualType T, QualType Class, - unsigned Quals, SourceLocation Loc, + QualType BuildMemberPointerType(QualType T, QualType Class, + unsigned Quals, SourceLocation Loc, DeclarationName Entity); QualType BuildBlockPointerType(QualType T, unsigned Quals, SourceLocation Loc, DeclarationName Entity); @@ -487,32 +487,32 @@ public: bool RequireCompleteType(SourceLocation Loc, QualType T, const PartialDiagnostic &PD); - + QualType getQualifiedNameType(const CXXScopeSpec &SS, QualType T); QualType BuildTypeofExprType(Expr *E); QualType BuildDecltypeType(Expr *E); - + //===--------------------------------------------------------------------===// // Symbol table / Decl tracking callbacks: SemaDecl.cpp. // /// getDeclName - Return a pretty name for the specified decl if possible, or - /// an empty string if not. This is used for pretty crash reporting. + /// an empty string if not. This is used for pretty crash reporting. virtual std::string getDeclName(DeclPtrTy D); - + DeclGroupPtrTy ConvertDeclToDeclGroup(DeclPtrTy Ptr); - virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, + virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, Scope *S, const CXXScopeSpec *SS, bool isClassName = false); virtual DeclSpec::TST isTagName(IdentifierInfo &II, Scope *S); - + virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D) { return HandleDeclarator(S, D, MultiTemplateParamsArg(*this), false); } - - DeclPtrTy HandleDeclarator(Scope *S, Declarator &D, + + DeclPtrTy HandleDeclarator(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, bool IsFunctionDefinition); void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl, @@ -530,26 +530,26 @@ public: bool &Redeclaration); NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, QualType R, DeclaratorInfo *DInfo, - NamedDecl* PrevDecl, + NamedDecl* PrevDecl, MultiTemplateParamsArg TemplateParamLists, bool IsFunctionDefinition, bool &Redeclaration); void CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl, - bool &Redeclaration, + bool &Redeclaration, bool &OverloadableAttrRequired); void CheckMain(FunctionDecl *FD); virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D); virtual void ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, ExprArg defarg); - virtual void ActOnParamUnparsedDefaultArgument(DeclPtrTy param, + virtual void ActOnParamUnparsedDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, SourceLocation ArgLoc); virtual void ActOnParamDefaultArgumentError(DeclPtrTy param); bool SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg, SourceLocation EqualLoc); - + // Contains the locations of the beginning of unparsed default // argument locations. llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs; @@ -570,19 +570,19 @@ public: virtual DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body); DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body, bool IsInstantiation); - + /// \brief Diagnose any unused parameters in the given sequence of /// ParmVarDecl pointers. template<typename InputIterator> void DiagnoseUnusedParameters(InputIterator Param, InputIterator ParamEnd) { for (; Param != ParamEnd; ++Param) { - if (!(*Param)->isUsed() && (*Param)->getDeclName() && + if (!(*Param)->isUsed() && (*Param)->getDeclName() && !(*Param)->template hasAttr<UnusedAttr>()) Diag((*Param)->getLocation(), diag::warn_unused_parameter) << (*Param)->getDeclName(); } } - + void DiagnoseInvalidJumps(Stmt *Body); virtual DeclPtrTy ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr); @@ -593,13 +593,13 @@ public: /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with /// no declarator (e.g. "struct foo;") is parsed. virtual DeclPtrTy ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS); - + bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner, RecordDecl *AnonRecord); - virtual DeclPtrTy BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, + virtual DeclPtrTy BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, RecordDecl *Record); - bool isAcceptableTagRedeclaration(const TagDecl *Previous, + bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagDecl::TagKind NewTag, SourceLocation NewTagLoc, const IdentifierInfo &Name); @@ -610,7 +610,7 @@ public: AttributeList *Attr, AccessSpecifier AS, MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl); - + virtual void ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, IdentifierInfo *ClassName, llvm::SmallVectorImpl<DeclPtrTy> &Decls); @@ -623,7 +623,7 @@ public: AccessSpecifier AS); FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, - DeclaratorInfo *DInfo, + DeclaratorInfo *DInfo, RecordDecl *Record, SourceLocation Loc, bool Mutable, Expr *BitfieldWidth, SourceLocation TSSL, @@ -637,7 +637,7 @@ public: CXXDestructor = 3 }; void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem); - + virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart, DeclPtrTy IntfDecl, Declarator &D, ExprTy *BitfieldWidth, @@ -680,19 +680,19 @@ public: /// Set the current declaration context until it gets popped. void PushDeclContext(Scope *S, DeclContext *DC); void PopDeclContext(); - + /// EnterDeclaratorContext - Used when we must lookup names in the context /// of a declarator's nested name specifier. void EnterDeclaratorContext(Scope *S, DeclContext *DC); void ExitDeclaratorContext(Scope *S); - + DeclContext *getFunctionLevelDeclContext(); - + /// getCurFunctionDecl - If inside of a function body, this returns a pointer /// to the function decl for the function being parsed. If we're currently /// in a 'block', this returns the containing context. FunctionDecl *getCurFunctionDecl(); - + /// getCurMethodDecl - If inside of a method body, this returns a pointer to /// the method decl for the method being parsed. If we're currently /// in a 'block', this returns the containing context. @@ -736,9 +736,9 @@ public: bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old); /// C++ Overloading. - bool IsOverload(FunctionDecl *New, Decl* OldD, + bool IsOverload(FunctionDecl *New, Decl* OldD, OverloadedFunctionDecl::function_iterator &MatchedDecl); - ImplicitConversionSequence + ImplicitConversionSequence TryImplicitConversion(Expr* From, QualType ToType, bool SuppressUserConversions, bool AllowExplicit, @@ -761,20 +761,20 @@ public: bool CheckMemberPointerConversion(Expr *From, QualType ToType, CastExpr::CastKind &Kind); bool IsQualificationConversion(QualType FromType, QualType ToType); - bool IsUserDefinedConversion(Expr *From, QualType ToType, + bool IsUserDefinedConversion(Expr *From, QualType ToType, UserDefinedConversionSequence& User, bool AllowConversionFunctions, bool AllowExplicit, bool ForceRValue); - ImplicitConversionSequence::CompareKind + ImplicitConversionSequence::CompareKind CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1, const ImplicitConversionSequence& ICS2); - ImplicitConversionSequence::CompareKind + ImplicitConversionSequence::CompareKind CompareStandardConversionSequences(const StandardConversionSequence& SCS1, const StandardConversionSequence& SCS2); - ImplicitConversionSequence::CompareKind + ImplicitConversionSequence::CompareKind CompareQualificationConversions(const StandardConversionSequence& SCS1, const StandardConversionSequence& SCS2); @@ -782,11 +782,11 @@ public: CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1, const StandardConversionSequence& SCS2); - ImplicitConversionSequence + ImplicitConversionSequence TryCopyInitialization(Expr* From, QualType ToType, bool SuppressUserConversions, bool ForceRValue, bool InOverloadResolution); - bool PerformCopyInitialization(Expr *&From, QualType ToType, + bool PerformCopyInitialization(Expr *&From, QualType ToType, const char *Flavor, bool Elidable = false); ImplicitConversionSequence @@ -795,7 +795,7 @@ public: ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From); bool PerformContextuallyConvertToBool(Expr *&From); - + bool PerformObjectMemberConversion(Expr *&From, NamedDecl *Member); /// OverloadingResult - Capture the result of performing overload @@ -814,7 +814,7 @@ public: typedef llvm::SmallPtrSet<AnyFunctionDecl, 16> FunctionSet; typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet; - void AddOverloadCandidate(FunctionDecl *Function, + void AddOverloadCandidate(FunctionDecl *Function, Expr **Args, unsigned NumArgs, OverloadCandidateSet& CandidateSet, bool SuppressUserConversions = false, @@ -864,13 +864,13 @@ public: Expr **Args, unsigned NumArgs, OverloadCandidateSet& CandidateSet, SourceRange OpRange = SourceRange()); - void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, + void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, Expr **Args, unsigned NumArgs, OverloadCandidateSet& CandidateSet, bool IsAssignmentOperator = false, unsigned NumContextualBoolArguments = 0); - void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, - Expr **Args, unsigned NumArgs, + void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, + Expr **Args, unsigned NumArgs, OverloadCandidateSet& CandidateSet); void AddArgumentDependentLookupCandidates(DeclarationName Name, Expr **Args, unsigned NumArgs, @@ -882,7 +882,7 @@ public: OverloadCandidateSet::iterator& Best); void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet, bool OnlyViable); - + FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, bool Complain); void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn); @@ -894,7 +894,7 @@ public: unsigned NumExplicitTemplateArgs, SourceLocation LParenLoc, Expr **Args, unsigned NumArgs, - SourceLocation *CommaLocs, + SourceLocation *CommaLocs, SourceLocation RParenLoc, bool &ArgumentDependentLookup); @@ -910,18 +910,18 @@ public: ExprResult BuildCallToMemberFunction(Scope *S, Expr *MemExpr, - SourceLocation LParenLoc, Expr **Args, + SourceLocation LParenLoc, Expr **Args, unsigned NumArgs, SourceLocation *CommaLocs, SourceLocation RParenLoc); - ExprResult + ExprResult BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, Expr **Args, unsigned NumArgs, - SourceLocation *CommaLocs, + SourceLocation *CommaLocs, SourceLocation RParenLoc); OwningExprResult BuildOverloadedArrowExpr(Scope *S, ExprArg Base, SourceLocation OpLoc); - + /// Helpers for dealing with blocks and functions. void CheckFallThroughForFunctionDef(Decl *D, Stmt *Body); void CheckFallThroughForBlock(QualType BlockTy, Stmt *Body); @@ -941,7 +941,7 @@ public: /// overloaded operator names, constructor names, etc.) into zero or /// more declarations within a particular scope. The major entry /// points are LookupName, which performs unqualified name lookup, - /// and LookupQualifiedName, which performs qualified name lookup. + /// and LookupQualifiedName, which performs qualified name lookup. /// /// All name lookup is performed based on some specific criteria, /// which specify what names will be visible to name lookup and how @@ -988,7 +988,7 @@ public: LookupNamespaceName, /// Look up an ordinary name that is going to be redeclared as a /// name with linkage. This lookup ignores any declarations that - /// are outside of the current scope unless they have linkage. See + /// are outside of the current scope unless they have linkage. See /// C99 6.2.2p4-5 and C++ [basic.link]p6. LookupRedeclarationWithLinkage, /// Look up the name of an Objective-C protocol. @@ -1005,7 +1005,7 @@ public: /// single name lookup, which can return no result (nothing found), /// a single declaration, a set of overloaded functions, or an /// ambiguity. Use the getKind() method to determine which of these - /// results occurred for a given lookup. + /// results occurred for a given lookup. /// /// Any non-ambiguous lookup can be converted into a single /// (possibly NULL) @c NamedDecl* via a conversion function or the @@ -1085,7 +1085,7 @@ public: /// struct A { void f(int); } /// struct B { void f(double); } /// struct C : A, B { }; - /// void test(C c) { + /// void test(C c) { /// c.f(0); // error: A::f and B::f come from subobjects of different /// // types. overload resolution is not performed. /// } @@ -1124,15 +1124,15 @@ public: static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D); - static LookupResult CreateLookupResult(ASTContext &Context, - IdentifierResolver::iterator F, + static LookupResult CreateLookupResult(ASTContext &Context, + IdentifierResolver::iterator F, IdentifierResolver::iterator L); - static LookupResult CreateLookupResult(ASTContext &Context, - DeclContext::lookup_iterator F, + static LookupResult CreateLookupResult(ASTContext &Context, + DeclContext::lookup_iterator F, DeclContext::lookup_iterator L); - static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths, + static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths, bool DifferentSubobjectTypes) { LookupResult Result; Result.StoredKind = AmbiguousLookupStoresBasePaths; @@ -1252,37 +1252,37 @@ public: case Sema::LookupObjCImplementationName: case Sema::LookupObjCCategoryImplName: return D->isInIdentifierNamespace(IDNS); - + case Sema::LookupOperatorName: - return D->isInIdentifierNamespace(IDNS) && + return D->isInIdentifierNamespace(IDNS) && !D->getDeclContext()->isRecord(); case Sema::LookupNestedNameSpecifierName: return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag); - + case Sema::LookupNamespaceName: return isa<NamespaceDecl>(D) || isa<NamespaceAliasDecl>(D); } - - assert(false && + + assert(false && "isAcceptableLookupResult always returns before this point"); return false; } - LookupResult LookupName(Scope *S, DeclarationName Name, - LookupNameKind NameKind, + LookupResult LookupName(Scope *S, DeclarationName Name, + LookupNameKind NameKind, bool RedeclarationOnly = false, bool AllowBuiltinCreation = false, SourceLocation Loc = SourceLocation()); LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, - LookupNameKind NameKind, + LookupNameKind NameKind, bool RedeclarationOnly = false); Decl *LookupQualifiedNameWithType(DeclContext *LookupCtx, DeclarationName Name, QualType T); - LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS, + LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS, DeclarationName Name, - LookupNameKind NameKind, + LookupNameKind NameKind, bool RedeclarationOnly = false, bool AllowBuiltinCreation = false, SourceLocation Loc = SourceLocation(), @@ -1292,9 +1292,9 @@ public: ObjCCategoryImplDecl *LookupObjCCategoryImpl(IdentifierInfo *II); void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, - QualType T1, QualType T2, + QualType T1, QualType T2, FunctionSet &Functions); - + void ArgumentDependentLookup(DeclarationName Name, Expr **Args, unsigned NumArgs, FunctionSet &Functions); @@ -1304,12 +1304,12 @@ public: AssociatedClassSet &AssociatedClasses); bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name, - SourceLocation NameLoc, + SourceLocation NameLoc, SourceRange LookupRange = SourceRange()); //@} - + ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id); - NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, + NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, bool ForRedeclaration, SourceLocation Loc); NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, @@ -1318,7 +1318,7 @@ public: // More parsing and symbol table subroutines. - // Decl attributes - this routine is the top level dispatcher. + // Decl attributes - this routine is the top level dispatcher. void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AttrList); @@ -1328,10 +1328,10 @@ public: ObjCMethodDecl *IntfMethod); NamespaceDecl *GetStdNamespace(); - + bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl, ObjCInterfaceDecl *IDecl); - + /// CheckProtocolMethodDefs - This routine checks unimplemented /// methods declared in protocol, and those referenced by it. /// \param IDecl - Used for checking for methods which may have been @@ -1342,24 +1342,24 @@ public: const llvm::DenseSet<Selector> &InsMap, const llvm::DenseSet<Selector> &ClsMap, ObjCInterfaceDecl *IDecl); - + /// CheckImplementationIvars - This routine checks if the instance variables - /// listed in the implelementation match those listed in the interface. + /// listed in the implelementation match those listed in the interface. void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, ObjCIvarDecl **Fields, unsigned nIvars, SourceLocation Loc); - + /// ImplMethodsVsClassMethods - This is main routine to warn if any method /// remains unimplemented in the class or category @implementation. - void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, - ObjCContainerDecl* IDecl, + void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, + ObjCContainerDecl* IDecl, bool IncompleteImpl = false); - + /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns /// true, or false, accordingly. - bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, + bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, const ObjCMethodDecl *PrevMethod, - bool matchBasedOnSizeAndAlignment = false); + bool matchBasedOnSizeAndAlignment = false); /// MatchAllMethodDeclarations - Check methods declaraed in interface or /// or protocol against those declared in their implementations. @@ -1377,7 +1377,7 @@ public: /// a selector with a method declaraation for purposes of typechecking /// messages sent to "id" (where the class of the object is unknown). void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method); - + /// LookupInstanceMethodInGlobalPool - Returns the method and warns if /// there are multiple signatures. ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, @@ -1386,7 +1386,7 @@ public: /// LookupFactoryMethodInGlobalPool - Returns the method and warns if /// there are multiple signatures. ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R); - + /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method); //===--------------------------------------------------------------------===// @@ -1405,7 +1405,7 @@ public: SourceLocation DotDotDotLoc, ExprArg RHSVal, SourceLocation ColonLoc); virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt); - + virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, StmtArg SubStmt, Scope *CurScope); @@ -1413,13 +1413,13 @@ public: IdentifierInfo *II, SourceLocation ColonLoc, StmtArg SubStmt); - virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, - FullExprArg CondVal, StmtArg ThenVal, + virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, + FullExprArg CondVal, StmtArg ThenVal, SourceLocation ElseLoc, StmtArg ElseVal); virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond); virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, StmtArg Body); - virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, + virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, StmtArg Body); virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, SourceLocation WhileLoc, @@ -1477,7 +1477,7 @@ public: StmtArg Catch, StmtArg Finally); virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, - ExprArg Throw, + ExprArg Throw, Scope *CurScope); virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr, @@ -1501,26 +1501,26 @@ public: /// DiagnoseUnusedExprResult - If the statement passed in is an expression /// whose result is unused, warn. void DiagnoseUnusedExprResult(const Stmt *S); - + //===--------------------------------------------------------------------===// // Expression Parsing Callbacks: SemaExpr.cpp. bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc); - bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, + bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, ObjCMethodDecl *Getter, SourceLocation Loc); void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, Expr **Args, unsigned NumArgs); - virtual ExpressionEvaluationContext + virtual ExpressionEvaluationContext PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext); - - virtual void + + virtual void PopExpressionEvaluationContext(ExpressionEvaluationContext OldContext, ExpressionEvaluationContext NewContext); - + void MarkDeclarationReferenced(SourceLocation Loc, Decl *D); - + // Primary Expressions. virtual SourceRange getExprRange(ExprTy *E) const; @@ -1541,8 +1541,8 @@ public: bool HasTrailingLParen, const CXXScopeSpec &SS, bool isAddressOfOperand); - OwningExprResult BuildDeclRefExpr(NamedDecl *D, QualType Ty, - SourceLocation Loc, bool TypeDependent, + OwningExprResult BuildDeclRefExpr(NamedDecl *D, QualType Ty, + SourceLocation Loc, bool TypeDependent, bool ValueDependent, const CXXScopeSpec *SS = 0); VarDecl *BuildAnonymousStructUnionMemberPath(FieldDecl *Field, @@ -1559,9 +1559,9 @@ public: bool isAddressOfOperand = false); OwningExprResult BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D, bool HasTrailingLParen, - const CXXScopeSpec *SS, + const CXXScopeSpec *SS, bool isAddressOfOperand); - + virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); virtual OwningExprResult ActOnNumericConstant(const Token &); @@ -1571,7 +1571,7 @@ public: virtual OwningExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val); - + /// ActOnStringLiteral - The specified tokens were lexed as pasted string /// fragments (e.g. "foo" "bar" L"baz"). virtual OwningExprResult ActOnStringLiteral(const Token *Toks, @@ -1579,19 +1579,19 @@ public: // Binary/Unary Operators. 'Tok' is the token for the operator. OwningExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, - unsigned OpcIn, + unsigned OpcIn, ExprArg InputArg); virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, ExprArg Input); - OwningExprResult CreateSizeOfAlignOfExpr(QualType T, SourceLocation OpLoc, + OwningExprResult CreateSizeOfAlignOfExpr(QualType T, SourceLocation OpLoc, bool isSizeOf, SourceRange R); - OwningExprResult CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc, + OwningExprResult CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc, bool isSizeOf, SourceRange R); virtual OwningExprResult ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType, void *TyOrEx, const SourceRange &ArgRange); - + bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R); bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc, const SourceRange &R, bool isSizeof); @@ -1613,7 +1613,7 @@ public: DeclPtrTy ImplDecl, const CXXScopeSpec *SS = 0, NamedDecl *FirstQualifierInScope = 0) { - // FIXME: Temporary helper while we migrate existing calls to + // FIXME: Temporary helper while we migrate existing calls to // BuildMemberReferenceExpr to support explicitly-specified template // arguments. return BuildMemberReferenceExpr(S, move(Base), OpLoc, OpKind, MemberLoc, @@ -1621,7 +1621,7 @@ public: SourceLocation(), ImplDecl, SS, FirstQualifierInScope); } - + OwningExprResult BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, tok::TokenKind OpKind, @@ -1635,7 +1635,7 @@ public: DeclPtrTy ImplDecl, const CXXScopeSpec *SS, NamedDecl *FirstQualifierInScope = 0); - + virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, tok::TokenKind OpKind, @@ -1667,7 +1667,7 @@ public: virtual OwningExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, TypeTy *Ty, SourceLocation RParenLoc, ExprArg Op); - + OwningExprResult MaybeConvertParenListExprToParenExpr(Scope *S, ExprArg ME); OwningExprResult ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc, SourceLocation RParenLoc, ExprArg E, @@ -1769,7 +1769,7 @@ public: SourceLocation IdentLoc, IdentifierInfo *NamespcName, AttributeList *AttrList); - + void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); virtual DeclPtrTy ActOnNamespaceAliasDef(Scope *CurScope, @@ -1786,7 +1786,7 @@ public: DeclarationName Name, AttributeList *AttrList, bool IsTypeName); - + virtual DeclPtrTy ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, SourceLocation UsingLoc, @@ -1796,8 +1796,8 @@ public: OverloadedOperatorKind Op, AttributeList *AttrList, bool IsTypeName); - - /// 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);" virtual void AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, @@ -1808,73 +1808,73 @@ public: /// InitializeVarWithConstructor - Creates an CXXConstructExpr /// and sets it as the initializer for the the passed in VarDecl. - bool InitializeVarWithConstructor(VarDecl *VD, + bool InitializeVarWithConstructor(VarDecl *VD, CXXConstructorDecl *Constructor, - QualType DeclInitType, + QualType DeclInitType, MultiExprArg Exprs); /// BuildCXXConstructExpr - Creates a complete call to a constructor, /// including handling of its default argument expressions. - OwningExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc, + OwningExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, CXXConstructorDecl *Constructor, MultiExprArg Exprs); // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if // the constructor can be elidable? - OwningExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc, + OwningExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs); - - OwningExprResult BuildCXXTemporaryObjectExpr(CXXConstructorDecl *Cons, - QualType writtenTy, - SourceLocation tyBeginLoc, + + OwningExprResult BuildCXXTemporaryObjectExpr(CXXConstructorDecl *Cons, + QualType writtenTy, + SourceLocation tyBeginLoc, MultiExprArg Args, SourceLocation rParenLoc); - + /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating /// the default expr if needed. OwningExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param); - + /// FinalizeVarWithDestructor - Prepare for calling destructor on the /// constructed variable. void FinalizeVarWithDestructor(VarDecl *VD, QualType DeclInitType); - - /// DefineImplicitDefaultConstructor - Checks for feasibility of + + /// DefineImplicitDefaultConstructor - Checks for feasibility of /// defining this constructor as the default constructor. void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, CXXConstructorDecl *Constructor); - - /// DefineImplicitDestructor - Checks for feasibility of + + /// DefineImplicitDestructor - Checks for feasibility of /// defining this destructor as the default destructor. void DefineImplicitDestructor(SourceLocation CurrentLocation, CXXDestructorDecl *Destructor); - - /// DefineImplicitCopyConstructor - Checks for feasibility of + + /// DefineImplicitCopyConstructor - Checks for feasibility of /// defining this constructor as the copy constructor. void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, CXXConstructorDecl *Constructor, unsigned TypeQuals); - + /// DefineImplicitOverloadedAssign - Checks for feasibility of /// defining implicit this overloaded assignment operator. - void DefineImplicitOverloadedAssign(SourceLocation CurrentLocation, + void DefineImplicitOverloadedAssign(SourceLocation CurrentLocation, CXXMethodDecl *MethodDecl); - + /// getAssignOperatorMethod - Returns the default copy assignmment operator /// for the class. CXXMethodDecl *getAssignOperatorMethod(ParmVarDecl *Decl, - CXXRecordDecl *ClassDecl); + CXXRecordDecl *ClassDecl); /// MaybeBindToTemporary - If the passed in expression has a record type with /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise /// it simply returns the passed in expression. OwningExprResult MaybeBindToTemporary(Expr *E); - + /// InitializationKind - Represents which kind of C++ initialization /// [dcl.init] a routine is to perform. enum InitializationKind { @@ -1945,7 +1945,7 @@ public: SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, - bool ParenTypeId, + bool ParenTypeId, QualType AllocType, SourceLocation TypeLoc, SourceRange TypeRange, @@ -1953,7 +1953,7 @@ public: SourceLocation ConstructorLParen, MultiExprArg ConstructorArgs, SourceLocation ConstructorRParen); - + bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, SourceRange R); bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, @@ -1990,13 +1990,13 @@ public: SourceLocation LParen, TypeTy *Ty, SourceLocation RParen); - + virtual OwningExprResult ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc, tok::TokenKind OpKind, TypeTy *&ObjectType); - + virtual OwningExprResult ActOnDestructorReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, @@ -2020,7 +2020,7 @@ public: SourceLocation ClassNameLoc, TypeTy *Ty, const CXXScopeSpec *SS = 0); - + virtual OwningExprResult ActOnMemberTemplateIdReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, @@ -2033,19 +2033,19 @@ public: ASTTemplateArgsPtr TemplateArgs, SourceLocation *TemplateArgLocs, SourceLocation RAngleLoc); - - /// MaybeCreateCXXExprWithTemporaries - If the list of temporaries is + + /// MaybeCreateCXXExprWithTemporaries - If the list of temporaries is /// non-empty, will create a new CXXExprWithTemporaries expression. /// Otherwise, just returs the passed in expression. Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr, bool ShouldDestroyTemporaries); - + virtual OwningExprResult ActOnFinishFullExpr(ExprArg Expr); bool RequireCompleteDeclContext(const CXXScopeSpec &SS); - + DeclContext *computeDeclContext(QualType T); - DeclContext *computeDeclContext(const CXXScopeSpec &SS, + DeclContext *computeDeclContext(const CXXScopeSpec &SS, bool EnteringContext = false); bool isDependentScopeSpecifier(const CXXScopeSpec &SS); CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); @@ -2057,7 +2057,7 @@ public: SourceLocation CCLoc); NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); - + CXXScopeTy *BuildCXXNestedNameSpecifier(Scope *S, const CXXScopeSpec &SS, @@ -2067,7 +2067,7 @@ public: QualType ObjectType, NamedDecl *ScopeLookupResult, bool EnteringContext); - + virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S, const CXXScopeSpec &SS, SourceLocation IdLoc, @@ -2117,26 +2117,26 @@ public: virtual void ActOnCXXExitDeclInitializer(Scope *S, DeclPtrTy Dcl); // ParseObjCStringLiteral - Parse Objective-C string literals. - virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, + virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, ExprTy **Strings, unsigned NumStrings); - - Expr *BuildObjCEncodeExpression(SourceLocation AtLoc, + + Expr *BuildObjCEncodeExpression(SourceLocation AtLoc, QualType EncodedType, - SourceLocation RParenLoc); + SourceLocation RParenLoc); virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, SourceLocation EncodeLoc, SourceLocation LParenLoc, TypeTy *Ty, SourceLocation RParenLoc); - + // ParseObjCSelectorExpression - Build selector expression for @selector virtual ExprResult ParseObjCSelectorExpression(Selector Sel, SourceLocation AtLoc, SourceLocation SelLoc, SourceLocation LParenLoc, SourceLocation RParenLoc); - + // ParseObjCProtocolExpression - Build protocol expression for @protocol virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, SourceLocation AtLoc, @@ -2190,25 +2190,25 @@ public: unsigned NumArgs, SourceLocation IdLoc, SourceLocation RParenLoc, CXXRecordDecl *ClassDecl); - + void setBaseOrMemberInitializers(CXXConstructorDecl *Constructor, CXXBaseOrMemberInitializer **Initializers, unsigned NumInitializers, llvm::SmallVectorImpl<CXXBaseSpecifier *>& Bases, llvm::SmallVectorImpl<FieldDecl *>&Members); - - /// computeBaseOrMembersToDestroy - Compute information in current - /// destructor decl's AST of bases and non-static data members which will be + + /// computeBaseOrMembersToDestroy - Compute information in current + /// destructor decl's AST of bases and non-static data members which will be /// implicitly destroyed. We are storing the destruction in the order that /// they should occur (which is the reverse of construction order). void computeBaseOrMembersToDestroy(CXXDestructorDecl *Destructor); - + void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); - virtual void ActOnMemInitializers(DeclPtrTy ConstructorDecl, + virtual void ActOnMemInitializers(DeclPtrTy ConstructorDecl, SourceLocation ColonLoc, MemInitTy **MemInits, unsigned NumMemInits); - + virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, DeclPtrTy TagDecl, SourceLocation LBrac, @@ -2221,10 +2221,10 @@ public: virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclPtrTy Method); - virtual DeclPtrTy ActOnStaticAssertDeclaration(SourceLocation AssertLoc, + virtual DeclPtrTy ActOnStaticAssertDeclaration(SourceLocation AssertLoc, ExprArg AssertExpr, ExprArg AssertMessageExpr); - + virtual DeclPtrTy ActOnFriendDecl(Scope *S, llvm::PointerUnion<const DeclSpec*,Declarator*> D, bool IsDefinition); @@ -2249,17 +2249,17 @@ public: CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, - QualType BaseType, + QualType BaseType, SourceLocation BaseLoc); - virtual BaseResult ActOnBaseSpecifier(DeclPtrTy classdecl, + virtual BaseResult ActOnBaseSpecifier(DeclPtrTy classdecl, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, - TypeTy *basetype, SourceLocation + TypeTy *basetype, SourceLocation BaseLoc); bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, unsigned NumBases); - virtual void ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases, + virtual void ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases, unsigned NumBases); bool IsDerivedFrom(QualType Derived, QualType Base); @@ -2273,9 +2273,9 @@ public: unsigned AmbigiousBaseConvID, SourceLocation Loc, SourceRange Range, DeclarationName Name); - + std::string getAmbiguousPathsDisplayString(BasePaths &Paths); - + /// CheckOverridingFunctionReturnType - Checks whether the return types are /// covariant, according to C++ [class.virtual]p5. bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, @@ -2290,7 +2290,7 @@ public: // C++ Access Control // - bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, + bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, NamedDecl *PrevMemberDecl, AccessSpecifier LexicalAS); @@ -2311,12 +2311,12 @@ public: AbstractVariableType, AbstractFieldType }; - + bool RequireNonAbstractType(SourceLocation Loc, QualType T, const PartialDiagnostic &PD, const CXXRecordDecl *CurrentRD = 0); - - bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, + + bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, AbstractDiagSelID SelID = AbstractNone, const CXXRecordDecl *CurrentRD = 0); @@ -2330,7 +2330,7 @@ public: // C++ Templates [C++ 14] // virtual TemplateNameKind isTemplateName(Scope *S, - const IdentifierInfo &II, + const IdentifierInfo &II, SourceLocation IdLoc, const CXXScopeSpec *SS, TypeTy *ObjectType, @@ -2339,13 +2339,13 @@ public: bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); TemplateDecl *AdjustDeclIfTemplate(DeclPtrTy &Decl); - virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, + virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, SourceLocation EllipsisLoc, SourceLocation KeyLoc, IdentifierInfo *ParamName, SourceLocation ParamNameLoc, unsigned Depth, unsigned Position); - virtual void ActOnTypeParameterDefault(DeclPtrTy TypeParam, + virtual void ActOnTypeParameterDefault(DeclPtrTy TypeParam, SourceLocation EqualLoc, SourceLocation DefaultLoc, TypeTy *Default); @@ -2371,7 +2371,7 @@ public: virtual TemplateParamsTy * ActOnTemplateParameterList(unsigned Depth, SourceLocation ExportLoc, - SourceLocation TemplateLoc, + SourceLocation TemplateLoc, SourceLocation LAngleLoc, DeclPtrTy *Params, unsigned NumParams, SourceLocation RAngleLoc); @@ -2382,7 +2382,7 @@ public: const CXXScopeSpec &SS, TemplateParameterList **ParamLists, unsigned NumParamLists); - + DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, const CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, @@ -2408,21 +2408,21 @@ public: TagUseKind TUK, DeclSpec::TST TagSpec, SourceLocation TagLoc); - + OwningExprResult BuildTemplateIdExpr(TemplateName Template, SourceLocation TemplateNameLoc, SourceLocation LAngleLoc, const TemplateArgument *TemplateArgs, unsigned NumTemplateArgs, SourceLocation RAngleLoc); - + virtual OwningExprResult ActOnTemplateIdExpr(TemplateTy Template, SourceLocation TemplateNameLoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, SourceLocation *TemplateArgLocs, SourceLocation RAngleLoc); - + virtual TemplateTy ActOnDependentTemplateName(SourceLocation TemplateKWLoc, const IdentifierInfo &Name, SourceLocation NameLoc, @@ -2443,7 +2443,7 @@ public: virtual DeclResult ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, - SourceLocation KWLoc, + SourceLocation KWLoc, const CXXScopeSpec &SS, TemplateTy Template, SourceLocation TemplateNameLoc, @@ -2454,19 +2454,19 @@ public: AttributeList *Attr, MultiTemplateParamsArg TemplateParameterLists); - virtual DeclPtrTy ActOnTemplateDeclarator(Scope *S, + virtual DeclPtrTy ActOnTemplateDeclarator(Scope *S, MultiTemplateParamsArg TemplateParameterLists, Declarator &D); - - virtual DeclPtrTy ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, + + virtual DeclPtrTy ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, MultiTemplateParamsArg TemplateParameterLists, Declarator &D); - + virtual DeclResult - ActOnExplicitInstantiation(Scope *S, + ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, - unsigned TagSpec, + unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, TemplateTy Template, @@ -2478,10 +2478,10 @@ public: AttributeList *Attr); virtual DeclResult - ActOnExplicitInstantiation(Scope *S, + ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, - unsigned TagSpec, + unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, IdentifierInfo *Name, @@ -2497,16 +2497,16 @@ public: bool PartialTemplateArgs, TemplateArgumentListBuilder &Converted); - bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, + bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, const TemplateArgument &Arg, TemplateArgumentListBuilder &Converted); bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg, SourceLocation ArgLoc); - bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, + bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, NamedDecl *&Entity); bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member); - bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param, + bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param, QualType InstantiatedParamType, Expr *&Arg, TemplateArgument &Converted); bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg); @@ -2516,7 +2516,7 @@ public: bool IsTemplateTemplateParm = false, SourceLocation TemplateArgLoc = SourceLocation()); - + bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); /// \brief Called when the parser has parsed a C++ typename @@ -2531,7 +2531,7 @@ public: const IdentifierInfo &II, SourceLocation IdLoc); /// \brief Called when the parser has parsed a C++ typename - /// specifier that ends in a template-id, e.g., + /// specifier that ends in a template-id, e.g., /// "typename MetaFun::template apply<T1, T2>". /// /// \param TypenameLoc the location of the 'typename' keyword @@ -2583,10 +2583,10 @@ public: /// produces a type that does not match the original template /// arguments provided. TDK_NonDeducedMismatch, - /// \brief When performing template argument deduction for a function + /// \brief When performing template argument deduction for a function /// template, there were too many call arguments. TDK_TooManyArguments, - /// \brief When performing template argument deduction for a function + /// \brief When performing template argument deduction for a function /// template, there were too few call arguments. TDK_TooFewArguments, /// \brief The explicitly-specified template arguments were not valid @@ -2617,7 +2617,7 @@ public: } /// \brief Take ownership of the deduced template argument list. - TemplateArgumentList *take() { + TemplateArgumentList *take() { TemplateArgumentList *Result = Deduced; Deduced = 0; return Result; @@ -2670,7 +2670,7 @@ public: DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, const TemplateArgumentList &TemplateArgs, TemplateDeductionInfo &Info); - + TemplateDeductionResult SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, const TemplateArgument *ExplicitTemplateArgs, @@ -2679,13 +2679,13 @@ public: llvm::SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType, TemplateDeductionInfo &Info); - - TemplateDeductionResult + + TemplateDeductionResult FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, llvm::SmallVectorImpl<TemplateArgument> &Deduced, FunctionDecl *&Specialization, TemplateDeductionInfo &Info); - + TemplateDeductionResult DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, bool HasExplicitTemplateArgs, @@ -2703,7 +2703,7 @@ public: QualType ArgFunctionType, FunctionDecl *&Specialization, TemplateDeductionInfo &Info); - + TemplateDeductionResult DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, QualType ToType, @@ -2716,7 +2716,7 @@ public: void MarkDeducedTemplateParameters(const TemplateArgumentList &TemplateArgs, llvm::SmallVectorImpl<bool> &Deduced); - + //===--------------------------------------------------------------------===// // C++ Template Instantiation // @@ -2743,10 +2743,10 @@ public: /// provides the template arguments as specified. DefaultFunctionArgumentInstantiation, - /// We are substituting explicit template arguments provided for + /// We are substituting explicit template arguments provided for /// a function template. The entity is a FunctionTemplateDecl. ExplicitTemplateArgumentSubstitution, - + /// We are substituting template argument determined as part of /// template argument deduction for either a class template /// partial specialization or a function template. The @@ -2793,7 +2793,7 @@ public: case DeducedTemplateArgumentSubstitution: case DefaultFunctionArgumentInstantiation: return X.TemplateArgs == Y.TemplateArgs; - + } return true; @@ -2811,7 +2811,7 @@ public: /// requires another template instantiation, additional /// instantiations are pushed onto the stack up to a /// user-configurable limit LangOptions::InstantiationDepth. - llvm::SmallVector<ActiveTemplateInstantiation, 16> + llvm::SmallVector<ActiveTemplateInstantiation, 16> ActiveTemplateInstantiations; /// \brief The last template from which a template instantiation @@ -2857,7 +2857,7 @@ public: unsigned NumTemplateArgs, ActiveTemplateInstantiation::InstantiationKind Kind, SourceRange InstantiationRange = SourceRange()); - + /// \brief Note that we are instantiating as part of template /// argument deduction for a class template partial /// specialization. @@ -2891,7 +2891,7 @@ public: InstantiatingTemplate(const InstantiatingTemplate&); // not implemented - InstantiatingTemplate& + InstantiatingTemplate& operator=(const InstantiatingTemplate&); // not implemented }; @@ -2918,8 +2918,8 @@ public: ~SFINAETrap() { SemaRef.NumSFINAEErrors = PrevSFINAEErrors; } /// \brief Determine whether any SFINAE errors have been trapped. - bool hasErrorOccurred() const { - return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; + bool hasErrorOccurred() const { + return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; } }; @@ -2961,7 +2961,7 @@ public: public: LocalInstantiationScope(Sema &SemaRef) - : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope) { + : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope) { SemaRef.CurrentInstantiationScope = this; } @@ -2996,34 +2996,34 @@ public: /// \brief An entity for which implicit template instantiation is required. /// - /// The source location associated with the declaration is the first place in + /// The source location associated with the declaration is the first place in /// the source code where the declaration was "used". It is not necessarily - /// the point of instantiation (which will be either before or after the + /// the point of instantiation (which will be either before or after the /// namespace-scope declaration that triggered this implicit instantiation), /// However, it is the location that diagnostics should generally refer to, /// because users will need to know what code triggered the instantiation. typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; - + /// \brief The queue of implicit template instantiations that are required /// but have not yet been performed. std::deque<PendingImplicitInstantiation> PendingImplicitInstantiations; void PerformPendingImplicitInstantiations(); - - QualType SubstType(QualType T, + + QualType SubstType(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity); - - OwningExprResult SubstExpr(Expr *E, + + OwningExprResult SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs); - OwningStmtResult SubstStmt(Stmt *S, + OwningStmtResult SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs); Decl *SubstDecl(Decl *D, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs); - bool + bool SubstBaseSpecifiers(CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs); @@ -3035,7 +3035,7 @@ public: TemplateSpecializationKind TSK, bool Complain = true); - bool + bool InstantiateClassTemplateSpecialization( ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, @@ -3073,10 +3073,10 @@ public: void InstantiateMemInitializers(CXXConstructorDecl *New, const CXXConstructorDecl *Tmpl, const MultiLevelTemplateArgumentList &TemplateArgs); - + NamedDecl *FindInstantiatedDecl(NamedDecl *D); DeclContext *FindInstantiatedContext(DeclContext *DC); - + // Objective-C declarations. virtual DeclPtrTy ActOnStartClassInterface(SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, @@ -3087,7 +3087,7 @@ public: unsigned NumProtoRefs, SourceLocation EndProtoLoc, AttributeList *AttrList); - + virtual DeclPtrTy ActOnCompatiblityAlias( SourceLocation AtCompatibilityAliasLoc, IdentifierInfo *AliasName, SourceLocation AliasLocation, @@ -3097,14 +3097,14 @@ public: IdentifierInfo *PName, SourceLocation &PLoc, SourceLocation PrevLoc, const ObjCList<ObjCProtocolDecl> &PList); - + virtual DeclPtrTy ActOnStartProtocolInterface( SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, const DeclPtrTy *ProtoRefNames, unsigned NumProtoRefs, SourceLocation EndProtoLoc, AttributeList *AttrList); - + virtual DeclPtrTy ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, @@ -3113,82 +3113,82 @@ public: const DeclPtrTy *ProtoRefs, unsigned NumProtoRefs, SourceLocation EndProtoLoc); - + virtual DeclPtrTy ActOnStartClassImplementation( SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, - IdentifierInfo *SuperClassname, + IdentifierInfo *SuperClassname, SourceLocation SuperClassLoc); - + virtual DeclPtrTy ActOnStartCategoryImplementation( SourceLocation AtCatImplLoc, - IdentifierInfo *ClassName, + IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc); - + virtual DeclPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, IdentifierInfo **IdentList, unsigned NumElts); - + virtual DeclPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, const IdentifierLocPair *IdentList, unsigned NumElts, AttributeList *attrList); - + virtual void FindProtocolDeclaration(bool WarnOnDeclarations, const IdentifierLocPair *ProtocolId, unsigned NumProtocols, llvm::SmallVectorImpl<DeclPtrTy> &Protocols); - - /// Ensure attributes are consistent with type. + + /// Ensure attributes are consistent with type. /// \param [in, out] Attributes The attributes to check; they will /// be modified to be consistent with \arg PropertyTy. - void CheckObjCPropertyAttributes(QualType PropertyTy, + void CheckObjCPropertyAttributes(QualType PropertyTy, SourceLocation Loc, unsigned &Attributes); void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC); - void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, + void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, ObjCPropertyDecl *SuperProperty, const IdentifierInfo *Name); void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); - - void CompareMethodParamsInBaseAndSuper(Decl *IDecl, + + void CompareMethodParamsInBaseAndSuper(Decl *IDecl, ObjCMethodDecl *MethodDecl, bool IsInstance); - + void MergeProtocolPropertiesIntoClass(Decl *CDecl, DeclPtrTy MergeProtocols); - - void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, + + void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, ObjCInterfaceDecl *ID); - + void MergeOneProtocolPropertiesIntoClass(Decl *CDecl, ObjCProtocolDecl *PDecl); - + virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, DeclPtrTy *allMethods = 0, unsigned allNum = 0, DeclPtrTy *allProperties = 0, unsigned pNum = 0, DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); - + virtual DeclPtrTy ActOnProperty(Scope *S, SourceLocation AtLoc, FieldDeclarator &FD, ObjCDeclSpec &ODS, Selector GetterSel, Selector SetterSel, DeclPtrTy ClassCategory, bool *OverridingProperty, tok::ObjCKeywordKind MethodImplKind); - - virtual DeclPtrTy ActOnPropertyImplDecl(SourceLocation AtLoc, + + virtual DeclPtrTy ActOnPropertyImplDecl(SourceLocation AtLoc, SourceLocation PropertyLoc, bool ImplKind,DeclPtrTy ClassImplDecl, IdentifierInfo *PropertyId, IdentifierInfo *PropertyIvar); - + virtual DeclPtrTy ActOnMethodDeclaration( SourceLocation BeginLoc, // location of the + or -. SourceLocation EndLoc, // location of the ; or {. - tok::TokenKind MethodType, - DeclPtrTy ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, + tok::TokenKind MethodType, + DeclPtrTy ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, Selector Sel, // optional arguments. The number of types/arguments is obtained // from the Sel.getNumArgs(). @@ -3201,24 +3201,24 @@ public: // Will search "local" class/category implementations for a method decl. // Will also search in class's root looking for instance method. // Returns 0 if no method is found. - ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, + ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, ObjCInterfaceDecl *CDecl); ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, ObjCInterfaceDecl *ClassDecl); - + virtual OwningExprResult ActOnClassPropertyRefExpr( IdentifierInfo &receiverName, IdentifierInfo &propertyName, SourceLocation &receiverNameLoc, SourceLocation &propertyNameLoc); - + // ActOnClassMessage - used for both unary and keyword messages. // ArgExprs is optional - if it is present, the number of expressions // is obtained from NumArgs. virtual ExprResult ActOnClassMessage( Scope *S, - IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac, - SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac, + IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac, + SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac, ExprTy **ArgExprs, unsigned NumArgs); // ActOnInstanceMessage - used for both unary and keyword messages. @@ -3226,21 +3226,21 @@ public: // is obtained from NumArgs. virtual ExprResult ActOnInstanceMessage( ExprTy *receiver, Selector Sel, - SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac, + SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac, ExprTy **ArgExprs, unsigned NumArgs); - + /// ActOnPragmaPack - Called on well formed #pragma pack(...). virtual void ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, ExprTy *Alignment, - SourceLocation PragmaLoc, + SourceLocation PragmaLoc, SourceLocation LParenLoc, SourceLocation RParenLoc); - + /// ActOnPragmaUnused - Called on well-formed '#pragma unused'. virtual void ActOnPragmaUnused(const Token *Identifiers, unsigned NumIdentifiers, Scope *curScope, - SourceLocation PragmaLoc, + SourceLocation PragmaLoc, SourceLocation LParenLoc, SourceLocation RParenLoc); @@ -3262,28 +3262,28 @@ public: /// getPragmaPackAlignment() - Return the current alignment as specified by /// the current #pragma pack directive, or 0 if none is currently active. unsigned getPragmaPackAlignment() const; - + /// FreePackedContext - Deallocate and null out PackContext. void FreePackedContext(); /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit /// cast. If there is already an implicit cast, merge into the existing one. /// If isLvalue, the result of the cast is an lvalue. - void ImpCastExprToType(Expr *&Expr, QualType Type, - const CastExpr::CastInfo &Info = + void ImpCastExprToType(Expr *&Expr, QualType Type, + const CastExpr::CastInfo &Info = CastExpr::CastInfo(CastExpr::CK_Unknown), bool isLvalue = false); // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts // functions and arrays to their respective pointers (C99 6.3.2.1). - Expr *UsualUnaryConversions(Expr *&expr); + Expr *UsualUnaryConversions(Expr *&expr); // DefaultFunctionArrayConversion - converts functions and arrays - // to their respective pointers (C99 6.3.2.1). + // to their respective pointers (C99 6.3.2.1). void DefaultFunctionArrayConversion(Expr *&expr); - + // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that - // do not have a prototype. Integer promotions are performed on each + // do not have a prototype. Integer promotions are performed on each // argument, and arguments that have type float are promoted to double. void DefaultArgumentPromotion(Expr *&Expr); @@ -3294,19 +3294,19 @@ public: VariadicMethod, VariadicConstructor }; - + // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but // will warn if the resulting type is not a POD type. bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT); - + // UsualArithmeticConversions - performs the UsualUnaryConversions on it's // operands and then handles various conversions that are common to binary // operators (C99 6.3.1.8). If both operands aren't arithmetic, this - // routine returns the first non-arithmetic type found. The client is + // routine returns the first non-arithmetic type found. The client is // responsible for emitting appropriate error diagnostics. QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr, bool isCompAssign = false); - + /// AssignConvertType - All of the 'assignment' semantic checks return this /// enum to indicate whether the assignment was allowed. These checks are /// done for simple assignments, as well as initialization, return from @@ -3315,15 +3315,15 @@ public: enum AssignConvertType { /// Compatible - the types are compatible according to the standard. Compatible, - + /// PointerToInt - The assignment converts a pointer to an int, which we /// accept as an extension. PointerToInt, - + /// IntToPointer - The assignment converts an int to a pointer, which we /// accept as an extension. IntToPointer, - + /// FunctionVoidPointer - The assignment is between a function pointer and /// void*, which the standard doesn't allow, but we accept as an extension. FunctionVoidPointer, @@ -3345,25 +3345,25 @@ public: /// IncompatibleVectors - The assignment is between two vector types that /// have the same size, which we accept as an extension. IncompatibleVectors, - - /// IntToBlockPointer - The assignment converts an int to a block + + /// IntToBlockPointer - The assignment converts an int to a block /// pointer. We disallow this. IntToBlockPointer, - /// IncompatibleBlockPointer - The assignment is between two block + /// IncompatibleBlockPointer - The assignment is between two block /// pointers types that are not compatible. IncompatibleBlockPointer, - + /// IncompatibleObjCQualifiedId - The assignment is between a qualified /// id type and something else (that is incompatible with it). For example, /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. IncompatibleObjCQualifiedId, - + /// Incompatible - We reject this conversion outright, it is invalid to /// represent it in the AST. Incompatible }; - + /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the /// assignment conversion type specified by ConvTy. This returns true if the /// conversion was invalid or false if the conversion was accepted. @@ -3371,39 +3371,39 @@ public: SourceLocation Loc, QualType DstType, QualType SrcType, Expr *SrcExpr, const char *Flavor); - - /// CheckAssignmentConstraints - Perform type checking for assignment, - /// argument passing, variable initialization, and function return values. + + /// CheckAssignmentConstraints - Perform type checking for assignment, + /// argument passing, variable initialization, and function return values. /// This routine is only used by the following two methods. C99 6.5.16. AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs); - - // CheckSingleAssignmentConstraints - Currently used by - // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, + + // CheckSingleAssignmentConstraints - Currently used by + // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, // this routine performs the default function/array converions. - AssignConvertType CheckSingleAssignmentConstraints(QualType lhs, + AssignConvertType CheckSingleAssignmentConstraints(QualType lhs, Expr *&rExpr); // \brief If the lhs type is a transparent union, check whether we // can initialize the transparent union with the given expression. - AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs, + AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs, Expr *&rExpr); - + // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1) - AssignConvertType CheckPointerTypesForAssignment(QualType lhsType, + AssignConvertType CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType); - + // Helper function for CheckAssignmentConstraints involving two // block pointer types. - AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType, + AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType, QualType rhsType); bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); - bool PerformImplicitConversion(Expr *&From, QualType ToType, + bool PerformImplicitConversion(Expr *&From, QualType ToType, const char *Flavor, bool AllowExplicit = false, bool Elidable = false); - bool PerformImplicitConversion(Expr *&From, QualType ToType, + bool PerformImplicitConversion(Expr *&From, QualType ToType, const ImplicitConversionSequence& ICS, const char *Flavor); bool PerformImplicitConversion(Expr *&From, QualType ToType, @@ -3450,7 +3450,7 @@ public: inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex); inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx, SourceLocation l, bool isRel); - + /// type checking unary operators (subroutines of ActOnUnaryOp). /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc, @@ -3458,20 +3458,20 @@ public: QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc); QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc); QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal); - + /// type checking primary expressions. QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc, - const IdentifierInfo *Comp, + const IdentifierInfo *Comp, SourceLocation CmpLoc); - + /// type checking declaration initializers (C99 6.7.8) - + bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType, SourceLocation InitLoc,DeclarationName InitEntity, bool DirectInit); bool CheckInitList(InitListExpr *&InitList, QualType &DeclType); bool CheckForConstantInitializer(Expr *e, QualType t); - + bool CheckValueInitialization(QualType Type, SourceLocation Loc); // type checking C++ declaration initializers (C++ [dcl.init]). @@ -3509,17 +3509,17 @@ public: /// CheckCastTypes - Check type constraints for casting between types under /// C semantics, or forward to CXXCheckCStyleCast in C++. bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr, - CastExpr::CastKind &Kind, + CastExpr::CastKind &Kind, CXXMethodDecl *& ConversionDecl, bool FunctionalStyle = false); - // CheckVectorCast - check type constraints for vectors. + // CheckVectorCast - check type constraints for vectors. // Since vectors are an extension, there are no C standard reference for this. // We allow casting between vectors and integer datatypes of the same size. // returns true if the cast is invalid bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty); - - // CheckExtVectorCast - check type constraints for extended vectors. + + // CheckExtVectorCast - check type constraints for extended vectors. // Since vectors are an extension, there are no C standard reference for this. // We allow casting between vectors and integer datatypes of the same size, // or vectors and the element type of that vector. @@ -3532,14 +3532,14 @@ public: CastExpr::CastKind &Kind, bool FunctionalStyle, CXXMethodDecl *&ConversionDecl); - /// CheckMessageArgumentTypes - Check types in an Obj-C message send. + /// CheckMessageArgumentTypes - Check types in an Obj-C message send. /// \param Method - May be null. /// \param [out] ReturnType - The return type of the send. /// \return true iff there were any incompatible types. bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, ObjCMethodDecl *Method, bool isClassMessage, SourceLocation lbrac, SourceLocation rbrac, - QualType &ReturnType); + QualType &ReturnType); /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. bool CheckCXXBooleanCondition(Expr *&CondExpr); @@ -3547,10 +3547,10 @@ public: /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have /// the specified width and sign. If an overflow occurs, detect it and emit /// the specified diagnostic. - void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, + void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, unsigned NewWidth, bool NewSign, SourceLocation Loc, unsigned DiagID); - + /// Checks that the Objective-C declaration is declared in the global scope. /// Emits an error and marks the declaration as invalid if it's not declared /// in the global scope. @@ -3564,22 +3564,22 @@ public: bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0); /// VerifyBitField - verifies that a bit field expression is an ICE and has - /// the correct width, and that the field type is valid. + /// the correct width, and that the field type is valid. /// Returns false on success. /// Can optionally return whether the bit-field is of width 0 - bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, - QualType FieldTy, const Expr *BitWidth, + bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, + QualType FieldTy, const Expr *BitWidth, bool *ZeroWidth = 0); void DiagnoseMissingMember(SourceLocation MemberLoc, DeclarationName Member, NestedNameSpecifier *NNS, SourceRange Range); - + //===--------------------------------------------------------------------===// // Extra semantic analysis beyond the C type system private: bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall); bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall); - + SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, unsigned ByteNo) const; bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall); @@ -3597,7 +3597,7 @@ public: Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); private: - bool SemaBuiltinPrefetch(CallExpr *TheCall); + bool SemaBuiltinPrefetch(CallExpr *TheCall); bool SemaBuiltinObjectSize(CallExpr *TheCall); bool SemaBuiltinLongjmp(CallExpr *TheCall); bool SemaBuiltinAtomicOverloaded(CallExpr *TheCall); @@ -3607,9 +3607,9 @@ private: void CheckPrintfString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, const CallExpr *TheCall, bool HasVAListArg, unsigned format_idx, unsigned firstDataArg); - void CheckNonNullArguments(const NonNullAttr *NonNull, + void CheckNonNullArguments(const NonNullAttr *NonNull, const CallExpr *TheCall); - void CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg, + void CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg, unsigned format_idx, unsigned firstDataArg); void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, SourceLocation ReturnLoc); @@ -3623,12 +3623,12 @@ template <typename T> class ExprOwningPtr : public Action::ExprArg { public: ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {} - + void reset(T* p) { Action::ExprArg::operator=(p); } T* get() const { return static_cast<T*>(Action::ExprArg::get()); } T* take() { return static_cast<T*>(Action::ExprArg::take()); } T* release() { return take(); } - + T& operator*() const { return *get(); } T* operator->() const { return get(); } }; diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp index 31d8a3f5ab..e1a7378061 100644 --- a/lib/Sema/SemaAccess.cpp +++ b/lib/Sema/SemaAccess.cpp @@ -19,7 +19,7 @@ using namespace clang; /// SetMemberAccessSpecifier - Set the access specifier of a member. /// Returns true on error (when the previous member decl access specifier /// is different from the new member decl access specifier). -bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, +bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, NamedDecl *PrevMemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { @@ -27,18 +27,18 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, MemberDecl->setAccess(LexicalAS); return false; } - + // C++ [class.access.spec]p3: When a member is redeclared its access // specifier must be same as its initial declaration. if (LexicalAS != AS_none && LexicalAS != PrevMemberDecl->getAccess()) { - Diag(MemberDecl->getLocation(), - diag::err_class_redeclared_with_different_access) + Diag(MemberDecl->getLocation(), + diag::err_class_redeclared_with_different_access) << MemberDecl << LexicalAS; Diag(PrevMemberDecl->getLocation(), diag::note_previous_access_declaration) << PrevMemberDecl << PrevMemberDecl->getAccess(); return true; } - + MemberDecl->setAccess(PrevMemberDecl->getAccess()); return false; } @@ -47,10 +47,9 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, /// inaccessible. If @p NoPrivileges is true, special access rights (members /// and friends) are not considered. const CXXBaseSpecifier *Sema::FindInaccessibleBase( - QualType Derived, QualType Base, BasePaths &Paths, bool NoPrivileges) -{ + QualType Derived, QualType Base, BasePaths &Paths, bool NoPrivileges) { Base = Context.getCanonicalType(Base).getUnqualifiedType(); - assert(!Paths.isAmbiguous(Base) && + assert(!Paths.isAmbiguous(Base) && "Can't check base class access if set of paths is ambiguous"); assert(Paths.isRecordingPaths() && "Can't check base class access without recorded paths"); @@ -105,7 +104,7 @@ const CXXBaseSpecifier *Sema::FindInaccessibleBase( /// CheckBaseClassAccess - Check that a derived class can access its base class /// and report an error if it can't. [class.access.base] -bool Sema::CheckBaseClassAccess(QualType Derived, QualType Base, +bool Sema::CheckBaseClassAccess(QualType Derived, QualType Base, unsigned InaccessibleBaseID, BasePaths &Paths, SourceLocation AccessLoc, DeclarationName Name) { @@ -116,7 +115,7 @@ bool Sema::CheckBaseClassAccess(QualType Derived, QualType Base, Derived, Base, Paths); if (InaccessibleBase) { - Diag(AccessLoc, InaccessibleBaseID) + Diag(AccessLoc, InaccessibleBaseID) << Derived << Base << Name; AccessSpecifier AS = InaccessibleBase->getAccessSpecifierAsWritten(); diff --git a/lib/Sema/SemaAttr.cpp b/lib/Sema/SemaAttr.cpp index 6622d53659..702e120f9c 100644 --- a/lib/Sema/SemaAttr.cpp +++ b/lib/Sema/SemaAttr.cpp @@ -32,8 +32,8 @@ namespace { /// Stack - Entries in the #pragma pack stack, consisting of saved /// alignments and optional names. stack_ty Stack; - - public: + + public: PragmaPackStack() : Alignment(0) {} void setAlignment(unsigned A) { Alignment = A; } @@ -56,14 +56,14 @@ namespace { bool PragmaPackStack::pop(IdentifierInfo *Name) { if (Stack.empty()) return false; - + // If name is empty just pop top. if (!Name) { Alignment = Stack.back().first; Stack.pop_back(); return true; - } - + } + // Otherwise, find the named record. for (unsigned i = Stack.size(); i != 0; ) { --i; @@ -74,7 +74,7 @@ bool PragmaPackStack::pop(IdentifierInfo *Name) { return true; } } - + return false; } @@ -93,8 +93,8 @@ unsigned Sema::getPragmaPackAlignment() const { return 0; } -void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, - ExprTy *alignment, SourceLocation PragmaLoc, +void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, + ExprTy *alignment, SourceLocation PragmaLoc, SourceLocation LParenLoc, SourceLocation RParenLoc) { Expr *Alignment = static_cast<Expr *>(alignment); @@ -102,7 +102,7 @@ void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, unsigned AlignmentVal = 0; if (Alignment) { llvm::APSInt Val; - + // pack(0) is like pack(), which just works out since that is what // we use 0 for in PackAttr. if (!Alignment->isIntegerConstantExpr(Val, Context) || @@ -115,12 +115,12 @@ void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, AlignmentVal = (unsigned) Val.getZExtValue(); } - + if (PackContext == 0) PackContext = new PragmaPackStack(); - + PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext); - + switch (Kind) { case Action::PPK_Default: // pack([n]) Context->setAlignment(AlignmentVal); @@ -140,15 +140,15 @@ void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, Context->push(Name); // Set the new alignment if specified. if (Alignment) - Context->setAlignment(AlignmentVal); + Context->setAlignment(AlignmentVal); break; case Action::PPK_Pop: // pack(pop [, id] [, n]) // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack: // "#pragma pack(pop, identifier, n) is undefined" if (Alignment && Name) - Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifer_and_alignment); - + Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifer_and_alignment); + // Do the pop. if (!Context->pop(Name)) { // If a name was specified then failure indicates the name @@ -178,7 +178,7 @@ void Sema::ActOnPragmaUnused(const Token *Identifiers, unsigned NumIdentifiers, for (unsigned i = 0; i < NumIdentifiers; ++i) { const Token &Tok = Identifiers[i]; - IdentifierInfo *Name = Tok.getIdentifierInfo(); + IdentifierInfo *Name = Tok.getIdentifierInfo(); const LookupResult &Lookup = LookupParsedName(curScope, NULL, Name, LookupOrdinaryName, false, true, @@ -187,18 +187,18 @@ void Sema::ActOnPragmaUnused(const Token *Identifiers, unsigned NumIdentifiers, NamedDecl *ND = Lookup.getAsDecl(); - if (!ND) { + if (!ND) { Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var) << Name << SourceRange(Tok.getLocation()); continue; } - + if (!isa<VarDecl>(ND) || !cast<VarDecl>(ND)->hasLocalStorage()) { Diag(PragmaLoc, diag::warn_pragma_unused_expected_localvar) << Name << SourceRange(Tok.getLocation()); continue; } - + ND->addAttr(::new (Context) UnusedAttr()); } } diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index ceb2de7ae8..ac85b79b39 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -47,7 +47,7 @@ static void CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType, CastExpr::CastKind &Kind); static void CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType, const SourceRange &OpRange, - const SourceRange &DestRange, + const SourceRange &DestRange, CastExpr::CastKind &Kind); static bool CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType); @@ -89,7 +89,7 @@ static TryCastResult TryStaticImplicitCast(Sema &Self, Expr *SrcExpr, CXXMethodDecl *&ConversionDecl); static TryCastResult TryStaticCast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, - CastExpr::CastKind &Kind, + CastExpr::CastKind &Kind, const SourceRange &OpRange, unsigned &msg, CXXMethodDecl *&ConversionDecl); @@ -97,7 +97,7 @@ static TryCastResult TryConstCast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, unsigned &msg); static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, - CastExpr::CastKind &Kind, + CastExpr::CastKind &Kind, const SourceRange &OpRange, unsigned &msg); @@ -158,8 +158,7 @@ Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, /// the cast checkers. Both arguments must denote pointer (possibly to member) /// types. bool -CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType) -{ +CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType) { // Casting away constness is defined in C++ 5.2.11p8 with reference to // C++ 4.4. We piggyback on Sema::IsQualificationConversion for this, since // the rules are non-trivial. So first we construct Tcv *...cv* as described @@ -185,8 +184,7 @@ CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType) QualType DestConstruct = Self.Context.VoidTy; for (llvm::SmallVector<unsigned, 8>::reverse_iterator i1 = cv1.rbegin(), i2 = cv2.rbegin(); - i1 != cv1.rend(); ++i1, ++i2) - { + i1 != cv1.rend(); ++i1, ++i2) { SrcConstruct = Self.Context.getPointerType( SrcConstruct.getQualifiedType(*i1)); DestConstruct = Self.Context.getPointerType( @@ -204,8 +202,7 @@ CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType) static void CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType, const SourceRange &OpRange, - const SourceRange &DestRange, CastExpr::CastKind &Kind) -{ + const SourceRange &DestRange, CastExpr::CastKind &Kind) { QualType OrigDestType = DestType, OrigSrcType = SrcExpr->getType(); DestType = Self.Context.getCanonicalType(DestType); @@ -325,8 +322,7 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType, /// legacy_function(const_cast\<char*\>(str)); void CheckConstCast(Sema &Self, Expr *&SrcExpr, QualType DestType, - const SourceRange &OpRange, const SourceRange &DestRange) -{ + const SourceRange &OpRange, const SourceRange &DestRange) { if (!DestType->isLValueReferenceType()) Self.DefaultFunctionArrayConversion(SrcExpr); @@ -344,8 +340,7 @@ CheckConstCast(Sema &Self, Expr *&SrcExpr, QualType DestType, /// char *bytes = reinterpret_cast\<char*\>(int_ptr); void CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType, - const SourceRange &OpRange, const SourceRange &DestRange) -{ + const SourceRange &OpRange, const SourceRange &DestRange) { if (!DestType->isLValueReferenceType()) Self.DefaultFunctionArrayConversion(SrcExpr); @@ -364,8 +359,7 @@ CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType, /// implicit conversions explicit and getting rid of data loss warnings. void CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType, - const SourceRange &OpRange, CastExpr::CastKind &Kind) -{ + const SourceRange &OpRange, CastExpr::CastKind &Kind) { // This test is outside everything else because it's the only case where // a non-lvalue-reference target type does not lead to decay. // C++ 5.2.9p4: Any expression can be explicitly converted to type "cv void". @@ -378,7 +372,7 @@ CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType, unsigned msg = diag::err_bad_cxx_cast_generic; CXXMethodDecl *ConversionDecl = 0; - if (TryStaticCast(Self, SrcExpr, DestType, /*CStyle*/false, Kind, + if (TryStaticCast(Self, SrcExpr, DestType, /*CStyle*/false, Kind, OpRange, msg, ConversionDecl) != TC_Success && msg != 0) Self.Diag(OpRange.getBegin(), msg) << CT_Static @@ -390,10 +384,9 @@ CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType, /// and casting away constness. static TryCastResult TryStaticCast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, - CastExpr::CastKind &Kind, + CastExpr::CastKind &Kind, const SourceRange &OpRange, unsigned &msg, - CXXMethodDecl *&ConversionDecl) -{ + CXXMethodDecl *&ConversionDecl) { // The order the tests is not entirely arbitrary. There is one conversion // that can be handled in two different ways. Given: // struct A {}; @@ -500,8 +493,7 @@ static TryCastResult TryStaticCast(Sema &Self, Expr *SrcExpr, /// Tests whether a conversion according to N2844 is valid. TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, QualType DestType, - unsigned &msg) -{ + unsigned &msg) { // N2844 5.2.9p3: An lvalue of type "cv1 T1" can be cast to type "rvalue // reference to cv2 T2" if "cv2 T2" is reference-compatible with "cv1 T1". const RValueReferenceType *R = DestType->getAs<RValueReferenceType>(); @@ -531,8 +523,7 @@ TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, QualType DestType, TryCastResult TryStaticReferenceDowncast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, const SourceRange &OpRange, - unsigned &msg) -{ + unsigned &msg) { // C++ 5.2.9p5: An lvalue of type "cv1 B", where B is a class type, can be // cast to type "reference to cv2 D", where D is a class derived from B, // if a valid standard conversion from "pointer to D" to "pointer to B" @@ -562,8 +553,8 @@ TryStaticReferenceDowncast(Sema &Self, Expr *SrcExpr, QualType DestType, /// Tests whether a conversion according to C++ 5.2.9p8 is valid. TryCastResult TryStaticPointerDowncast(Sema &Self, QualType SrcType, QualType DestType, - bool CStyle, const SourceRange &OpRange, unsigned &msg) -{ + bool CStyle, const SourceRange &OpRange, + unsigned &msg) { // C++ 5.2.9p8: An rvalue of type "pointer to cv1 B", where B is a class // type, can be converted to an rvalue of type "pointer to cv2 D", where D // is a class derived from B, if a valid standard conversion from "pointer @@ -594,8 +585,7 @@ TryStaticPointerDowncast(Sema &Self, QualType SrcType, QualType DestType, TryCastResult TryStaticDowncast(Sema &Self, QualType SrcType, QualType DestType, bool CStyle, const SourceRange &OpRange, QualType OrigSrcType, - QualType OrigDestType, unsigned &msg) -{ + QualType OrigDestType, unsigned &msg) { // Downcast can only happen in class hierarchies, so we need classes. if (!DestType->isRecordType() || !SrcType->isRecordType()) { return TC_NotApplicable; @@ -614,7 +604,7 @@ TryStaticDowncast(Sema &Self, QualType SrcType, QualType DestType, // struct B : virtual A { // B(A&); // }; - // + // // void f() // { // (void)static_cast<const B&>(*((A*)0)); @@ -691,8 +681,7 @@ TryStaticDowncast(Sema &Self, QualType SrcType, QualType DestType, TryCastResult TryStaticMemberPointerUpcast(Sema &Self, QualType SrcType, QualType DestType, bool CStyle, const SourceRange &OpRange, - unsigned &msg) -{ + unsigned &msg) { const MemberPointerType *DestMemPtr = DestType->getAs<MemberPointerType>(); if (!DestMemPtr) return TC_NotApplicable; @@ -757,8 +746,7 @@ TryStaticMemberPointerUpcast(Sema &Self, QualType SrcType, QualType DestType, TryCastResult TryStaticImplicitCast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, const SourceRange &OpRange, unsigned &msg, - CXXMethodDecl *&ConversionDecl) -{ + CXXMethodDecl *&ConversionDecl) { if (DestType->isRecordType()) { if (Self.RequireCompleteType(OpRange.getBegin(), DestType, diag::err_bad_dynamic_cast_incomplete)) { @@ -766,7 +754,7 @@ TryStaticImplicitCast(Sema &Self, Expr *SrcExpr, QualType DestType, return TC_Failed; } } - + if (DestType->isReferenceType()) { // At this point of CheckStaticCast, if the destination is a reference, // this has to work. There is no other way that works. @@ -774,7 +762,7 @@ TryStaticImplicitCast(Sema &Self, Expr *SrcExpr, QualType DestType, // the reinterpret_cast way. In that case, we pass an ICS so we don't // get error messages. ImplicitConversionSequence ICS; - bool failed = Self.CheckReferenceInit(SrcExpr, DestType, + bool failed = Self.CheckReferenceInit(SrcExpr, DestType, /*SuppressUserConversions=*/false, /*AllowExplicit=*/false, /*ForceRValue=*/false, @@ -792,15 +780,15 @@ TryStaticImplicitCast(Sema &Self, Expr *SrcExpr, QualType DestType, // reimplement more of this. // FIXME: This does not actually perform the conversion, and thus does not // check for ambiguity or access. - ImplicitConversionSequence ICS = + ImplicitConversionSequence ICS = Self.TryImplicitConversion(SrcExpr, DestType, /*SuppressUserConversions=*/false, /*AllowExplicit=*/true, /*ForceRValue=*/false, /*InOverloadResolution=*/false); - + if (ICS.ConversionKind == ImplicitConversionSequence::UserDefinedConversion) - if (CXXMethodDecl *MD = + if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(ICS.UserDefined.ConversionFunction)) ConversionDecl = MD; return ICS.ConversionKind == ImplicitConversionSequence::BadConversion ? @@ -1032,8 +1020,7 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr, bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr, CastExpr::CastKind &Kind, bool FunctionalStyle, - CXXMethodDecl *&ConversionDecl) -{ + CXXMethodDecl *&ConversionDecl) { // This test is outside everything else because it's the only case where // a non-lvalue-reference target type does not lead to decay. // C++ 5.2.9p4: Any expression can be explicitly converted to type "cv void". @@ -1067,7 +1054,7 @@ bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr, ConversionDecl); if (tcr == TC_NotApplicable) { // ... and finally a reinterpret_cast, ignoring const. - tcr = TryReinterpretCast(*this, CastExpr, CastTy, /*CStyle*/true, Kind, + tcr = TryReinterpretCast(*this, CastExpr, CastTy, /*CStyle*/true, Kind, R, msg); } } diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp index fb6c88ebc4..759b56ced2 100644 --- a/lib/Sema/SemaCXXScopeSpec.cpp +++ b/lib/Sema/SemaCXXScopeSpec.cpp @@ -26,13 +26,13 @@ using namespace clang; /// /// \param T the type for which we are attempting to find a DeclContext. /// -/// \returns the declaration context represented by the type T, +/// \returns the declaration context represented by the type T, /// or NULL if the declaration context cannot be computed (e.g., because it is /// dependent and not the current instantiation). DeclContext *Sema::computeDeclContext(QualType T) { if (const TagType *Tag = T->getAs<TagType>()) return Tag->getDecl(); - + return 0; } @@ -54,21 +54,21 @@ DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS, if (!SS.isSet() || SS.isInvalid()) return 0; - NestedNameSpecifier *NNS + NestedNameSpecifier *NNS = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); if (NNS->isDependent()) { // If this nested-name-specifier refers to the current // instantiation, return its DeclContext. if (CXXRecordDecl *Record = getCurrentInstantiationOf(NNS)) return Record; - + if (EnteringContext) { if (const TemplateSpecializationType *SpecType = dyn_cast_or_null<TemplateSpecializationType>(NNS->getAsType())) { // We are entering the context of the nested name specifier, so try to // match the nested name specifier to either a primary class template // or a class template partial specialization. - if (ClassTemplateDecl *ClassTemplate + if (ClassTemplateDecl *ClassTemplate = dyn_cast_or_null<ClassTemplateDecl>( SpecType->getTemplateName().getAsTemplateDecl())) { QualType ContextType @@ -80,7 +80,7 @@ DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS, QualType Injected = ClassTemplate->getInjectedClassNameType(Context); if (Context.hasSameType(Injected, ContextType)) return ClassTemplate->getTemplatedDecl(); - + // If the type of the nested name specifier is the same as the // type of one of the class template's class template partial // specializations, we're entering into the definition of that @@ -89,13 +89,13 @@ DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS, = ClassTemplate->findPartialSpecialization(ContextType)) return PartialSpec; } - } else if (const RecordType *RecordT + } else if (const RecordType *RecordT = dyn_cast_or_null<RecordType>(NNS->getAsType())) { // The nested name specifier refers to a member of a class template. return RecordT->getDecl(); } } - + return 0; } @@ -126,7 +126,7 @@ bool Sema::isDependentScopeSpecifier(const CXXScopeSpec &SS) { if (!SS.isSet() || SS.isInvalid()) return false; - NestedNameSpecifier *NNS + NestedNameSpecifier *NNS = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); return NNS->isDependent(); } @@ -138,7 +138,7 @@ bool Sema::isUnknownSpecialization(const CXXScopeSpec &SS) { if (!isDependentScopeSpecifier(SS)) return false; - NestedNameSpecifier *NNS + NestedNameSpecifier *NNS = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); return getCurrentInstantiationOf(NNS) == 0; } @@ -154,7 +154,7 @@ CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) { if (!NNS->getAsType()) return 0; - + QualType T = QualType(NNS->getAsType(), 0); // If the nested name specifier does not refer to a type, then it // does not refer to the current instantiation. @@ -174,7 +174,7 @@ CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) { if (!Record) continue; - // If this record type is not dependent, + // If this record type is not dependent, if (!Record->isDependentType()) return 0; @@ -192,13 +192,13 @@ CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) { // enclosed in <>, // -- in the definition of a nested class of a class template, // the name of the nested class referenced as a member of - // the current instantiation, or + // the current instantiation, or // -- in the definition of a partial specialization, the name // of the class template followed by the template argument // list of the partial specialization enclosed in <>. If // the nth template parameter is a parameter pack, the nth // template argument is a pack expansion (14.6.3) whose - // pattern is the name of the parameter pack. + // pattern is the name of the parameter pack. // (FIXME: parameter packs) // // All of these options come down to having the @@ -207,9 +207,9 @@ CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) { // our context. if (Context.getCanonicalType(Context.getTypeDeclType(Record)) == T) return Record; - + if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) { - QualType InjectedClassName + QualType InjectedClassName = Template->getInjectedClassNameType(Context); if (T == Context.getCanonicalType(InjectedClassName)) return Template->getTemplatedDecl(); @@ -232,7 +232,7 @@ CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) { bool Sema::RequireCompleteDeclContext(const CXXScopeSpec &SS) { if (!SS.isSet() || SS.isInvalid()) return false; - + DeclContext *DC = computeDeclContext(SS, true); if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) { // If we're currently defining this type, then lookup into the @@ -263,14 +263,14 @@ Sema::CXXScopeTy *Sema::ActOnCXXGlobalScopeSpecifier(Scope *S, bool isAcceptableNestedNameSpecifier(ASTContext &Context, NamedDecl *SD) { if (!SD) return false; - + // Namespace and namespace aliases are fine. if (isa<NamespaceDecl>(SD) || isa<NamespaceAliasDecl>(SD)) return true; - + if (!isa<TypeDecl>(SD)) return false; - + // Determine whether we have a class (or, in C++0x, an enum) or // a typedef thereof. If so, build the nested-name-specifier. QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD)); @@ -278,10 +278,10 @@ bool isAcceptableNestedNameSpecifier(ASTContext &Context, NamedDecl *SD) { return true; else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(SD)) { if (TD->getUnderlyingType()->isRecordType() || - (Context.getLangOptions().CPlusPlus0x && + (Context.getLangOptions().CPlusPlus0x && TD->getUnderlyingType()->isEnumeralType())) return true; - } else if (isa<RecordDecl>(SD) || + } else if (isa<RecordDecl>(SD) || (Context.getLangOptions().CPlusPlus0x && isa<EnumDecl>(SD))) return true; @@ -289,27 +289,27 @@ bool isAcceptableNestedNameSpecifier(ASTContext &Context, NamedDecl *SD) { } /// \brief If the given nested-name-specifier begins with a bare identifier -/// (e.g., Base::), perform name lookup for that identifier as a +/// (e.g., Base::), perform name lookup for that identifier as a /// nested-name-specifier within the given scope, and return the result of that /// name lookup. NamedDecl *Sema::FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS) { if (!S || !NNS) return 0; - + while (NNS->getPrefix()) NNS = NNS->getPrefix(); - + if (NNS->getKind() != NestedNameSpecifier::Identifier) return 0; - - LookupResult Found + + LookupResult Found = LookupName(S, NNS->getAsIdentifier(), LookupNestedNameSpecifierName); assert(!Found.isAmbiguous() && "Cannot handle ambiguities here yet"); NamedDecl *Result = Found; if (isAcceptableNestedNameSpecifier(Context, Result)) return Result; - + return 0; } @@ -328,9 +328,9 @@ Sema::CXXScopeTy *Sema::BuildCXXNestedNameSpecifier(Scope *S, QualType ObjectType, NamedDecl *ScopeLookupResult, bool EnteringContext) { - NestedNameSpecifier *Prefix + NestedNameSpecifier *Prefix = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); - + // Determine where to perform name lookup DeclContext *LookupCtx = 0; bool isDependent = false; @@ -346,70 +346,70 @@ Sema::CXXScopeTy *Sema::BuildCXXNestedNameSpecifier(Scope *S, LookupCtx = computeDeclContext(SS, EnteringContext); isDependent = isDependentScopeSpecifier(SS); } - + LookupResult Found; bool ObjectTypeSearchedInScope = false; if (LookupCtx) { - // Perform "qualified" name lookup into the declaration context we + // Perform "qualified" name lookup into the declaration context we // computed, which is either the type of the base of a member access - // expression or the declaration context associated with a prior + // expression or the declaration context associated with a prior // nested-name-specifier. - + // The declaration context must be complete. if (!LookupCtx->isDependentContext() && RequireCompleteDeclContext(SS)) return 0; - + Found = LookupQualifiedName(LookupCtx, &II, LookupNestedNameSpecifierName, false); - + if (!ObjectType.isNull() && Found.getKind() == LookupResult::NotFound) { // C++ [basic.lookup.classref]p4: // If the id-expression in a class member access is a qualified-id of - // the form + // the form // // class-name-or-namespace-name::... // - // the class-name-or-namespace-name following the . or -> operator is - // looked up both in the context of the entire postfix-expression and in + // the class-name-or-namespace-name following the . or -> operator is + // looked up both in the context of the entire postfix-expression and in // the scope of the class of the object expression. If the name is found - // only in the scope of the class of the object expression, the name - // shall refer to a class-name. If the name is found only in the + // only in the scope of the class of the object expression, the name + // shall refer to a class-name. If the name is found only in the // context of the entire postfix-expression, the name shall refer to a // class-name or namespace-name. [...] // // Qualified name lookup into a class will not find a namespace-name, - // so we do not need to diagnoste that case specifically. However, + // so we do not need to diagnoste that case specifically. However, // this qualified name lookup may find nothing. In that case, perform - // unqualified name lookup in the given scope (if available) or + // unqualified name lookup in the given scope (if available) or // reconstruct the result from when name lookup was performed at template // definition time. if (S) Found = LookupName(S, &II, LookupNestedNameSpecifierName); else Found = LookupResult::CreateLookupResult(Context, ScopeLookupResult); - + ObjectTypeSearchedInScope = true; } } else if (isDependent) { // We were not able to compute the declaration context for a dependent - // base object type or prior nested-name-specifier, so this + // base object type or prior nested-name-specifier, so this // nested-name-specifier refers to an unknown specialization. Just build // a dependent nested-name-specifier. if (!Prefix) return NestedNameSpecifier::Create(Context, &II); - + return NestedNameSpecifier::Create(Context, Prefix, &II); } else { // Perform unqualified name lookup in the current scope. Found = LookupName(S, &II, LookupNestedNameSpecifierName); } - + // FIXME: Deal with ambiguities cleanly. NamedDecl *SD = Found; if (isAcceptableNestedNameSpecifier(Context, SD)) { if (!ObjectType.isNull() && !ObjectTypeSearchedInScope) { // C++ [basic.lookup.classref]p4: - // [...] If the name is found in both contexts, the + // [...] If the name is found in both contexts, the // class-name-or-namespace-name shall refer to the same entity. // // We already found the name in the scope of the object. Now, look @@ -420,9 +420,9 @@ Sema::CXXScopeTy *Sema::BuildCXXNestedNameSpecifier(Scope *S, if (S) FoundOuter = LookupName(S, &II, LookupNestedNameSpecifierName); else - FoundOuter = LookupResult::CreateLookupResult(Context, + FoundOuter = LookupResult::CreateLookupResult(Context, ScopeLookupResult); - + // FIXME: Handle ambiguities in FoundOuter! NamedDecl *OuterDecl = FoundOuter; if (isAcceptableNestedNameSpecifier(Context, OuterDecl) && @@ -436,50 +436,50 @@ Sema::CXXScopeTy *Sema::BuildCXXNestedNameSpecifier(Scope *S, Diag(SD->getLocation(), diag::note_ambig_member_ref_object_type) << ObjectType; Diag(OuterDecl->getLocation(), diag::note_ambig_member_ref_scope); - + // Fall through so that we'll pick the name we found in the object type, // since that's probably what the user wanted anyway. } } - + if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD)) return NestedNameSpecifier::Create(Context, Prefix, Namespace); - + // FIXME: It would be nice to maintain the namespace alias name, then // see through that alias when resolving the nested-name-specifier down to // a declaration context. if (NamespaceAliasDecl *Alias = dyn_cast<NamespaceAliasDecl>(SD)) return NestedNameSpecifier::Create(Context, Prefix, - + Alias->getNamespace()); - + QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD)); return NestedNameSpecifier::Create(Context, Prefix, false, T.getTypePtr()); } - + // If we didn't find anything during our lookup, try again with // ordinary name lookup, which can help us produce better error // messages. if (!SD) SD = LookupName(S, &II, LookupOrdinaryName); - + unsigned DiagID; if (SD) DiagID = diag::err_expected_class_or_namespace; else if (SS.isSet()) { - DiagnoseMissingMember(IdLoc, DeclarationName(&II), - (NestedNameSpecifier *)SS.getScopeRep(), + DiagnoseMissingMember(IdLoc, DeclarationName(&II), + (NestedNameSpecifier *)SS.getScopeRep(), SS.getRange()); return 0; } else DiagID = diag::err_undeclared_var_use; - + if (SS.isSet()) Diag(IdLoc, DiagID) << &II << SS.getRange(); else Diag(IdLoc, DiagID) << &II; - + return 0; } @@ -496,7 +496,7 @@ Sema::CXXScopeTy *Sema::ActOnCXXNestedNameSpecifier(Scope *S, IdentifierInfo &II, TypeTy *ObjectTypePtr, bool EnteringContext) { - return BuildCXXNestedNameSpecifier(S, SS, IdLoc, CCLoc, II, + return BuildCXXNestedNameSpecifier(S, SS, IdLoc, CCLoc, II, QualType::getFromOpaquePtr(ObjectTypePtr), /*ScopeLookupResult=*/0, EnteringContext); } @@ -506,7 +506,7 @@ Sema::CXXScopeTy *Sema::ActOnCXXNestedNameSpecifier(Scope *S, TypeTy *Ty, SourceRange TypeRange, SourceLocation CCLoc) { - NestedNameSpecifier *Prefix + NestedNameSpecifier *Prefix = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); QualType T = GetTypeFromParser(Ty); return NestedNameSpecifier::Create(Context, Prefix, /*FIXME:*/false, diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index a63e044272..5faafada50 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file implements extra semantic analysis beyond what is enforced +// This file implements extra semantic analysis beyond what is enforced // by the C type system. // //===----------------------------------------------------------------------===// @@ -32,14 +32,14 @@ using namespace clang; SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL, unsigned ByteNo) const { assert(!SL->isWide() && "This doesn't work for wide strings yet"); - + // Loop over all of the tokens in this string until we find the one that // contains the byte we're looking for. unsigned TokNo = 0; while (1) { assert(TokNo < SL->getNumConcatenated() && "Invalid byte number!"); SourceLocation StrTokLoc = SL->getStrTokenLoc(TokNo); - + // Get the spelling of the string so that we can get the data that makes up // the string literal, not the identifier for the macro it is potentially // expanded through. @@ -51,33 +51,33 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL, std::pair<const char *,const char *> Buffer = SourceMgr.getBufferData(LocInfo.first); const char *StrData = Buffer.first+LocInfo.second; - + // Create a langops struct and enable trigraphs. This is sufficient for // relexing tokens. LangOptions LangOpts; LangOpts.Trigraphs = true; - + // Create a lexer starting at the beginning of this token. Lexer TheLexer(StrTokSpellingLoc, LangOpts, Buffer.first, StrData, Buffer.second); Token TheTok; TheLexer.LexFromRawLexer(TheTok); - + // Use the StringLiteralParser to compute the length of the string in bytes. StringLiteralParser SLP(&TheTok, 1, PP); unsigned TokNumBytes = SLP.GetStringLength(); - + // If the byte is in this token, return the location of the byte. if (ByteNo < TokNumBytes || (ByteNo == TokNumBytes && TokNo == SL->getNumConcatenated())) { - unsigned Offset = + unsigned Offset = StringLiteralParser::getOffsetOfStringByte(TheTok, ByteNo, PP); - + // Now that we know the offset of the token in the spelling, use the // preprocessor to get the offset in the original source. return PP.AdvanceToTokenCharacter(StrTokLoc, Offset); } - + // Move to the next string token. ++TokNo; ByteNo -= TokNumBytes; @@ -174,7 +174,7 @@ Sema::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { return ExprError(); break; } - + return move(TheCallResult); } @@ -188,7 +188,7 @@ bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) { // simple names (e.g., C++ conversion functions). if (!FnInfo) return false; - + // FIXME: This mechanism should be abstracted to be less fragile and // more efficient. For example, just map function ids to custom // handlers. @@ -198,7 +198,7 @@ bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) { if (CheckablePrintfAttr(Format, TheCall)) { bool HasVAListArg = Format->getFirstArg() == 0; if (!HasVAListArg) { - if (const FunctionProtoType *Proto + if (const FunctionProtoType *Proto = FDecl->getType()->getAsFunctionProtoType()) HasVAListArg = !Proto->isVariadic(); } @@ -206,8 +206,8 @@ bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) { HasVAListArg ? 0 : Format->getFirstArg() - 1); } } - - for (const NonNullAttr *NonNull = FDecl->getAttr<NonNullAttr>(); NonNull; + + for (const NonNullAttr *NonNull = FDecl->getAttr<NonNullAttr>(); NonNull; NonNull = NonNull->getNext<NonNullAttr>()) CheckNonNullArguments(NonNull, TheCall); @@ -219,21 +219,21 @@ bool Sema::CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall) { const FormatAttr *Format = NDecl->getAttr<FormatAttr>(); if (!Format) return false; - + const VarDecl *V = dyn_cast<VarDecl>(NDecl); if (!V) return false; - + QualType Ty = V->getType(); if (!Ty->isBlockPointerType()) return false; - + if (!CheckablePrintfAttr(Format, TheCall)) return false; - + bool HasVAListArg = Format->getFirstArg() == 0; if (!HasVAListArg) { - const FunctionType *FT = + const FunctionType *FT = Ty->getAs<BlockPointerType>()->getPointeeType()->getAsFunctionType(); if (const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FT)) HasVAListArg = !Proto->isVariadic(); @@ -260,7 +260,7 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { if (TheCall->getNumArgs() < 1) return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args) << 0 << TheCall->getCallee()->getSourceRange(); - + // Inspect the first argument of the atomic builtin. This should always be // a pointer type, whose element is an integral scalar or pointer type. // Because it is a pointer type, we don't have to worry about any implicit @@ -269,9 +269,9 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { if (!FirstArg->getType()->isPointerType()) return Diag(DRE->getLocStart(), diag::err_atomic_builtin_must_be_pointer) << FirstArg->getType() << FirstArg->getSourceRange(); - + QualType ValType = FirstArg->getType()->getAs<PointerType>()->getPointeeType(); - if (!ValType->isIntegerType() && !ValType->isPointerType() && + if (!ValType->isIntegerType() && !ValType->isPointerType() && !ValType->isBlockPointerType()) return Diag(DRE->getLocStart(), diag::err_atomic_builtin_must_be_pointer_intptr) @@ -283,7 +283,7 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { #define BUILTIN_ROW(x) \ { Builtin::BI##x##_1, Builtin::BI##x##_2, Builtin::BI##x##_4, \ Builtin::BI##x##_8, Builtin::BI##x##_16 } - + static const unsigned BuiltinIndices[][5] = { BUILTIN_ROW(__sync_fetch_and_add), BUILTIN_ROW(__sync_fetch_and_sub), @@ -291,21 +291,21 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { BUILTIN_ROW(__sync_fetch_and_and), BUILTIN_ROW(__sync_fetch_and_xor), BUILTIN_ROW(__sync_fetch_and_nand), - + BUILTIN_ROW(__sync_add_and_fetch), BUILTIN_ROW(__sync_sub_and_fetch), BUILTIN_ROW(__sync_and_and_fetch), BUILTIN_ROW(__sync_or_and_fetch), BUILTIN_ROW(__sync_xor_and_fetch), BUILTIN_ROW(__sync_nand_and_fetch), - + BUILTIN_ROW(__sync_val_compare_and_swap), BUILTIN_ROW(__sync_bool_compare_and_swap), BUILTIN_ROW(__sync_lock_test_and_set), BUILTIN_ROW(__sync_lock_release) }; -#undef BUILTIN_ROW - +#undef BUILTIN_ROW + // Determine the index of the size. unsigned SizeIndex; switch (Context.getTypeSize(ValType)/8) { @@ -318,7 +318,7 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { return Diag(DRE->getLocStart(), diag::err_atomic_builtin_pointer_size) << FirstArg->getType() << FirstArg->getSourceRange(); } - + // Each of these builtins has one pointer argument, followed by some number of // values (0, 1 or 2) followed by a potentially empty varags list of stuff // that we ignore. Find out which row of BuiltinIndices to read from as well @@ -333,14 +333,14 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { case Builtin::BI__sync_fetch_and_and: BuiltinIndex = 3; break; case Builtin::BI__sync_fetch_and_xor: BuiltinIndex = 4; break; case Builtin::BI__sync_fetch_and_nand:BuiltinIndex = 5; break; - + case Builtin::BI__sync_add_and_fetch: BuiltinIndex = 6; break; case Builtin::BI__sync_sub_and_fetch: BuiltinIndex = 7; break; case Builtin::BI__sync_and_and_fetch: BuiltinIndex = 8; break; case Builtin::BI__sync_or_and_fetch: BuiltinIndex = 9; break; case Builtin::BI__sync_xor_and_fetch: BuiltinIndex =10; break; case Builtin::BI__sync_nand_and_fetch:BuiltinIndex =11; break; - + case Builtin::BI__sync_val_compare_and_swap: BuiltinIndex = 12; NumFixed = 2; @@ -355,37 +355,37 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { NumFixed = 0; break; } - + // Now that we know how many fixed arguments we expect, first check that we // have at least that many. if (TheCall->getNumArgs() < 1+NumFixed) return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args) << 0 << TheCall->getCallee()->getSourceRange(); - - + + // Get the decl for the concrete builtin from this, we can tell what the // concrete integer type we should convert to is. unsigned NewBuiltinID = BuiltinIndices[BuiltinIndex][SizeIndex]; const char *NewBuiltinName = Context.BuiltinInfo.GetName(NewBuiltinID); IdentifierInfo *NewBuiltinII = PP.getIdentifierInfo(NewBuiltinName); - FunctionDecl *NewBuiltinDecl = + FunctionDecl *NewBuiltinDecl = cast<FunctionDecl>(LazilyCreateBuiltin(NewBuiltinII, NewBuiltinID, TUScope, false, DRE->getLocStart())); const FunctionProtoType *BuiltinFT = NewBuiltinDecl->getType()->getAsFunctionProtoType(); ValType = BuiltinFT->getArgType(0)->getAs<PointerType>()->getPointeeType(); - + // If the first type needs to be converted (e.g. void** -> int*), do it now. if (BuiltinFT->getArgType(0) != FirstArg->getType()) { ImpCastExprToType(FirstArg, BuiltinFT->getArgType(0), CastExpr::CK_Unknown, /*isLvalue=*/false); TheCall->setArg(0, FirstArg); } - + // Next, walk the valid ones promoting to the right type. for (unsigned i = 0; i != NumFixed; ++i) { Expr *Arg = TheCall->getArg(i+1); - + // If the argument is an implicit cast, then there was a promotion due to // "...", just remove it now. if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg)) { @@ -394,7 +394,7 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { ICE->Destroy(Context); TheCall->setArg(i+1, Arg); } - + // GCC does an implicit conversion to the pointer or integer ValType. This // can fail in some cases (1i -> int**), check for this error case now. CastExpr::CastKind Kind = CastExpr::CK_Unknown; @@ -402,27 +402,27 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { if (CheckCastTypes(Arg->getSourceRange(), ValType, Arg, Kind, ConversionDecl)) return true; - + // Okay, we have something that *can* be converted to the right type. Check // to see if there is a potentially weird extension going on here. This can // happen when you do an atomic operation on something like an char* and // pass in 42. The 42 gets converted to char. This is even more strange // for things like 45.123 -> char, etc. - // FIXME: Do this check. + // FIXME: Do this check. ImpCastExprToType(Arg, ValType, Kind, /*isLvalue=*/false); TheCall->setArg(i+1, Arg); } - + // Switch the DeclRefExpr to refer to the new decl. DRE->setDecl(NewBuiltinDecl); DRE->setType(NewBuiltinDecl->getType()); - + // Set the callee in the CallExpr. // FIXME: This leaks the original parens and implicit casts. Expr *PromotedCall = DRE; UsualUnaryConversions(PromotedCall); TheCall->setCallee(PromotedCall); - + // Change the result type of the call to match the result type of the decl. TheCall->setType(NewBuiltinDecl->getResultType()); @@ -433,7 +433,7 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { /// CheckObjCString - Checks that the argument to the builtin /// CFString constructor is correct /// FIXME: GCC currently emits the following warning: -/// "warning: input conversion stopped due to an input byte that does not +/// "warning: input conversion stopped due to an input byte that does not /// belong to the input codeset UTF-8" /// Note: It might also make sense to do the UTF-16 conversion here (would /// simplify the backend). @@ -446,10 +446,10 @@ bool Sema::CheckObjCString(Expr *Arg) { << Arg->getSourceRange(); return true; } - + const char *Data = Literal->getStrData(); unsigned Length = Literal->getByteLength(); - + for (unsigned i = 0; i < Length; ++i) { if (!Data[i]) { Diag(getLocationOfStringLiteralByte(Literal, i), @@ -458,7 +458,7 @@ bool Sema::CheckObjCString(Expr *Arg) { break; } } - + return false; } @@ -470,7 +470,7 @@ bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) { Diag(TheCall->getArg(2)->getLocStart(), diag::err_typecheck_call_too_many_args) << 0 /*function call*/ << Fn->getSourceRange() - << SourceRange(TheCall->getArg(2)->getLocStart(), + << SourceRange(TheCall->getArg(2)->getLocStart(), (*(TheCall->arg_end()-1))->getLocEnd()); return true; } @@ -493,17 +493,17 @@ bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) { } else { isVariadic = getCurMethodDecl()->isVariadic(); } - + if (!isVariadic) { Diag(Fn->getLocStart(), diag::err_va_start_used_in_non_variadic_function); return true; } - + // Verify that the second argument to the builtin is the last argument of the // current function or method. bool SecondArgIsLastNamedArgument = false; const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts(); - + if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Arg)) { if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(DR->getDecl())) { // FIXME: This isn't correct for methods (results in bogus warning). @@ -518,9 +518,9 @@ bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) { SecondArgIsLastNamedArgument = PV == LastArg; } } - + if (!SecondArgIsLastNamedArgument) - Diag(TheCall->getArg(1)->getLocStart(), + Diag(TheCall->getArg(1)->getLocStart(), diag::warn_second_parameter_of_va_start_not_last_named_argument); return false; } @@ -532,12 +532,12 @@ bool Sema::SemaBuiltinUnorderedCompare(CallExpr *TheCall) { return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args) << 0 /*function call*/; if (TheCall->getNumArgs() > 2) - return Diag(TheCall->getArg(2)->getLocStart(), + return Diag(TheCall->getArg(2)->getLocStart(), diag::err_typecheck_call_too_many_args) << 0 /*function call*/ << SourceRange(TheCall->getArg(2)->getLocStart(), (*(TheCall->arg_end()-1))->getLocEnd()); - + Expr *OrigArg0 = TheCall->getArg(0); Expr *OrigArg1 = TheCall->getArg(1); @@ -550,18 +550,18 @@ bool Sema::SemaBuiltinUnorderedCompare(CallExpr *TheCall) { // foo(...)". TheCall->setArg(0, OrigArg0); TheCall->setArg(1, OrigArg1); - + if (OrigArg0->isTypeDependent() || OrigArg1->isTypeDependent()) return false; // If the common type isn't a real floating type, then the arguments were // invalid for this operation. if (!Res->isRealFloatingType()) - return Diag(OrigArg0->getLocStart(), + return Diag(OrigArg0->getLocStart(), diag::err_typecheck_call_invalid_ordered_compare) << OrigArg0->getType() << OrigArg1->getType() << SourceRange(OrigArg0->getLocStart(), OrigArg1->getLocEnd()); - + return false; } @@ -572,23 +572,23 @@ bool Sema::SemaBuiltinUnaryFP(CallExpr *TheCall) { return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args) << 0 /*function call*/; if (TheCall->getNumArgs() > 1) - return Diag(TheCall->getArg(1)->getLocStart(), + return Diag(TheCall->getArg(1)->getLocStart(), diag::err_typecheck_call_too_many_args) << 0 /*function call*/ << SourceRange(TheCall->getArg(1)->getLocStart(), (*(TheCall->arg_end()-1))->getLocEnd()); Expr *OrigArg = TheCall->getArg(0); - + if (OrigArg->isTypeDependent()) return false; // This operation requires a floating-point number if (!OrigArg->getType()->isRealFloatingType()) - return Diag(OrigArg->getLocStart(), + return Diag(OrigArg->getLocStart(), diag::err_typecheck_call_invalid_unary_fp) << OrigArg->getType() << OrigArg->getSourceRange(); - + return false; } @@ -600,7 +600,7 @@ bool Sema::SemaBuiltinStackAddress(CallExpr *TheCall) { !TheCall->getArg(0)->isValueDependent() && !TheCall->getArg(0)->isIntegerConstantExpr(Context, &Loc)) return Diag(Loc, diag::err_stack_const_level) << TheCall->getSourceRange(); - + return false; } @@ -617,18 +617,18 @@ Action::OwningExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) { !TheCall->getArg(1)->isTypeDependent()) { QualType FAType = TheCall->getArg(0)->getType(); QualType SAType = TheCall->getArg(1)->getType(); - + if (!FAType->isVectorType() || !SAType->isVectorType()) { Diag(TheCall->getLocStart(), diag::err_shufflevector_non_vector) - << SourceRange(TheCall->getArg(0)->getLocStart(), + << SourceRange(TheCall->getArg(0)->getLocStart(), TheCall->getArg(1)->getLocEnd()); return ExprError(); } - + if (Context.getCanonicalType(FAType).getUnqualifiedType() != Context.getCanonicalType(SAType).getUnqualifiedType()) { Diag(TheCall->getLocStart(), diag::err_shufflevector_incompatible_vector) - << SourceRange(TheCall->getArg(0)->getLocStart(), + << SourceRange(TheCall->getArg(0)->getLocStart(), TheCall->getArg(1)->getLocEnd()); return ExprError(); } @@ -706,7 +706,7 @@ bool Sema::SemaBuiltinPrefetch(CallExpr *TheCall) { if (!Arg->isIntegerConstantExpr(Result, Context)) return Diag(TheCall->getLocStart(), diag::err_prefetch_invalid_argument) << SourceRange(Arg->getLocStart(), Arg->getLocEnd()); - + // FIXME: gcc issues a warning and rewrites these to 0. These // seems especially odd for the third argument since the default // is 3. @@ -732,8 +732,8 @@ bool Sema::SemaBuiltinObjectSize(CallExpr *TheCall) { if (Arg->isTypeDependent()) return false; - QualType ArgType = Arg->getType(); - const BuiltinType *BT = ArgType->getAsBuiltinType(); + QualType ArgType = Arg->getType(); + const BuiltinType *BT = ArgType->getAsBuiltinType(); llvm::APSInt Result(32); if (!BT || BT->getKind() != BuiltinType::Int) return Diag(TheCall->getLocStart(), diag::err_object_size_invalid_argument) @@ -797,10 +797,10 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, return SemaCheckStringLiteral(Expr->getSubExpr(), TheCall, HasVAListArg, format_idx, firstDataArg); } - + case Stmt::DeclRefExprClass: { const DeclRefExpr *DR = cast<DeclRefExpr>(E); - + // As an exception, do not flag errors for variables binding to // const string literals. if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) { @@ -810,17 +810,17 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, if (const ArrayType *AT = Context.getAsArrayType(T)) { isConstant = AT->getElementType().isConstant(Context); } else if (const PointerType *PT = T->getAs<PointerType>()) { - isConstant = T.isConstant(Context) && + isConstant = T.isConstant(Context) && PT->getPointeeType().isConstant(Context); } - + if (isConstant) { const VarDecl *Def = 0; if (const Expr *Init = VD->getDefinition(Def)) return SemaCheckStringLiteral(Init, TheCall, HasVAListArg, format_idx, firstDataArg); } - + // For vprintf* functions (i.e., HasVAListArg==true), we add a // special check to see if the format string is a function parameter // of the function calling the printf function. If the function @@ -843,55 +843,55 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, if (isa<ParmVarDecl>(VD)) return true; } - + return false; } case Stmt::CallExprClass: { const CallExpr *CE = cast<CallExpr>(E); - if (const ImplicitCastExpr *ICE + if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(CE->getCallee())) { if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr())) { if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) { if (const FormatArgAttr *FA = FD->getAttr<FormatArgAttr>()) { unsigned ArgIndex = FA->getFormatIdx(); const Expr *Arg = CE->getArg(ArgIndex - 1); - - return SemaCheckStringLiteral(Arg, TheCall, HasVAListArg, + + return SemaCheckStringLiteral(Arg, TheCall, HasVAListArg, format_idx, firstDataArg); } } } } - + return false; } case Stmt::ObjCStringLiteralClass: case Stmt::StringLiteralClass: { const StringLiteral *StrE = NULL; - + if (const ObjCStringLiteral *ObjCFExpr = dyn_cast<ObjCStringLiteral>(E)) StrE = ObjCFExpr->getString(); else StrE = cast<StringLiteral>(E); - + if (StrE) { - CheckPrintfString(StrE, E, TheCall, HasVAListArg, format_idx, + CheckPrintfString(StrE, E, TheCall, HasVAListArg, format_idx, firstDataArg); return true; } - + return false; } - + default: return false; } } void -Sema::CheckNonNullArguments(const NonNullAttr *NonNull, const CallExpr *TheCall) -{ +Sema::CheckNonNullArguments(const NonNullAttr *NonNull, + const CallExpr *TheCall) { for (NonNullAttr::iterator i = NonNull->begin(), e = NonNull->end(); i != e; ++i) { const Expr *ArgExpr = TheCall->getArg(*i); @@ -902,7 +902,7 @@ Sema::CheckNonNullArguments(const NonNullAttr *NonNull, const CallExpr *TheCall) } /// CheckPrintfArguments - Check calls to printf (and similar functions) for -/// correct use of format strings. +/// correct use of format strings. /// /// HasVAListArg - A predicate indicating whether the printf-like /// function is passed an explicit va_arg argument (e.g., vprintf) @@ -951,30 +951,30 @@ Sema::CheckNonNullArguments(const NonNullAttr *NonNull, const CallExpr *TheCall) /// /// For now, we ONLY do (1), (3), (5), (6), (7), and (8). void -Sema::CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg, +Sema::CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg, unsigned format_idx, unsigned firstDataArg) { const Expr *Fn = TheCall->getCallee(); - // CHECK: printf-like function is called with no format string. + // CHECK: printf-like function is called with no format string. if (format_idx >= TheCall->getNumArgs()) { Diag(TheCall->getRParenLoc(), diag::warn_printf_missing_format_string) << Fn->getSourceRange(); return; } - + const Expr *OrigFormatExpr = TheCall->getArg(format_idx)->IgnoreParenCasts(); - + // CHECK: format string is not a string literal. - // + // // Dynamically generated format strings are difficult to // automatically vet at compile time. Requiring that format strings // are string literals: (1) permits the checking of format strings by // the compiler and thereby (2) can practically remove the source of // many format string exploits. - // Format string can be either ObjC string (e.g. @"%d") or + // Format string can be either ObjC string (e.g. @"%d") or // C string (e.g. "%d") - // ObjC string uses the same format specifiers as C string, so we can use + // ObjC string uses the same format specifiers as C string, so we can use // the same format string checking logic for both ObjC and C strings. if (SemaCheckStringLiteral(OrigFormatExpr, TheCall, HasVAListArg, format_idx, firstDataArg)) @@ -983,11 +983,11 @@ Sema::CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg, // If there are no arguments specified, warn with -Wformat-security, otherwise // warn only with -Wformat-nonliteral. if (TheCall->getNumArgs() == format_idx+1) - Diag(TheCall->getArg(format_idx)->getLocStart(), + Diag(TheCall->getArg(format_idx)->getLocStart(), diag::warn_printf_nonliteral_noargs) << OrigFormatExpr->getSourceRange(); else - Diag(TheCall->getArg(format_idx)->getLocStart(), + Diag(TheCall->getArg(format_idx)->getLocStart(), diag::warn_printf_nonliteral) << OrigFormatExpr->getSourceRange(); } @@ -1013,7 +1013,7 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, // CHECK: empty format string? unsigned StrLen = FExpr->getByteLength(); - + if (StrLen == 0) { Diag(FExpr->getLocStart(), diag::warn_printf_empty_format_string) << OrigFormatExpr->getSourceRange(); @@ -1026,7 +1026,7 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, state_OrdChr, state_Conversion } CurrentState = state_OrdChr; - + // numConversions - The number of conversions seen so far. This is // incremented as we traverse the format string. unsigned numConversions = 0; @@ -1039,17 +1039,17 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, // Inspect the format string. unsigned StrIdx = 0; - + // LastConversionIdx - Index within the format string where we last saw // a '%' character that starts a new format conversion. unsigned LastConversionIdx = 0; - + for (; StrIdx < StrLen; ++StrIdx) { - + // Is the number of detected conversion conversions greater than // the number of matching data arguments? If so, stop. if (!HasVAListArg && numConversions > numDataArgs) break; - + // Handle "\0" if (Str[StrIdx] == '\0') { // The string returned by getStrData() is not null-terminated, @@ -1059,7 +1059,7 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, << OrigFormatExpr->getSourceRange(); return; } - + // Ordinary characters (not processing a format conversion). if (CurrentState == state_OrdChr) { if (Str[StrIdx] == '%') { @@ -1071,10 +1071,10 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, // Seen '%'. Now processing a format conversion. switch (Str[StrIdx]) { - // Handle dynamic precision or width specifier. + // Handle dynamic precision or width specifier. case '*': { ++numConversions; - + if (!HasVAListArg) { if (numConversions > numDataArgs) { SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx); @@ -1085,39 +1085,39 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, else Diag(Loc, diag::warn_printf_asterisk_width_missing_arg) << OrigFormatExpr->getSourceRange(); - + // Don't do any more checking. We'll just emit spurious errors. return; } - + // Perform type checking on width/precision specifier. const Expr *E = TheCall->getArg(format_idx+numConversions); if (const BuiltinType *BT = E->getType()->getAsBuiltinType()) if (BT->getKind() == BuiltinType::Int) break; - + SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx); - + if (Str[StrIdx-1] == '.') Diag(Loc, diag::warn_printf_asterisk_precision_wrong_type) << E->getType() << E->getSourceRange(); else Diag(Loc, diag::warn_printf_asterisk_width_wrong_type) << E->getType() << E->getSourceRange(); - - break; + + break; } } - + // Characters which can terminate a format conversion // (e.g. "%d"). Characters that specify length modifiers or // other flags are handled by the default case below. // - // FIXME: additional checks will go into the following cases. + // FIXME: additional checks will go into the following cases. case 'i': case 'd': - case 'o': - case 'u': + case 'o': + case 'u': case 'x': case 'X': case 'D': @@ -1135,7 +1135,7 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, case 'C': case 'S': case 's': - case 'p': + case 'p': ++numConversions; CurrentState = state_OrdChr; break; @@ -1151,21 +1151,21 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, CurrentState = state_OrdChr; SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, LastConversionIdx); - + Diag(Loc, diag::warn_printf_write_back)<<OrigFormatExpr->getSourceRange(); break; } - + // Handle "%@" case '@': // %@ is allowed in ObjC format strings only. - if(ObjCFExpr != NULL) - CurrentState = state_OrdChr; + if (ObjCFExpr != NULL) + CurrentState = state_OrdChr; else { // Issue a warning: invalid format conversion. - SourceLocation Loc = + SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, LastConversionIdx); - + Diag(Loc, diag::warn_printf_invalid_conversion) << std::string(Str+LastConversionIdx, Str+std::min(LastConversionIdx+2, StrLen)) @@ -1173,7 +1173,7 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, } ++numConversions; break; - + // Handle "%%" case '%': // Sanity check: Was the first "%" character the previous one? @@ -1181,23 +1181,23 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, // conversion, and that the current "%" character is the start // of a new conversion. if (StrIdx - LastConversionIdx == 1) - CurrentState = state_OrdChr; + CurrentState = state_OrdChr; else { // Issue a warning: invalid format conversion. SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, LastConversionIdx); - + Diag(Loc, diag::warn_printf_invalid_conversion) << std::string(Str+LastConversionIdx, Str+StrIdx) << OrigFormatExpr->getSourceRange(); - + // This conversion is broken. Advance to the next format // conversion. LastConversionIdx = StrIdx; ++numConversions; } break; - + default: // This case catches all other characters: flags, widths, etc. // We should eventually process those as well. @@ -1209,21 +1209,21 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, // Issue a warning: invalid format conversion. SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, LastConversionIdx); - + Diag(Loc, diag::warn_printf_invalid_conversion) << std::string(Str+LastConversionIdx, Str+std::min(LastConversionIdx+2, StrLen)) << OrigFormatExpr->getSourceRange(); return; } - + if (!HasVAListArg) { // CHECK: Does the number of format conversions exceed the number // of data arguments? if (numConversions > numDataArgs) { SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, LastConversionIdx); - + Diag(Loc, diag::warn_printf_insufficient_data_args) << OrigFormatExpr->getSourceRange(); } @@ -1246,13 +1246,13 @@ static DeclRefExpr* EvalAddr(Expr* E); void Sema::CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, SourceLocation ReturnLoc) { - + // Perform checking for returned stack addresses. if (lhsType->isPointerType() || lhsType->isBlockPointerType()) { if (DeclRefExpr *DR = EvalAddr(RetValExp)) Diag(DR->getLocStart(), diag::warn_ret_stack_addr) << DR->getDecl()->getDeclName() << RetValExp->getSourceRange(); - + // Skip over implicit cast expressions when checking for block expressions. RetValExp = RetValExp->IgnoreParenCasts(); @@ -1279,7 +1279,7 @@ Sema::CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, /// /// EvalAddr processes expressions that are pointers that are used as /// references (and not L-values). EvalVal handles all other values. -/// At the base case of the recursion is a check for a DeclRefExpr* in +/// At the base case of the recursion is a check for a DeclRefExpr* in /// the refers to a stack variable. /// /// This implementation handles: @@ -1296,7 +1296,7 @@ static DeclRefExpr* EvalAddr(Expr *E) { E->getType()->isBlockPointerType() || E->getType()->isObjCQualifiedIdType()) && "EvalAddr only works on pointers"); - + // Our "symbolic interpreter" is just a dispatch off the currently // viewed AST node. We then recursively traverse the AST by calling // EvalAddr and EvalVal appropriately. @@ -1309,28 +1309,28 @@ static DeclRefExpr* EvalAddr(Expr *E) { // The only unary operator that make sense to handle here // is AddrOf. All others don't make sense as pointers. UnaryOperator *U = cast<UnaryOperator>(E); - + if (U->getOpcode() == UnaryOperator::AddrOf) return EvalVal(U->getSubExpr()); else return NULL; } - + case Stmt::BinaryOperatorClass: { // Handle pointer arithmetic. All other binary operators are not valid // in this context. BinaryOperator *B = cast<BinaryOperator>(E); BinaryOperator::Opcode op = B->getOpcode(); - + if (op != BinaryOperator::Add && op != BinaryOperator::Sub) return NULL; - + Expr *Base = B->getLHS(); // Determine which argument is the real pointer base. It could be // the RHS argument instead of the LHS. if (!Base->getType()->isPointerType()) Base = B->getRHS(); - + assert (Base->getType()->isPointerType()); return EvalAddr(Base); } @@ -1339,7 +1339,7 @@ static DeclRefExpr* EvalAddr(Expr *E) { // valid DeclRefExpr*s. If one of them is valid, we return it. case Stmt::ConditionalOperatorClass: { ConditionalOperator *C = cast<ConditionalOperator>(E); - + // Handle the GNU extension for missing LHS. if (Expr *lhsExpr = C->getLHS()) if (DeclRefExpr* LHS = EvalAddr(lhsExpr)) @@ -1347,7 +1347,7 @@ static DeclRefExpr* EvalAddr(Expr *E) { return EvalAddr(C->getRHS()); } - + // For casts, we need to handle conversions from arrays to // pointer values, and pointer-to-pointer conversions. case Stmt::ImplicitCastExprClass: @@ -1355,7 +1355,7 @@ static DeclRefExpr* EvalAddr(Expr *E) { case Stmt::CXXFunctionalCastExprClass: { Expr* SubExpr = cast<CastExpr>(E)->getSubExpr(); QualType T = SubExpr->getType(); - + if (SubExpr->getType()->isPointerType() || SubExpr->getType()->isBlockPointerType() || SubExpr->getType()->isObjCQualifiedIdType()) @@ -1365,7 +1365,7 @@ static DeclRefExpr* EvalAddr(Expr *E) { else return 0; } - + // C++ casts. For dynamic casts, static casts, and const casts, we // are always converting from a pointer-to-pointer, so we just blow // through the cast. In the case the dynamic cast doesn't fail (and @@ -1373,9 +1373,9 @@ static DeclRefExpr* EvalAddr(Expr *E) { // where we return the address of a stack variable. For Reinterpre // FIXME: The comment about is wrong; we're not always converting // from pointer to pointer. I'm guessing that this code should also - // handle references to objects. - case Stmt::CXXStaticCastExprClass: - case Stmt::CXXDynamicCastExprClass: + // handle references to objects. + case Stmt::CXXStaticCastExprClass: + case Stmt::CXXDynamicCastExprClass: case Stmt::CXXConstCastExprClass: case Stmt::CXXReinterpretCastExprClass: { Expr *S = cast<CXXNamedCastExpr>(E)->getSubExpr(); @@ -1384,62 +1384,62 @@ static DeclRefExpr* EvalAddr(Expr *E) { else return NULL; } - + // Everything else: we simply don't reason about them. default: return NULL; } } - + /// EvalVal - This function is complements EvalAddr in the mutual recursion. /// See the comments for EvalAddr for more details. static DeclRefExpr* EvalVal(Expr *E) { - + // We should only be called for evaluating non-pointer expressions, or // expressions with a pointer type that are not used as references but instead // are l-values (e.g., DeclRefExpr with a pointer type). - + // Our "symbolic interpreter" is just a dispatch off the currently // viewed AST node. We then recursively traverse the AST by calling // EvalAddr and EvalVal appropriately. switch (E->getStmtClass()) { - case Stmt::DeclRefExprClass: + case Stmt::DeclRefExprClass: case Stmt::QualifiedDeclRefExprClass: { // DeclRefExpr: the base case. When we hit a DeclRefExpr we are looking // at code that refers to a variable's name. We check if it has local // storage within the function, and if so, return the expression. DeclRefExpr *DR = cast<DeclRefExpr>(E); - + if (VarDecl *V = dyn_cast<VarDecl>(DR->getDecl())) - if(V->hasLocalStorage() && !V->getType()->isReferenceType()) return DR; - + if (V->hasLocalStorage() && !V->getType()->isReferenceType()) return DR; + return NULL; } - + case Stmt::ParenExprClass: // Ignore parentheses. return EvalVal(cast<ParenExpr>(E)->getSubExpr()); - + case Stmt::UnaryOperatorClass: { // The only unary operator that make sense to handle here // is Deref. All others don't resolve to a "name." This includes // handling all sorts of rvalues passed to a unary operator. UnaryOperator *U = cast<UnaryOperator>(E); - + if (U->getOpcode() == UnaryOperator::Deref) return EvalAddr(U->getSubExpr()); return NULL; } - + case Stmt::ArraySubscriptExprClass: { // Array subscripts are potential references to data on the stack. We // retrieve the DeclRefExpr* for the array variable if it indeed // has local storage. return EvalAddr(cast<ArraySubscriptExpr>(E)->getBase()); } - + case Stmt::ConditionalOperatorClass: { // For conditional operators we need to see if either the LHS or RHS are // non-NULL DeclRefExpr's. If one is non-NULL, we return it. @@ -1452,18 +1452,18 @@ static DeclRefExpr* EvalVal(Expr *E) { return EvalVal(C->getRHS()); } - + // Accesses to members are potential references to data on the stack. case Stmt::MemberExprClass: { MemberExpr *M = cast<MemberExpr>(E); - + // Check for indirect access. We only want direct field accesses. if (!M->isArrow()) return EvalVal(M->getBase()); else return NULL; } - + // Everything else: we simply don't reason about them. default: return NULL; @@ -1477,7 +1477,7 @@ static DeclRefExpr* EvalVal(Expr *E) { /// to do what the programmer intended. void Sema::CheckFloatComparison(SourceLocation loc, Expr* lex, Expr *rex) { bool EmitWarning = true; - + Expr* LeftExprSansParen = lex->IgnoreParens(); Expr* RightExprSansParen = rex->IgnoreParens(); @@ -1487,8 +1487,8 @@ void Sema::CheckFloatComparison(SourceLocation loc, Expr* lex, Expr *rex) { if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(RightExprSansParen)) if (DRL->getDecl() == DRR->getDecl()) EmitWarning = false; - - + + // Special case: check for comparisons against literals that can be exactly // represented by APFloat. In such cases, do not emit a warning. This // is a heuristic: often comparison against such literals are used to @@ -1504,18 +1504,18 @@ void Sema::CheckFloatComparison(SourceLocation loc, Expr* lex, Expr *rex) { EmitWarning = false; } } - + // Check for comparisons with builtin types. if (EmitWarning) if (CallExpr* CL = dyn_cast<CallExpr>(LeftExprSansParen)) if (CL->isBuiltinCall(Context)) EmitWarning = false; - + if (EmitWarning) if (CallExpr* CR = dyn_cast<CallExpr>(RightExprSansParen)) if (CR->isBuiltinCall(Context)) EmitWarning = false; - + // Emit the diagnostic. if (EmitWarning) Diag(loc, diag::warn_floatingpoint_eq) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 8074ab94bf..d49ba890b2 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -28,7 +28,7 @@ #include "clang/Basic/TargetInfo.h" // FIXME: layering (ideally, Sema shouldn't be dependent on Lex API's) #include "clang/Lex/Preprocessor.h" -#include "clang/Lex/HeaderSearch.h" +#include "clang/Lex/HeaderSearch.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/STLExtras.h" #include <algorithm> @@ -37,7 +37,7 @@ using namespace clang; /// getDeclName - Return a pretty name for the specified decl if possible, or -/// an empty string if not. This is used for pretty crash reporting. +/// an empty string if not. This is used for pretty crash reporting. std::string Sema::getDeclName(DeclPtrTy d) { Decl *D = d.getAs<Decl>(); if (NamedDecl *DN = dyn_cast_or_null<NamedDecl>(D)) @@ -75,16 +75,16 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc, if (SS && isUnknownSpecialization(*SS)) { if (!isClassName) return 0; - - // We know from the grammar that this name refers to a type, so build a + + // We know from the grammar that this name refers to a type, so build a // TypenameType node to describe the type. // FIXME: Record somewhere that this TypenameType node has no "typename" // keyword associated with it. return CheckTypenameType((NestedNameSpecifier *)SS->getScopeRep(), II, SS->getRange()).getAsOpaquePtr(); } - - LookupResult Result + + LookupResult Result = LookupParsedName(S, SS, &II, LookupOrdinaryName, false, false); NamedDecl *IIDecl = 0; @@ -100,8 +100,8 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc, for (LookupResult::iterator Res = Result.begin(), ResEnd = Result.end(); Res != ResEnd; ++Res) { if (isa<TypeDecl>(*Res) || isa<ObjCInterfaceDecl>(*Res)) { - if (!IIDecl || - (*Res)->getLocation().getRawEncoding() < + if (!IIDecl || + (*Res)->getLocation().getRawEncoding() < IIDecl->getLocation().getRawEncoding()) IIDecl = *Res; } @@ -133,11 +133,11 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc, if (IIDecl) { QualType T; - + if (TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) { // Check whether we can use this type (void)DiagnoseUseOfDecl(IIDecl, NameLoc); - + if (getLangOptions().CPlusPlus) { // C++ [temp.local]p2: // Within the scope of a class template specialization or @@ -157,7 +157,7 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc, } else if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(IIDecl)) { // Check whether we can use this interface. (void)DiagnoseUseOfDecl(IIDecl, NameLoc); - + T = Context.getObjCInterfaceType(IDecl); } else return 0; @@ -188,7 +188,7 @@ DeclSpec::TST Sema::isTagName(IdentifierInfo &II, Scope *S) { case TagDecl::TK_enum: return DeclSpec::TST_enum; } } - + return DeclSpec::TST_unspecified; } @@ -284,7 +284,7 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext) { // Move up the scope chain until we find the nearest enclosing // non-transparent context. The declaration will be introduced into this // scope. - while (S->getEntity() && + while (S->getEntity() && ((DeclContext *)S->getEntity())->isTransparentContext()) S = S->getParent(); @@ -304,7 +304,7 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext) { // in this case the class name or enumeration name is hidden. if (TagDecl *TD = dyn_cast<TagDecl>(D)) { // We are pushing the name of a tag (enum or class). - if (CurContext->getLookupContext() + if (CurContext->getLookupContext() == TD->getDeclContext()->getLookupContext()) { // We're pushing the tag into the current context, which might // require some reshuffling in the identifier resolver. @@ -313,7 +313,7 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext) { IEnd = IdResolver.end(); if (I != IEnd && isDeclInScope(*I, CurContext, S)) { NamedDecl *PrevDecl = *I; - for (; I != IEnd && isDeclInScope(*I, CurContext, S); + for (; I != IEnd && isDeclInScope(*I, CurContext, S); PrevDecl = *I, ++I) { if (TD->declarationReplaces(*I)) { // This is a redeclaration. Remove it from the chain and @@ -336,7 +336,7 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext) { // before we find the new declaration, so insert the new // declaration at the end of the chain. IdResolver.AddShadowedDecl(TD, PrevDecl); - + return; } } @@ -360,7 +360,7 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext) { } else if (isa<ObjCInterfaceDecl>(D)) { // We're pushing an Objective-C interface into the current // context. If there is already an alias declaration, remove it first. - for (IdentifierResolver::iterator + for (IdentifierResolver::iterator I = IdResolver.begin(D->getDeclName()), IEnd = IdResolver.end(); I != IEnd; ++I) { if (isa<ObjCCompatibleAliasDecl>(*I)) { @@ -377,7 +377,7 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext) { void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) { if (S->decl_empty()) return; assert((S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) && - "Scope shouldn't contain decls!"); + "Scope shouldn't contain decls!"); for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end(); I != E; ++I) { @@ -400,7 +400,7 @@ ObjCInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *Id) { // The third "scope" argument is 0 since we aren't enabling lazy built-in // creation from this context. NamedDecl *IDecl = LookupName(TUScope, Id, LookupOrdinaryName); - + return dyn_cast_or_null<ObjCInterfaceDecl>(IDecl); } @@ -413,7 +413,7 @@ ObjCInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *Id) { /// struct S6 { /// enum { BAR } e; /// }; -/// +/// /// void test_S6() { /// struct S6 a; /// a.e = BAR; @@ -429,7 +429,7 @@ ObjCInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *Id) { /// contain non-field names. Scope *Sema::getNonFieldDeclScope(Scope *S) { while (((S->getFlags() & Scope::DeclScope) == 0) || - (S->getEntity() && + (S->getEntity() && ((DeclContext *)S->getEntity())->isTransparentContext()) || (S->isClassScope() && !getLangOptions().CPlusPlus)) S = S->getParent(); @@ -439,7 +439,7 @@ Scope *Sema::getNonFieldDeclScope(Scope *S) { void Sema::InitBuiltinVaListType() { if (!Context.getBuiltinVaListType().isNull()) return; - + IdentifierInfo *VaIdent = &Context.Idents.get("__builtin_va_list"); NamedDecl *VaDecl = LookupName(TUScope, VaIdent, LookupOrdinaryName); TypedefDecl *VaTypedef = cast<TypedefDecl>(VaDecl); @@ -459,7 +459,7 @@ NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid, InitBuiltinVaListType(); ASTContext::GetBuiltinTypeError Error; - QualType R = Context.GetBuiltinType(BID, Error); + QualType R = Context.GetBuiltinType(BID, Error); switch (Error) { case ASTContext::GE_None: // Okay @@ -507,9 +507,9 @@ NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid, VarDecl::None, 0)); New->setParams(Context, Params.data(), Params.size()); } - - AddKnownFunctionAttributes(New); - + + AddKnownFunctionAttributes(New); + // TUScope is the translation-unit scope to insert this function into. // FIXME: This is hideous. We need to teach PushOnScopeChains to // relate Scopes to DeclContexts, and probably eliminate CurContext @@ -543,14 +543,14 @@ void Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { // don't bother doing any merging checks. if (New->isInvalidDecl() || OldD->isInvalidDecl()) return New->setInvalidDecl(); - + // Allow multiple definitions for ObjC built-in typedefs. // FIXME: Verify the underlying types are equivalent! if (getLangOptions().ObjC1) { const IdentifierInfo *TypeID = New->getIdentifier(); switch (TypeID->getLength()) { default: break; - case 2: + case 2: if (!TypeID->isStr("id")) break; Context.ObjCIdRedefinitionType = New->getUnderlyingType(); @@ -580,14 +580,14 @@ void Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { // Verify the old decl was also a type. TypeDecl *Old = dyn_cast<TypeDecl>(OldD); if (!Old) { - Diag(New->getLocation(), diag::err_redefinition_different_kind) + Diag(New->getLocation(), diag::err_redefinition_different_kind) << New->getDeclName(); if (OldD->getLocation().isValid()) Diag(OldD->getLocation(), diag::note_previous_definition); return New->setInvalidDecl(); } - // Determine the "old" type we'll use for checking and diagnostics. + // Determine the "old" type we'll use for checking and diagnostics. QualType OldType; if (TypedefDecl *OldTypedef = dyn_cast<TypedefDecl>(Old)) OldType = OldTypedef->getUnderlyingType(); @@ -597,8 +597,8 @@ void Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { // If the typedef types are not identical, reject them in all languages and // with any extensions enabled. - if (OldType != New->getUnderlyingType() && - Context.getCanonicalType(OldType) != + if (OldType != New->getUnderlyingType() && + Context.getCanonicalType(OldType) != Context.getCanonicalType(New->getUnderlyingType())) { Diag(New->getLocation(), diag::err_redefinition_different_typedef) << New->getUnderlyingType() << OldType; @@ -606,7 +606,7 @@ void Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { Diag(Old->getLocation(), diag::note_previous_definition); return New->setInvalidDecl(); } - + if (getLangOptions().Microsoft) return; @@ -631,7 +631,7 @@ void Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { (Context.getSourceManager().isInSystemHeader(Old->getLocation()) || Context.getSourceManager().isInSystemHeader(New->getLocation()))) return; - + Diag(New->getLocation(), diag::warn_redefinition_of_typedef) << New->getDeclName(); Diag(Old->getLocation(), diag::note_previous_definition); @@ -640,7 +640,7 @@ void Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { /// DeclhasAttr - returns true if decl Declaration already has the target /// attribute. -static bool +static bool DeclHasAttr(const Decl *decl, const Attr *target) { for (const Attr *attr = decl->getAttrs(); attr; attr = attr->getNext()) if (attr->getKind() == target->getKind()) @@ -680,15 +680,15 @@ struct GNUCompatibleParamWarning { /// /// Returns true if there was an error, false otherwise. bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { - assert(!isa<OverloadedFunctionDecl>(OldD) && + assert(!isa<OverloadedFunctionDecl>(OldD) && "Cannot merge with an overloaded function declaration"); // Verify the old decl was also a function. FunctionDecl *Old = 0; - if (FunctionTemplateDecl *OldFunctionTemplate + if (FunctionTemplateDecl *OldFunctionTemplate = dyn_cast<FunctionTemplateDecl>(OldD)) Old = OldFunctionTemplate->getTemplatedDecl(); - else + else Old = dyn_cast<FunctionDecl>(OldD); if (!Old) { Diag(New->getLocation(), diag::err_redefinition_different_kind) @@ -704,12 +704,12 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { PrevDiag = diag::note_previous_definition; else if (Old->isImplicit()) PrevDiag = diag::note_previous_implicit_declaration; - else + else PrevDiag = diag::note_previous_declaration; - + QualType OldQType = Context.getCanonicalType(Old->getType()); QualType NewQType = Context.getCanonicalType(New->getType()); - + if (!isa<CXXMethodDecl>(New) && !isa<CXXMethodDecl>(Old) && New->getStorageClass() == FunctionDecl::Static && Old->getStorageClass() != FunctionDecl::Static) { @@ -722,11 +722,11 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { if (getLangOptions().CPlusPlus) { // (C++98 13.1p2): // Certain function declarations cannot be overloaded: - // -- Function declarations that differ only in the return type + // -- Function declarations that differ only in the return type // cannot be overloaded. - QualType OldReturnType + QualType OldReturnType = cast<FunctionType>(OldQType.getTypePtr())->getResultType(); - QualType NewReturnType + QualType NewReturnType = cast<FunctionType>(NewQType.getTypePtr())->getResultType(); if (OldReturnType != NewReturnType) { Diag(New->getLocation(), diag::err_ovl_diff_return_type); @@ -738,8 +738,8 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { const CXXMethodDecl* NewMethod = dyn_cast<CXXMethodDecl>(New); if (OldMethod && NewMethod && !NewMethod->getFriendObjectKind() && NewMethod->getLexicalDeclContext()->isRecord()) { - // -- Member function declarations with the same name and the - // same parameter types cannot be overloaded if any of them + // -- Member function declarations with the same name and the + // same parameter types cannot be overloaded if any of them // is a static member function declaration. if (OldMethod->isStatic() || NewMethod->isStatic()) { Diag(New->getLocation(), diag::err_ovl_static_nonstatic_member); @@ -760,7 +760,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { NewDiag = diag::err_conv_function_redeclared; else NewDiag = diag::err_member_redeclared; - + Diag(New->getLocation(), NewDiag); Diag(Old->getLocation(), PrevDiag) << Old << Old->getType(); } @@ -797,8 +797,8 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { // Synthesize a parameter for each argument type. llvm::SmallVector<ParmVarDecl*, 16> Params; - for (FunctionProtoType::arg_type_iterator - ParamType = OldProto->arg_type_begin(), + for (FunctionProtoType::arg_type_iterator + ParamType = OldProto->arg_type_begin(), ParamEnd = OldProto->arg_type_end(); ParamType != ParamEnd; ++ParamType) { ParmVarDecl *Param = ParmVarDecl::Create(Context, New, @@ -810,7 +810,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { } New->setParams(Context, Params.data(), Params.size()); - } + } return MergeCompatibleFunctionDecls(New, Old); } @@ -832,25 +832,25 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { Old->getNumParams() == New->getNumParams()) { llvm::SmallVector<QualType, 16> ArgTypes; llvm::SmallVector<GNUCompatibleParamWarning, 16> Warnings; - const FunctionProtoType *OldProto + const FunctionProtoType *OldProto = Old->getType()->getAsFunctionProtoType(); - const FunctionProtoType *NewProto + const FunctionProtoType *NewProto = New->getType()->getAsFunctionProtoType(); - + // Determine whether this is the GNU C extension. QualType MergedReturn = Context.mergeTypes(OldProto->getResultType(), NewProto->getResultType()); bool LooseCompatible = !MergedReturn.isNull(); - for (unsigned Idx = 0, End = Old->getNumParams(); + for (unsigned Idx = 0, End = Old->getNumParams(); LooseCompatible && Idx != End; ++Idx) { ParmVarDecl *OldParm = Old->getParamDecl(Idx); ParmVarDecl *NewParm = New->getParamDecl(Idx); - if (Context.typesAreCompatible(OldParm->getType(), + if (Context.typesAreCompatible(OldParm->getType(), NewProto->getArgType(Idx))) { ArgTypes.push_back(NewParm->getType()); } else if (Context.typesAreCompatible(OldParm->getType(), NewParm->getType())) { - GNUCompatibleParamWarning Warn + GNUCompatibleParamWarning Warn = { OldParm, NewParm, NewProto->getArgType(Idx) }; Warnings.push_back(Warn); ArgTypes.push_back(NewParm->getType()); @@ -864,7 +864,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { diag::ext_param_promoted_not_compatible_with_prototype) << Warnings[Warn].PromotedType << Warnings[Warn].OldParm->getType(); - Diag(Warnings[Warn].OldParm->getLocation(), + Diag(Warnings[Warn].OldParm->getLocation(), diag::note_previous_declaration); } @@ -904,7 +904,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { } /// \brief Completes the merge of two function declarations that are -/// known to be compatible. +/// known to be compatible. /// /// This routine handles the merging of attributes and other /// properties of function declarations form the old declaration to @@ -931,7 +931,7 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old) { New->setC99InlineDefinition(false); else if (Old->isC99InlineDefinition() && !New->isC99InlineDefinition()) { // Mark all preceding definitions as not being C99 inline definitions. - for (const FunctionDecl *Prev = Old; Prev; + for (const FunctionDecl *Prev = Old; Prev; Prev = Prev->getPreviousDeclaration()) const_cast<FunctionDecl *>(Prev)->setC99InlineDefinition(false); } @@ -943,7 +943,7 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old) { // Merge the "deleted" flag. if (Old->isDeleted()) New->setDeleted(); - + if (getLangOptions().CPlusPlus) return MergeCXXFunctionDecl(New, Old); @@ -954,16 +954,16 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old) { /// and scope as a previous declaration 'Old'. Figure out how to resolve this /// situation, merging decls or emitting diagnostics as appropriate. /// -/// Tentative definition rules (C99 6.9.2p2) are checked by -/// FinalizeDeclaratorGroup. Unfortunately, we can't analyze tentative +/// Tentative definition rules (C99 6.9.2p2) are checked by +/// FinalizeDeclaratorGroup. Unfortunately, we can't analyze tentative /// definitions here, since the initializer hasn't been attached. -/// +/// void Sema::MergeVarDecl(VarDecl *New, Decl *OldD) { // If either decl is invalid, make sure the new one is marked invalid and // don't do any other checking. if (New->isInvalidDecl() || OldD->isInvalidDecl()) return New->setInvalidDecl(); - + // Verify the old decl was also a variable. VarDecl *Old = dyn_cast<VarDecl>(OldD); if (!Old) { @@ -981,14 +981,14 @@ void Sema::MergeVarDecl(VarDecl *New, Decl *OldD) { if (Context.hasSameType(New->getType(), Old->getType())) MergedT = New->getType(); // C++ [basic.types]p7: - // [...] The declared type of an array object might be an array of - // unknown size and therefore be incomplete at one point in a + // [...] The declared type of an array object might be an array of + // unknown size and therefore be incomplete at one point in a // translation unit and complete later on; [...] - else if (Old->getType()->isIncompleteArrayType() && + else if (Old->getType()->isIncompleteArrayType() && New->getType()->isArrayType()) { - CanQual<ArrayType> OldArray + CanQual<ArrayType> OldArray = Context.getCanonicalType(Old->getType())->getAs<ArrayType>(); - CanQual<ArrayType> NewArray + CanQual<ArrayType> NewArray = Context.getCanonicalType(New->getType())->getAs<ArrayType>(); if (OldArray->getElementType() == NewArray->getElementType()) MergedT = New->getType(); @@ -997,7 +997,7 @@ void Sema::MergeVarDecl(VarDecl *New, Decl *OldD) { MergedT = Context.mergeTypes(New->getType(), Old->getType()); } if (MergedT.isNull()) { - Diag(New->getLocation(), diag::err_redefinition_different_type) + Diag(New->getLocation(), diag::err_redefinition_different_type) << New->getDeclName(); Diag(Old->getLocation(), diag::note_previous_definition); return New->setInvalidDecl(); @@ -1011,7 +1011,7 @@ void Sema::MergeVarDecl(VarDecl *New, Decl *OldD) { Diag(Old->getLocation(), diag::note_previous_definition); return New->setInvalidDecl(); } - // C99 6.2.2p4: + // C99 6.2.2p4: // For an identifier declared with the storage-class specifier // extern in a scope in which a prior declaration of that // identifier is visible,23) if the prior declaration specifies @@ -1030,7 +1030,7 @@ void Sema::MergeVarDecl(VarDecl *New, Decl *OldD) { } // Variables with external linkage are analyzed in FinalizeDeclaratorGroup. - + // FIXME: The test for external storage here seems wrong? We still // need to check for mismatches. if (!New->hasExternalStorage() && !New->isFileVarDecl() && @@ -1063,7 +1063,7 @@ void Sema::MergeVarDecl(VarDecl *New, Decl *OldD) { /// that functions not marked noreturn will return. Sema::ControlFlowKind Sema::CheckFallThrough(Stmt *Root) { llvm::OwningPtr<CFG> cfg (CFG::buildCFG(Root, &Context)); - + // FIXME: They should never return 0, fix that, delete this code. if (cfg == 0) return NeverFallThrough; @@ -1175,7 +1175,7 @@ void Sema::CheckFallThroughForFunctionDef(Decl *D, Stmt *Body) { if (MD->hasAttr<NoReturnAttr>()) HasNoReturn = true; } - + // Short circuit for compilation speed. if ((Diags.getDiagnosticLevel(diag::warn_maybe_falloff_nonvoid_function) == Diagnostic::Ignored || ReturnsVoid) @@ -1228,7 +1228,7 @@ void Sema::CheckFallThroughForBlock(QualType BlockTy, Stmt *Body) { if (FT->getNoReturnAttr()) HasNoReturn = true; } - + // Short circuit for compilation speed. if (ReturnsVoid && !HasNoReturn @@ -1279,10 +1279,10 @@ bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) { Param->setInvalidDecl(); HasInvalidParm = true; } - + // C99 6.9.1p5: If the declarator includes a parameter type list, the // declaration of each parameter shall include an identifier. - if (Param->getIdentifier() == 0 && + if (Param->getIdentifier() == 0 && !Param->isImplicit() && !getLangOptions().CPlusPlus) Diag(Param->getLocation(), diag::err_parameter_name_omitted); @@ -1333,7 +1333,7 @@ Sema::DeclPtrTy Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { return DeclPtrTy::make(Tag); } - if (!DS.isMissingDeclaratorOk() && + if (!DS.isMissingDeclaratorOk() && DS.getTypeSpecType() != DeclSpec::TST_error) { // Warn about typedefs of enums without names, since this is an // extension in both Microsoft an GNU. @@ -1348,7 +1348,7 @@ Sema::DeclPtrTy Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { << DS.getSourceRange(); return DeclPtrTy(); } - + return DeclPtrTy::make(Tag); } @@ -1382,7 +1382,7 @@ bool Sema::InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner, // The names of the members of an anonymous union shall be // distinct from the names of any other entity in the // scope in which the anonymous union is declared. - unsigned diagKind + unsigned diagKind = AnonRecord->isUnion()? diag::err_anonymous_union_member_redecl : diag::err_anonymous_struct_member_redecl; Diag((*F)->getLocation(), diagKind) @@ -1403,7 +1403,7 @@ bool Sema::InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner, = (*F)->getType()->getAs<RecordType>()) { RecordDecl *InnerRecord = InnerRecordType->getDecl(); if (InnerRecord->isAnonymousStructOrUnion()) - Invalid = Invalid || + Invalid = Invalid || InjectAnonymousStructOrUnionMembers(S, Owner, InnerRecord); } } @@ -1414,7 +1414,7 @@ bool Sema::InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner, /// ActOnAnonymousStructOrUnion - Handle the declaration of an /// anonymous structure or union. Anonymous unions are a C++ feature /// (C++ [class.union]) and a GNU C extension; anonymous structures -/// are a GNU C and GNU C++ extension. +/// are a GNU C and GNU C++ extension. Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, RecordDecl *Record) { DeclContext *Owner = Record->getDeclContext(); @@ -1424,7 +1424,7 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, Diag(Record->getLocation(), diag::ext_anonymous_union); else if (!Record->isUnion()) Diag(Record->getLocation(), diag::ext_anonymous_struct); - + // C and C++ require different kinds of checks for anonymous // structs/unions. bool Invalid = false; @@ -1436,7 +1436,7 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, // global namespace shall be declared static. if (DS.getStorageClassSpec() != DeclSpec::SCS_static && (isa<TranslationUnitDecl>(Owner) || - (isa<NamespaceDecl>(Owner) && + (isa<NamespaceDecl>(Owner) && cast<NamespaceDecl>(Owner)->getDeclName()))) { Diag(Record->getLocation(), diag::err_anonymous_union_not_static); Invalid = true; @@ -1444,13 +1444,13 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, // Recover by adding 'static'. DS.SetStorageClassSpec(DeclSpec::SCS_static, SourceLocation(), PrevSpec, DiagID); - } + } // C++ [class.union]p3: // A storage class is not allowed in a declaration of an // anonymous union in a class scope. else if (DS.getStorageClassSpec() != DeclSpec::SCS_unspecified && isa<RecordDecl>(Owner)) { - Diag(DS.getStorageClassSpecLoc(), + Diag(DS.getStorageClassSpecLoc(), diag::err_anonymous_union_with_storage_spec); Invalid = true; @@ -1459,7 +1459,7 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, PrevSpec, DiagID); } - // C++ [class.union]p2: + // C++ [class.union]p2: // The member-specification of an anonymous union shall only // define non-static data members. [Note: nested types and // functions cannot be declared within an anonymous union. ] @@ -1505,7 +1505,7 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, Invalid = true; } } - } + } if (!Record->isUnion() && !Owner->isRecord()) { Diag(Record->getLocation(), diag::err_anonymous_struct_not_member) @@ -1513,11 +1513,11 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, Invalid = true; } - // Create a declaration for this anonymous struct/union. + // Create a declaration for this anonymous struct/union. NamedDecl *Anon = 0; if (RecordDecl *OwningClass = dyn_cast<RecordDecl>(Owner)) { Anon = FieldDecl::Create(Context, OwningClass, Record->getLocation(), - /*IdentifierInfo=*/0, + /*IdentifierInfo=*/0, Context.getTypeDeclType(Record), // FIXME: Type source info. /*DInfo=*/0, @@ -1545,7 +1545,7 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, } Anon = VarDecl::Create(Context, Owner, Record->getLocation(), - /*IdentifierInfo=*/0, + /*IdentifierInfo=*/0, Context.getTypeDeclType(Record), // FIXME: Type source info. /*DInfo=*/0, @@ -1569,7 +1569,7 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, // members of this anonymous struct/union type, because otherwise // the members could be injected twice: once by DeclContext when it // builds its lookup table, and once by - // InjectAnonymousStructOrUnionMembers. + // InjectAnonymousStructOrUnionMembers. Record->setAnonymousStructOrUnion(true); if (Invalid) @@ -1643,8 +1643,8 @@ static bool isNearlyMatchingFunction(ASTContext &Context, return true; } -Sema::DeclPtrTy -Sema::HandleDeclarator(Scope *S, Declarator &D, +Sema::DeclPtrTy +Sema::HandleDeclarator(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParamLists, bool IsFunctionDefinition) { DeclarationName Name = GetNameForDeclarator(D); @@ -1658,13 +1658,13 @@ Sema::HandleDeclarator(Scope *S, Declarator &D, << D.getDeclSpec().getSourceRange() << D.getSourceRange(); return DeclPtrTy(); } - + // The scope passed in may not be a decl scope. Zip up the scope tree until // we find one that is. while ((S->getFlags() & Scope::DeclScope) == 0 || (S->getFlags() & Scope::TemplateParamScope) != 0) S = S->getParent(); - + // If this is an out-of-line definition of a member of a class template // or class template partial specialization, we may need to rebuild the // type specifier in the declarator. See RebuildTypeInCurrentInstantiation() @@ -1689,7 +1689,7 @@ Sema::HandleDeclarator(Scope *S, Declarator &D, DS.UpdateTypeRep(T.getAsOpaquePtr()); } } - + DeclContext *DC; NamedDecl *PrevDecl; NamedDecl *New; @@ -1721,24 +1721,24 @@ Sema::HandleDeclarator(Scope *S, Declarator &D, NameKind = LookupRedeclarationWithLinkage; DC = CurContext; - PrevDecl = LookupName(S, Name, NameKind, true, + PrevDecl = LookupName(S, Name, NameKind, true, NameKind == LookupRedeclarationWithLinkage, D.getIdentifierLoc()); } else { // Something like "int foo::x;" DC = computeDeclContext(D.getCXXScopeSpec(), true); - + if (!DC) { // If we could not compute the declaration context, it's because the // declaration context is dependent but does not refer to a class, // class template, or class template partial specialization. Complain // and return early, to avoid the coming semantic disaster. - Diag(D.getIdentifierLoc(), + Diag(D.getIdentifierLoc(), diag::err_template_qualified_declarator_no_match) << (NestedNameSpecifier*)D.getCXXScopeSpec().getScopeRep() << D.getCXXScopeSpec().getRange(); return DeclPtrTy(); } - + PrevDecl = LookupQualifiedName(DC, Name, LookupOrdinaryName, true); // C++ 7.3.1.2p2: @@ -1762,11 +1762,11 @@ Sema::HandleDeclarator(Scope *S, Declarator &D, // // In this case, PrevDecl will point to the overload set // containing the two f's declared in X, but neither of them - // matches. + // matches. // First check whether we named the global scope. if (isa<TranslationUnitDecl>(DC)) { - Diag(D.getIdentifierLoc(), diag::err_invalid_declarator_global_scope) + Diag(D.getIdentifierLoc(), diag::err_invalid_declarator_global_scope) << Name << D.getCXXScopeSpec().getRange(); } else if (!CurContext->Encloses(DC)) { // The qualifying scope doesn't enclose the original declaration. @@ -1775,7 +1775,7 @@ Sema::HandleDeclarator(Scope *S, Declarator &D, SourceRange R = D.getCXXScopeSpec().getRange(); if (isa<FunctionDecl>(CurContext)) Diag(L, diag::err_invalid_declarator_in_function) << Name << R; - else + else Diag(L, diag::err_invalid_declarator_scope) << Name << cast<NamedDecl>(DC) << R; D.setInvalidType(); @@ -1784,10 +1784,10 @@ Sema::HandleDeclarator(Scope *S, Declarator &D, if (PrevDecl && PrevDecl->isTemplateParameter()) { // Maybe we will complain about the shadowed template parameter. - if (!D.isInvalidType()) + if (!D.isInvalidType()) if (DiagnoseTemplateParameterShadow(D.getIdentifierLoc(), PrevDecl)) D.setInvalidType(); - + // Just pretend that we didn't see the previous declaration. PrevDecl = 0; } @@ -1806,26 +1806,26 @@ Sema::HandleDeclarator(Scope *S, Declarator &D, Diag(D.getIdentifierLoc(), diag::err_template_typedef); return DeclPtrTy(); } - + New = ActOnTypedefDeclarator(S, D, DC, R, DInfo, PrevDecl, Redeclaration); } else if (R->isFunctionType()) { - New = ActOnFunctionDeclarator(S, D, DC, R, DInfo, PrevDecl, + New = ActOnFunctionDeclarator(S, D, DC, R, DInfo, PrevDecl, move(TemplateParamLists), IsFunctionDefinition, Redeclaration); } else { - New = ActOnVariableDeclarator(S, D, DC, R, DInfo, PrevDecl, + New = ActOnVariableDeclarator(S, D, DC, R, DInfo, PrevDecl, move(TemplateParamLists), Redeclaration); } if (New == 0) return DeclPtrTy(); - + // If this has an identifier and is not an invalid redeclaration, // add it to the scope stack. if (Name && !(Redeclaration && New->isInvalidDecl())) PushOnScopeChains(New, S); - + return DeclPtrTy::make(New); } @@ -1857,7 +1857,7 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T, // FIXME: We should probably handle this case if (VLATy->getElementType()->isVariablyModifiedType()) return QualType(); - + Expr::EvalResult EvalResult; if (!VLATy->getSizeExpr() || !VLATy->getSizeExpr()->Evaluate(EvalResult, Context) || @@ -1884,7 +1884,7 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T, /// \brief Register the given locally-scoped external C declaration so /// that it can be found later for redeclarations -void +void Sema::RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl, Scope *S) { assert(ND->getLexicalDeclContext()->isFunctionOrMethod() && @@ -1915,15 +1915,15 @@ void Sema::DiagnoseFunctionSpecifiers(Declarator& D) { // FIXME: We should probably indicate the identifier in question to avoid // confusion for constructs like "inline int a(), b;" if (D.getDeclSpec().isInlineSpecified()) - Diag(D.getDeclSpec().getInlineSpecLoc(), + Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_non_function); if (D.getDeclSpec().isVirtualSpecified()) - Diag(D.getDeclSpec().getVirtualSpecLoc(), + Diag(D.getDeclSpec().getVirtualSpecLoc(), diag::err_virtual_non_function); if (D.getDeclSpec().isExplicitSpecified()) - Diag(D.getDeclSpec().getExplicitSpecLoc(), + Diag(D.getDeclSpec().getExplicitSpecLoc(), diag::err_explicit_non_function); } @@ -1952,7 +1952,7 @@ Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, TypedefDecl *NewTD = ParseTypedefDecl(S, D, R); if (!NewTD) return 0; - + if (D.isInvalidType()) NewTD->setInvalidDecl(); @@ -1970,7 +1970,7 @@ Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, QualType T = NewTD->getUnderlyingType(); if (T->isVariablyModifiedType()) { CurFunctionNeedsScopeChecking = true; - + if (S->getFnParent() == 0) { bool SizeIsNegative; QualType FixedTy = @@ -2017,13 +2017,13 @@ Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, /// /// \param PrevDecl the previous declaration found by name /// lookup -/// +/// /// \param DC the context in which the new declaration is being /// declared. /// /// \returns true if PrevDecl is an out-of-scope previous declaration /// for a new delcaration with the same name. -static bool +static bool isOutOfScopePreviousDeclaration(NamedDecl *PrevDecl, DeclContext *DC, ASTContext &Context) { if (!PrevDecl) @@ -2057,10 +2057,10 @@ isOutOfScopePreviousDeclaration(NamedDecl *PrevDecl, DeclContext *DC, OuterContext = OuterContext->getParent(); while (!PrevOuterContext->isFileContext()) PrevOuterContext = PrevOuterContext->getParent(); - + // The previous declaration is in a different namespace, so it // isn't the same function. - if (OuterContext->getPrimaryContext() != + if (OuterContext->getPrimaryContext() != PrevOuterContext->getPrimaryContext()) return false; } @@ -2114,7 +2114,7 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, // C99 6.9p2: The storage-class specifiers auto and register shall not // appear in the declaration specifiers in an external declaration. if (SC == VarDecl::Auto || SC == VarDecl::Register) { - + // If this is a register variable with an asm label specified, then this // is a GNU extension. if (SC == VarDecl::Register && D.getAsmLabel()) @@ -2127,7 +2127,7 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, if (DC->isRecord() && !CurContext->isRecord()) { // This is an out-of-line definition of a static data member. if (SC == VarDecl::Static) { - Diag(D.getDeclSpec().getStorageClassSpecLoc(), + Diag(D.getDeclSpec().getStorageClassSpecLoc(), diag::err_static_out_of_line) << CodeModificationHint::CreateRemoval( SourceRange(D.getDeclSpec().getStorageClassSpecLoc())); @@ -2137,12 +2137,12 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, if (SC == VarDecl::Static) { if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) { if (RD->isLocalClass()) - Diag(D.getIdentifierLoc(), + Diag(D.getIdentifierLoc(), diag::err_static_data_member_not_allowed_in_local_class) << Name << RD->getDeclName(); } } - + // Match up the template parameter lists with the scope specifier, then // determine whether we have a template or a template specialization. if (TemplateParameterList *TemplateParams @@ -2161,20 +2161,20 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, } else { // There is an extraneous 'template<>' for this variable. Complain // about it, but allow the declaration of the variable. - Diag(TemplateParams->getTemplateLoc(), + Diag(TemplateParams->getTemplateLoc(), diag::err_template_variable_noparams) << II << SourceRange(TemplateParams->getTemplateLoc(), - TemplateParams->getRAngleLoc()); + TemplateParams->getRAngleLoc()); } - } - - NewVD = VarDecl::Create(Context, DC, D.getIdentifierLoc(), + } + + NewVD = VarDecl::Create(Context, DC, D.getIdentifierLoc(), II, R, DInfo, SC); if (D.isInvalidType()) NewVD->setInvalidDecl(); - + if (D.getDeclSpec().isThreadSpecified()) { if (NewVD->hasLocalStorage()) Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_thread_non_global); @@ -2194,7 +2194,7 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, // Handle GNU asm-label extension (encoded as an attribute). if (Expr *E = (Expr*) D.getAsmLabel()) { // The parser guarantees this is a string. - StringLiteral *SE = cast<StringLiteral>(E); + StringLiteral *SE = cast<StringLiteral>(E); NewVD->addAttr(::new (Context) AsmLabelAttr(std::string(SE->getStrData(), SE->getByteLength()))); } @@ -2205,7 +2205,7 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, if (PrevDecl && !isDeclInScope(PrevDecl, DC, S) && !(NewVD->hasLinkage() && isOutOfScopePreviousDeclaration(PrevDecl, DC, Context))) - PrevDecl = 0; + PrevDecl = 0; // Merge the decl with the existing one if appropriate. if (PrevDecl) { @@ -2219,9 +2219,9 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, } } else if (D.getCXXScopeSpec().isSet()) { // No previous declaration in the qualifying scope. - NestedNameSpecifier *NNS = + NestedNameSpecifier *NNS = (NestedNameSpecifier *)D.getCXXScopeSpec().getScopeRep(); - DiagnoseMissingMember(D.getIdentifierLoc(), Name, NNS, + DiagnoseMissingMember(D.getIdentifierLoc(), Name, NNS, D.getCXXScopeSpec().getRange()); NewVD->setInvalidDecl(); } @@ -2261,17 +2261,17 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl, // If the decl is already known invalid, don't check it. if (NewVD->isInvalidDecl()) return; - + QualType T = NewVD->getType(); if (T->isObjCInterfaceType()) { Diag(NewVD->getLocation(), diag::err_statically_allocated_object); return NewVD->setInvalidDecl(); } - + // The variable can not have an abstract class type. if (RequireNonAbstractType(NewVD->getLocation(), T, - diag::err_abstract_type_in_decl, + diag::err_abstract_type_in_decl, AbstractVariableType)) return NewVD->setInvalidDecl(); @@ -2292,19 +2292,19 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl, if (isVM || NewVD->hasAttr<CleanupAttr>() || NewVD->hasAttr<BlocksAttr>()) CurFunctionNeedsScopeChecking = true; - + if ((isVM && NewVD->hasLinkage()) || (T->isVariableArrayType() && NewVD->hasGlobalStorage())) { bool SizeIsNegative; QualType FixedTy = TryToFixInvalidVariablyModifiedType(T, Context, SizeIsNegative); - + if (FixedTy.isNull() && T->isVariableArrayType()) { const VariableArrayType *VAT = Context.getAsVariableArrayType(T); - // FIXME: This won't give the correct result for - // int a[10][n]; + // FIXME: This won't give the correct result for + // int a[10][n]; SourceRange SizeRange = VAT->getSizeExpr()->getSourceRange(); - + if (NewVD->isFileVarDecl()) Diag(NewVD->getLocation(), diag::err_vla_decl_in_file_scope) << SizeRange; @@ -2315,8 +2315,8 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl, Diag(NewVD->getLocation(), diag::err_vla_decl_has_extern_linkage) << SizeRange; return NewVD->setInvalidDecl(); - } - + } + if (FixedTy.isNull()) { if (NewVD->isFileVarDecl()) Diag(NewVD->getLocation(), diag::err_vm_decl_in_file_scope); @@ -2324,7 +2324,7 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl, Diag(NewVD->getLocation(), diag::err_vm_decl_has_extern_linkage); return NewVD->setInvalidDecl(); } - + Diag(NewVD->getLocation(), diag::warn_illegal_constant_array_size); NewVD->setType(FixedTy); } @@ -2349,7 +2349,7 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl, Diag(NewVD->getLocation(), diag::err_block_on_nonlocal); return NewVD->setInvalidDecl(); } - + if (isVM && NewVD->hasAttr<BlocksAttr>()) { Diag(NewVD->getLocation(), diag::err_block_on_vm); return NewVD->setInvalidDecl(); @@ -2365,7 +2365,7 @@ static bool isUsingDecl(Decl *D) { return isa<UsingDecl>(D) || isa<UnresolvedUsingDecl>(D); } -NamedDecl* +NamedDecl* Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, QualType R, DeclaratorInfo *DInfo, NamedDecl* PrevDecl, @@ -2380,7 +2380,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, case DeclSpec::SCS_auto: case DeclSpec::SCS_register: case DeclSpec::SCS_mutable: - Diag(D.getDeclSpec().getStorageClassSpecLoc(), + Diag(D.getDeclSpec().getStorageClassSpecLoc(), diag::err_typecheck_sclass_func); D.setInvalidType(); break; @@ -2393,11 +2393,11 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // block scope shall have no explicit storage-class specifier // other than extern // See also (C++ [dcl.stc]p4). - Diag(D.getDeclSpec().getStorageClassSpecLoc(), + Diag(D.getDeclSpec().getStorageClassSpecLoc(), diag::err_static_block_func); SC = FunctionDecl::None; } else - SC = FunctionDecl::Static; + SC = FunctionDecl::Static; break; } case DeclSpec::SCS_private_extern: SC = FunctionDecl::PrivateExtern;break; @@ -2413,14 +2413,14 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // Check that the return type is not an abstract class type. // For record types, this is done by the AbstractClassUsageDiagnoser once - // the class has been completely parsed. + // the class has been completely parsed. if (!DC->isRecord() && - RequireNonAbstractType(D.getIdentifierLoc(), + RequireNonAbstractType(D.getIdentifierLoc(), R->getAsFunctionType()->getResultType(), - diag::err_abstract_type_in_decl, + diag::err_abstract_type_in_decl, AbstractReturnType)) D.setInvalidType(); - + // Do not allow returning a objc interface by-value. if (R->getAsFunctionType()->getResultType()->isObjCInterfaceType()) { Diag(D.getIdentifierLoc(), @@ -2451,7 +2451,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, R = CheckConstructorDeclarator(D, R, SC); // Create the new declaration - NewFD = CXXConstructorDecl::Create(Context, + NewFD = CXXConstructorDecl::Create(Context, cast<CXXRecordDecl>(DC), D.getIdentifierLoc(), Name, R, DInfo, isExplicit, isInline, @@ -2460,10 +2460,10 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // This is a C++ destructor declaration. if (DC->isRecord()) { R = CheckDestructorDeclarator(D, SC); - + NewFD = CXXDestructorDecl::Create(Context, cast<CXXRecordDecl>(DC), - D.getIdentifierLoc(), Name, R, + D.getIdentifierLoc(), Name, R, isInline, /*isImplicitlyDeclared=*/false); @@ -2474,7 +2474,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // Create a FunctionDecl to satisfy the function definition parsing // code path. NewFD = FunctionDecl::Create(Context, DC, D.getIdentifierLoc(), - Name, R, DInfo, SC, isInline, + Name, R, DInfo, SC, isInline, /*hasPrototype=*/true); D.setInvalidType(); } @@ -2484,26 +2484,26 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, diag::err_conv_function_not_member); return 0; } - + CheckConversionDeclarator(D, R, SC); NewFD = CXXConversionDecl::Create(Context, cast<CXXRecordDecl>(DC), D.getIdentifierLoc(), Name, R, DInfo, isInline, isExplicit); - + isVirtualOkay = true; } else if (DC->isRecord()) { // If the of the function is the same as the name of the record, then this - // must be an invalid constructor that has a return type. - // (The parser checks for a return type and makes the declarator a + // must be an invalid constructor that has a return type. + // (The parser checks for a return type and makes the declarator a // constructor if it has no return type). - // must have an invalid constructor that has a return type + // must have an invalid constructor that has a return type if (Name.getAsIdentifierInfo() == cast<CXXRecordDecl>(DC)->getIdentifier()){ Diag(D.getIdentifierLoc(), diag::err_constructor_return_type) << SourceRange(D.getDeclSpec().getTypeSpecTypeLoc()) << SourceRange(D.getIdentifierLoc()); return 0; } - + // This is a C++ method declaration. NewFD = CXXMethodDecl::Create(Context, cast<CXXRecordDecl>(DC), D.getIdentifierLoc(), Name, R, DInfo, @@ -2517,11 +2517,11 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // - there is a prototype in the declarator, or // - the type R of the function is some kind of typedef or other reference // to a type name (which eventually refers to a function type). - bool HasPrototype = + bool HasPrototype = getLangOptions().CPlusPlus || (D.getNumTypeObjects() && D.getTypeObject(0).Fun.hasPrototype) || (!isa<FunctionType>(R.getTypePtr()) && R->isFunctionProtoType()); - + NewFD = FunctionDecl::Create(Context, DC, D.getIdentifierLoc(), Name, R, DInfo, SC, isInline, HasPrototype); @@ -2529,7 +2529,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, if (D.isInvalidType()) NewFD->setInvalidDecl(); - + // Set the lexical context. If the declarator has a C++ // scope specifier, or is the object of a friend declaration, the // lexical context will be different from the semantic context. @@ -2549,11 +2549,11 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, TemplateParamLists.size())) { if (TemplateParams->size() > 0) { // This is a function template - + // Check that we can declare a template here. if (CheckTemplateDeclScope(S, TemplateParams)) return 0; - + FunctionTemplate = FunctionTemplateDecl::Create(Context, DC, NewFD->getLocation(), Name, TemplateParams, @@ -2563,11 +2563,11 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, } else { // FIXME: Handle function template specializations } - + // FIXME: Free this memory properly. TemplateParamLists.release(); - } - + } + // C++ [dcl.fct.spec]p5: // The virtual specifier shall only be used in declarations of // nonstatic class member functions that appear within a @@ -2575,7 +2575,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // if (isVirtual && !NewFD->isInvalidDecl()) { if (!isVirtualOkay) { - Diag(D.getDeclSpec().getVirtualSpecLoc(), + Diag(D.getDeclSpec().getVirtualSpecLoc(), diag::err_virtual_non_function); } else if (!CurContext->isRecord()) { // 'virtual' was specified outside of the class. @@ -2600,9 +2600,9 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // Look for virtual methods in base classes that this method might override. BasePaths Paths; - if (LookupInBases(cast<CXXRecordDecl>(DC), + if (LookupInBases(cast<CXXRecordDecl>(DC), MemberLookupCriteria(NewMD), Paths)) { - for (BasePaths::decl_iterator I = Paths.found_decls_begin(), + for (BasePaths::decl_iterator I = Paths.found_decls_begin(), E = Paths.found_decls_end(); I != E; ++I) { if (CXXMethodDecl *OldMD = dyn_cast<CXXMethodDecl>(*I)) { if (!CheckOverridingFunctionReturnType(NewMD, OldMD) && @@ -2612,8 +2612,8 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, } } } - - if (SC == FunctionDecl::Static && isa<CXXMethodDecl>(NewFD) && + + if (SC == FunctionDecl::Static && isa<CXXMethodDecl>(NewFD) && !CurContext->isRecord()) { // C++ [class.static]p1: // A data or function member of a class may be declared static @@ -2622,7 +2622,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // Complain about the 'static' specifier if it's on an out-of-line // member function definition. - Diag(D.getDeclSpec().getStorageClassSpecLoc(), + Diag(D.getDeclSpec().getStorageClassSpecLoc(), diag::err_static_out_of_line) << CodeModificationHint::CreateRemoval( SourceRange(D.getDeclSpec().getStorageClassSpecLoc())); @@ -2631,7 +2631,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // Handle GNU asm-label extension (encoded as an attribute). if (Expr *E = (Expr*) D.getAsmLabel()) { // The parser guarantees this is a string. - StringLiteral *SE = cast<StringLiteral>(E); + StringLiteral *SE = cast<StringLiteral>(E); NewFD->addAttr(::new (Context) AsmLabelAttr(std::string(SE->getStrData(), SE->getByteLength()))); } @@ -2667,7 +2667,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, Params.push_back(Param); } } - + } else if (const FunctionProtoType *FT = R->getAsFunctionProtoType()) { // When we're declaring a function with a typedef, typeof, etc as in the // following example, we'll need to synthesize (unnamed) @@ -2677,7 +2677,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // typedef void fn(int); // fn f; // @endcode - + // Synthesize a parameter for each argument type. for (FunctionProtoType::arg_type_iterator AI = FT->arg_type_begin(), AE = FT->arg_type_end(); AI != AE; ++AI) { @@ -2694,7 +2694,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, } // Finally, we know we have the right number of parameters, install them. NewFD->setParams(Context, Params.data(), Params.size()); - + // If name lookup finds a previous declaration that is not in the // same scope as the new declaration, this may still be an // acceptable redeclaration. @@ -2718,12 +2718,12 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, } else if (!Redeclaration && (!PrevDecl || !isUsingDecl(PrevDecl))) { // The user tried to provide an out-of-line definition for a // function that is a member of a class or namespace, but there - // was no such member function declared (C++ [class.mfct]p2, + // was no such member function declared (C++ [class.mfct]p2, // C++ [namespace.memdef]p2). For example: - // + // // class X { // void f() const; - // }; + // }; // // void X::f() { } // ill-formed // @@ -2733,10 +2733,10 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, Diag(D.getIdentifierLoc(), diag::err_member_def_does_not_match) << cast<NamedDecl>(DC) << D.getCXXScopeSpec().getRange(); NewFD->setInvalidDecl(); - - LookupResult Prev = LookupQualifiedName(DC, Name, LookupOrdinaryName, + + LookupResult Prev = LookupQualifiedName(DC, Name, LookupOrdinaryName, true); - assert(!Prev.isAmbiguous() && + assert(!Prev.isAmbiguous() && "Cannot have an ambiguity in previous-declaration lookup"); for (LookupResult::iterator Func = Prev.begin(), FuncEnd = Prev.end(); Func != FuncEnd; ++Func) { @@ -2744,7 +2744,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, isNearlyMatchingFunction(Context, cast<FunctionDecl>(*Func), NewFD)) Diag((*Func)->getLocation(), diag::note_member_def_close_match); } - + PrevDecl = 0; } } @@ -2772,7 +2772,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, Diag(NewFD->getLocation(), diag::err_attribute_overloadable_missing) << Redeclaration << NewFD; if (PrevDecl) - Diag(PrevDecl->getLocation(), + Diag(PrevDecl->getLocation(), diag::note_attribute_overloadable_prev_overload); NewFD->addAttr(::new (Context) OverloadableAttr()); } @@ -2788,10 +2788,10 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, if (FunctionTemplate && NewFD->isInvalidDecl()) FunctionTemplate->setInvalidDecl(); - + if (FunctionTemplate) return FunctionTemplate; - + return NewFD; } @@ -2831,27 +2831,27 @@ void Sema::CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl, CXXRecordDecl *Record = cast<CXXRecordDecl>(NewFD->getParent()); QualType ClassType = Context.getTypeDeclType(Record); if (!ClassType->isDependentType()) { - DeclarationName Name + DeclarationName Name = Context.DeclarationNames.getCXXDestructorName( Context.getCanonicalType(ClassType)); if (NewFD->getDeclName() != Name) { Diag(NewFD->getLocation(), diag::err_destructor_name); - return NewFD->setInvalidDecl(); + return NewFD->setInvalidDecl(); } } Record->setUserDeclaredDestructor(true); // C++ [class]p4: A POD-struct is an aggregate class that has [...] no // user-defined destructor. Record->setPOD(false); - + // C++ [class.dtor]p3: A destructor is trivial if it is an implicitly- // declared destructor. // FIXME: C++0x: don't do this for "= default" destructors Record->setHasTrivialDestructor(false); - } else if (CXXConversionDecl *Conversion + } else if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(NewFD)) ActOnConversionDeclarator(Conversion); - + // Extra checking for C++ overloaded operators (C++ [over.oper]). if (NewFD->isOverloadedOperator() && CheckOverloadedOperatorDeclaration(NewFD)) @@ -2871,7 +2871,7 @@ void Sema::CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl, // Here we determine whether this function, in isolation, would be a // C99 inline definition. MergeCompatibleFunctionDecls looks at // previous declarations. - if (NewFD->isInline() && getLangOptions().C99 && + if (NewFD->isInline() && getLangOptions().C99 && NewFD->getStorageClass() == FunctionDecl::None && NewFD->getDeclContext()->getLookupContext()->isTranslationUnit()) NewFD->setC99InlineDefinition(true); @@ -2917,7 +2917,7 @@ void Sema::CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl, } if (PrevDecl && - (!AllowOverloadingOfFunction(PrevDecl, Context) || + (!AllowOverloadingOfFunction(PrevDecl, Context) || !IsOverload(NewFD, PrevDecl, MatchedDecl)) && !isUsingDecl(PrevDecl)) { Redeclaration = true; Decl *OldDecl = PrevDecl; @@ -2928,7 +2928,7 @@ void Sema::CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl, OldDecl = *MatchedDecl; // NewFD and OldDecl represent declarations that need to be - // merged. + // merged. if (MergeFunctionDecl(NewFD, OldDecl)) return NewFD->setInvalidDecl(); @@ -2970,7 +2970,7 @@ void Sema::CheckMain(FunctionDecl* FD) { QualType T = FD->getType(); assert(T->isFunctionType() && "function decl is not of function type"); const FunctionType* FT = T->getAsFunctionType(); - + if (!Context.hasSameUnqualifiedType(FT->getResultType(), Context.IntTy)) { // TODO: add a replacement fixit to turn the return type into 'int'. Diag(FD->getTypeSpecStartLoc(), diag::err_main_returns_nonint); @@ -3061,7 +3061,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { // the initializer. if (RealDecl == 0) return; - + if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(RealDecl)) { // With declarators parsed the way they are, the parser cannot // distinguish between a normal initializer and a pure-specifier. @@ -3110,7 +3110,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { const VarDecl *Def = 0; if (VDecl->getDefinition(Def)) { - Diag(VDecl->getLocation(), diag::err_redefinition) + Diag(VDecl->getLocation(), diag::err_redefinition) << VDecl->getDeclName(); Diag(Def->getLocation(), diag::note_previous_definition); VDecl->setInvalidDecl(); @@ -3133,7 +3133,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { if (CheckInitializerTypes(Init, DclT, VDecl->getLocation(), VDecl->getDeclName(), DirectInit)) VDecl->setInvalidDecl(); - + // C++ 3.6.2p2, allow dynamic initialization of static initializers. // Don't check invalid declarations to avoid emitting useless diagnostics. if (!getLangOptions().CPlusPlus && !VDecl->isInvalidDecl()) { @@ -3141,7 +3141,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { CheckForConstantInitializer(Init, DclT); } } - } else if (VDecl->isStaticDataMember() && + } else if (VDecl->isStaticDataMember() && VDecl->getLexicalDeclContext()->isRecord()) { // This is an in-class initialization for a static data member, e.g., // @@ -3157,7 +3157,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { // if it declares a static member (9.4) of const integral or // const enumeration type, see 9.4.2. QualType T = VDecl->getType(); - if (!T->isDependentType() && + if (!T->isDependentType() && (!Context.getCanonicalType(T).isConstQualified() || !T->isIntegralType())) { Diag(VDecl->getLocation(), diag::err_member_initialization) @@ -3172,7 +3172,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { if (!Init->isTypeDependent() && !Init->getType()->isIntegralType()) { // We have a non-dependent, non-integral or enumeration type. - Diag(Init->getSourceRange().getBegin(), + Diag(Init->getSourceRange().getBegin(), diag::err_in_class_initializer_non_integral_type) << Init->getType() << Init->getSourceRange(); VDecl->setInvalidDecl(); @@ -3195,7 +3195,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { if (CheckInitializerTypes(Init, DclT, VDecl->getLocation(), VDecl->getDeclName(), DirectInit)) VDecl->setInvalidDecl(); - + // C++ 3.6.2p2, allow dynamic initialization of static initializers. // Don't check invalid declarations to avoid emitting useless diagnostics. if (!getLangOptions().CPlusPlus && !VDecl->isInvalidDecl()) { @@ -3204,15 +3204,15 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { } } // If the type changed, it means we had an incomplete type that was - // completed by the initializer. For example: + // completed by the initializer. For example: // int ary[] = { 1, 3, 5 }; // "ary" transitions from a VariableArrayType to a ConstantArrayType. if (!VDecl->isInvalidDecl() && (DclT != SavT)) { VDecl->setType(DclT); Init->setType(DclT); } - - Init = MaybeCreateCXXExprWithTemporaries(Init, + + Init = MaybeCreateCXXExprWithTemporaries(Init, /*ShouldDestroyTemporaries=*/true); // Attach the initializer to the decl. VDecl->setInit(Context, Init); @@ -3228,7 +3228,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { return; } -void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, +void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, bool TypeContainsUndeducedAuto) { Decl *RealDecl = dcl.getAs<Decl>(); @@ -3242,9 +3242,9 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, // Record tentative definitions. if (Var->isTentativeDefinition(Context)) { std::pair<llvm::DenseMap<DeclarationName, VarDecl *>::iterator, bool> - InsertPair = + InsertPair = TentativeDefinitions.insert(std::make_pair(Var->getDeclName(), Var)); - + // Keep the latest definition in the map. If we see 'int i; int i;' we // want the second one in the map. InsertPair.first->second = Var; @@ -3276,7 +3276,7 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, Var->setInvalidDecl(); return; } - + // C++ [dcl.init]p9: // // If no initializer is specified for an object, and the object @@ -3290,13 +3290,13 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, InitType = Array->getElementType(); if ((!Var->hasExternalStorage() && !Var->isExternC(Context)) && InitType->isRecordType() && !InitType->isDependentType()) { - CXXRecordDecl *RD = + CXXRecordDecl *RD = cast<CXXRecordDecl>(InitType->getAs<RecordType>()->getDecl()); CXXConstructorDecl *Constructor = 0; - if (!RequireCompleteType(Var->getLocation(), InitType, + if (!RequireCompleteType(Var->getLocation(), InitType, diag::err_invalid_incomplete_type_use)) Constructor - = PerformInitializationByConstructor(InitType, 0, 0, + = PerformInitializationByConstructor(InitType, 0, 0, Var->getLocation(), SourceRange(Var->getLocation(), Var->getLocation()), @@ -3304,13 +3304,13 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, IK_Default); if (!Constructor) Var->setInvalidDecl(); - else { + else { if (!RD->hasTrivialConstructor() || !RD->hasTrivialDestructor()) { - if (InitializeVarWithConstructor(Var, Constructor, InitType, + if (InitializeVarWithConstructor(Var, Constructor, InitType, MultiExprArg(*this))) Var->setInvalidDecl(); } - + FinalizeVarWithDestructor(Var, InitType); } } @@ -3318,7 +3318,7 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, #if 0 // FIXME: Temporarily disabled because we are not properly parsing - // linkage specifications on declarations, e.g., + // linkage specifications on declarations, e.g., // // extern "C" const CGPoint CGPointerZero; // @@ -3360,7 +3360,7 @@ Sema::DeclGroupPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, for (unsigned i = 0; i != NumDecls; ++i) if (Decl *D = Group[i].getAs<Decl>()) Decls.push_back(D); - + // Perform semantic analysis that depends on having fully processed both // the declarator and initializer. for (unsigned i = 0, e = Decls.size(); i != e; ++i) { @@ -3368,12 +3368,12 @@ Sema::DeclGroupPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, if (!IDecl) continue; QualType T = IDecl->getType(); - + // Block scope. C99 6.7p7: If an identifier for an object is declared with // no linkage (C99 6.2.2p6), the type for the object shall be complete... if (IDecl->isBlockVarDecl() && !IDecl->hasExternalStorage()) { if (!IDecl->isInvalidDecl() && - RequireCompleteType(IDecl->getLocation(), T, + RequireCompleteType(IDecl->getLocation(), T, diag::err_typecheck_decl_incomplete_type)) IDecl->setInvalidDecl(); } @@ -3412,7 +3412,7 @@ Sema::DeclGroupPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, /// ActOnParamDeclarator - Called from Parser::ParseFunctionDeclarator() /// to introduce parameters into function prototype scope. -Sema::DeclPtrTy +Sema::DeclPtrTy Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { const DeclSpec &DS = D.getDeclSpec(); @@ -3435,12 +3435,12 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { // parameter (C++ only). if (getLangOptions().CPlusPlus) CheckExtraCXXDefaultArguments(D); - + DeclaratorInfo *DInfo = 0; TagDecl *OwnedDecl = 0; QualType parmDeclType = GetTypeForDeclarator(D, S, &DInfo, /*Skip=*/0, &OwnedDecl); - + if (getLangOptions().CPlusPlus && OwnedDecl && OwnedDecl->isDefinition()) { // C++ [dcl.fct]p6: // Types shall not be defined in return or parameter types. @@ -3471,26 +3471,26 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { // Parameters can not be abstract class types. // For record types, this is done by the AbstractClassUsageDiagnoser once - // the class has been completely parsed. - if (!CurContext->isRecord() && - RequireNonAbstractType(D.getIdentifierLoc(), parmDeclType, + // the class has been completely parsed. + if (!CurContext->isRecord() && + RequireNonAbstractType(D.getIdentifierLoc(), parmDeclType, diag::err_abstract_type_in_decl, AbstractParamType)) D.setInvalidType(true); QualType T = adjustParameterType(parmDeclType); - + ParmVarDecl *New; if (T == parmDeclType) // parameter type did not need adjustment - New = ParmVarDecl::Create(Context, CurContext, + New = ParmVarDecl::Create(Context, CurContext, D.getIdentifierLoc(), II, - parmDeclType, DInfo, StorageClass, + parmDeclType, DInfo, StorageClass, 0); else // keep track of both the adjusted and unadjusted types - New = OriginalParmVarDecl::Create(Context, CurContext, + New = OriginalParmVarDecl::Create(Context, CurContext, D.getIdentifierLoc(), II, T, DInfo, parmDeclType, StorageClass, 0); - + if (D.isInvalidType()) New->setInvalidDecl(); @@ -3501,7 +3501,7 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { diag::err_object_cannot_be_passed_returned_by_value) << 1 << T; New->setInvalidDecl(); } - + // Parameter declarators cannot be qualified (C++ [dcl.meaning]p1). if (D.getCXXScopeSpec().isSet()) { Diag(D.getIdentifierLoc(), diag::err_qualified_param_declarator) @@ -3546,14 +3546,14 @@ void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, DeclSpec DS; const char* PrevSpec; // unused unsigned DiagID; // unused - DS.SetTypeSpecType(DeclSpec::TST_int, FTI.ArgInfo[i].IdentLoc, + DS.SetTypeSpecType(DeclSpec::TST_int, FTI.ArgInfo[i].IdentLoc, PrevSpec, DiagID); Declarator ParamD(DS, Declarator::KNRTypeListContext); ParamD.SetIdentifier(FTI.ArgInfo[i].Ident, FTI.ArgInfo[i].IdentLoc); FTI.ArgInfo[i].Param = ActOnParamDeclarator(S, ParamD); } } - } + } } Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, @@ -3564,12 +3564,12 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun; if (FTI.hasPrototype) { - // FIXME: Diagnose arguments without names in C. + // FIXME: Diagnose arguments without names in C. } - + Scope *ParentScope = FnBodyScope->getParent(); - DeclPtrTy DP = HandleDeclarator(ParentScope, D, + DeclPtrTy DP = HandleDeclarator(ParentScope, D, MultiTemplateParamsArg(*this), /*IsFunctionDefinition=*/true); return ActOnStartOfFunctionDef(FnBodyScope, DP); @@ -3579,15 +3579,15 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) { if (!D) return D; FunctionDecl *FD = 0; - - if (FunctionTemplateDecl *FunTmpl + + if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D.getAs<Decl>())) FD = FunTmpl->getTemplatedDecl(); else FD = cast<FunctionDecl>(D.getAs<Decl>()); CurFunctionNeedsScopeChecking = false; - + // See if this is a redefinition. const FunctionDecl *Definition; if (FD->getBody(Definition)) { @@ -3653,7 +3653,7 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) { // Checking attributes of current function definition // dllimport attribute. - if (FD->getAttr<DLLImportAttr>() && + if (FD->getAttr<DLLImportAttr>() && (!FD->getAttr<DLLExportAttr>())) { // dllimport attribute cannot be applied to definition. if (!(FD->getAttr<DLLImportAttr>())->isInherited()) { @@ -3698,23 +3698,23 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg, FD->setHasImplicitReturnZero(true); else CheckFallThroughForFunctionDef(FD, Body); - + if (!FD->isInvalidDecl()) DiagnoseUnusedParameters(FD->param_begin(), FD->param_end()); - + // C++ [basic.def.odr]p2: // [...] A virtual member function is used if it is not pure. [...] if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FD)) if (Method->isVirtual() && !Method->isPure()) MarkDeclarationReferenced(Method->getLocation(), Method); - + assert(FD == getCurFunctionDecl() && "Function parsing confused"); } else if (ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(dcl)) { assert(MD == getCurMethodDecl() && "Method parsing confused"); MD->setBody(Body); CheckFallThroughForFunctionDef(MD, Body); MD->setEndLoc(Body->getLocEnd()); - + if (!MD->isInvalidDecl()) DiagnoseUnusedParameters(MD->param_begin(), MD->param_end()); } else { @@ -3727,21 +3727,21 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg, // Verify and clean out per-function state. assert(&getLabelMap() == &FunctionLabelMap && "Didn't pop block right?"); - + // Check goto/label use. for (llvm::DenseMap<IdentifierInfo*, LabelStmt*>::iterator I = FunctionLabelMap.begin(), E = FunctionLabelMap.end(); I != E; ++I) { LabelStmt *L = I->second; - + // Verify that we have no forward references left. If so, there was a goto // or address of a label taken, but no definition of it. Label fwd // definitions are indicated with a null substmt. if (L->getSubStmt() != 0) continue; - + // Emit error. Diag(L->getIdentLoc(), diag::err_undeclared_label_use) << L->getName(); - + // At this point, we have gotos that use the bogus label. Stitch it into // the function body so that they aren't leaked and that the AST is well // formed. @@ -3750,7 +3750,7 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg, L->Destroy(Context); continue; } - + // Otherwise, the body is valid: we want to stitch the label decl into the // function somewhere so that it is properly owned and so that the goto // has a valid target. Do this by creating a new compound stmt with the @@ -3773,13 +3773,13 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg, // Verify that that gotos and switch cases don't jump into scopes illegally. if (CurFunctionNeedsScopeChecking) DiagnoseInvalidJumps(Body); - - // C++ constructors that have function-try-blocks can't have return - // statements in the handlers of that block. (C++ [except.handle]p14) + + // C++ constructors that have function-try-blocks can't have return + // statements in the handlers of that block. (C++ [except.handle]p14) // Verify this. if (FD && isa<CXXConstructorDecl>(FD) && isa<CXXTryStmt>(Body)) DiagnoseReturnInConstructorExceptionHandler(cast<CXXTryStmt>(Body)); - + if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(dcl)) computeBaseOrMembersToDestroy(Destructor); return D; @@ -3787,7 +3787,7 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg, /// ImplicitlyDefineFunction - An undeclared identifier was used in a function /// call, forming a call to an implicitly defined function (per C99 6.5.1p2). -NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, +NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, Scope *S) { // Before we produce a declaration for an implicitly defined // function, see whether there was a locally-scoped declaration of @@ -3806,7 +3806,7 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, Diag(Loc, diag::ext_implicit_function_decl) << &II; else Diag(Loc, diag::warn_implicit_function_decl) << &II; - + // FIXME: handle stuff like: // void foo() { extern float X(); } // void bar() { X(); } <-- implicit decl for X in another scope. @@ -3829,8 +3829,8 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, DeclContext *PrevDC = CurContext; CurContext = Context.getTranslationUnitDecl(); - - FunctionDecl *FD = + + FunctionDecl *FD = dyn_cast<FunctionDecl>(ActOnDeclarator(TUScope, D).getAs<Decl>()); FD->setImplicit(); @@ -3879,10 +3879,10 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) { IdentifierInfo *Name = FD->getIdentifier(); if (!Name) return; - if ((!getLangOptions().CPlusPlus && + if ((!getLangOptions().CPlusPlus && FD->getDeclContext()->isTranslationUnit()) || (isa<LinkageSpecDecl>(FD->getDeclContext()) && - cast<LinkageSpecDecl>(FD->getDeclContext())->getLanguage() == + cast<LinkageSpecDecl>(FD->getDeclContext())->getLanguage() == LinkageSpecDecl::lang_c)) { // Okay: this could be a libc/libm/Objective-C function we know // about. @@ -3894,12 +3894,12 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) { if (const FormatAttr *Format = FD->getAttr<FormatAttr>()) { // FIXME: We known better than our headers. const_cast<FormatAttr *>(Format)->setType("printf"); - } else + } else FD->addAttr(::new (Context) FormatAttr("printf", 1, Name->isStr("NSLogv") ? 0 : 2)); } else if (Name->isStr("asprintf") || Name->isStr("vasprintf")) { // FIXME: asprintf and vasprintf aren't C99 functions. Should they be - // target-specific builtins, perhaps? + // target-specific builtins, perhaps? if (!FD->getAttr<FormatAttr>()) FD->addAttr(::new (Context) FormatAttr("printf", 2, Name->isStr("vasprintf") ? 0 : 3)); @@ -3909,16 +3909,16 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) { TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T) { assert(D.getIdentifier() && "Wrong callback for declspec without declarator"); assert(!T.isNull() && "GetTypeForDeclarator() returned null type"); - + // Scope manipulation handled by caller. TypedefDecl *NewTD = TypedefDecl::Create(Context, CurContext, D.getIdentifierLoc(), - D.getIdentifier(), + D.getIdentifier(), T); - + if (const TagType *TT = T->getAs<TagType>()) { TagDecl *TD = TT->getDecl(); - + // If the TagDecl that the TypedefDecl points to is an anonymous decl // keep track of the TypedefDecl. if (!TD->getIdentifier() && !TD->getTypedefForAnonDecl()) @@ -3935,7 +3935,7 @@ TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T) { /// as a redeclaration of the given tag declaration. /// /// \returns true if the new tag kind is acceptable, false otherwise. -bool Sema::isAcceptableTagRedeclaration(const TagDecl *Previous, +bool Sema::isAcceptableTagRedeclaration(const TagDecl *Previous, TagDecl::TagKind NewTag, SourceLocation NewTagLoc, const IdentifierInfo &Name) { @@ -3955,7 +3955,7 @@ bool Sema::isAcceptableTagRedeclaration(const TagDecl *Previous, TagDecl::TagKind OldTag = Previous->getTagKind(); if (OldTag == NewTag) return true; - + if ((OldTag == TagDecl::TK_struct || OldTag == TagDecl::TK_class) && (NewTag == TagDecl::TK_struct || NewTag == TagDecl::TK_class)) { // Warn about the struct/class tag mismatch. @@ -3990,7 +3990,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, OwnedDecl = false; TagDecl::TagKind Kind = TagDecl::getTagKindForTypeSpec(TagSpec); - + if (TUK != TUK_Reference) { if (TemplateParameterList *TemplateParams = MatchTemplateParametersToScopeSpecifier(KWLoc, SS, @@ -4011,9 +4011,9 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, // slightly better in ParseTemplate.cpp from bogus template // parameters. } - } - } - + } + } + DeclContext *SearchDC = CurContext; DeclContext *DC = CurContext; NamedDecl *PrevDecl = 0; @@ -4035,7 +4035,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, DC = computeDeclContext(SS, true); SearchDC = DC; // Look-up name inside 'foo::'. - PrevDecl + PrevDecl = dyn_cast_or_null<TagDecl>( LookupQualifiedName(DC, Name, LookupTagName, true).getAsDecl()); @@ -4087,7 +4087,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, if (PrevDecl) { // Check whether the previous declaration is usable. (void)DiagnoseUseOfDecl(PrevDecl, NameLoc); - + if (TagDecl *PrevTagDecl = dyn_cast<TagDecl>(PrevDecl)) { // If this is a use of a previous tag, or if the tag is already declared // in the same scope (so that the definition/declaration completes or @@ -4097,11 +4097,11 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, // Make sure that this wasn't declared as an enum and now used as a // struct or something similar. if (!isAcceptableTagRedeclaration(PrevTagDecl, Kind, KWLoc, *Name)) { - bool SafeToContinue + bool SafeToContinue = (PrevTagDecl->getTagKind() != TagDecl::TK_enum && Kind != TagDecl::TK_enum); if (SafeToContinue) - Diag(KWLoc, diag::err_use_with_wrong_tag) + Diag(KWLoc, diag::err_use_with_wrong_tag) << Name << CodeModificationHint::CreateReplacement(SourceRange(KWLoc), PrevTagDecl->getKindName()); @@ -4109,7 +4109,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, Diag(KWLoc, diag::err_use_with_wrong_tag) << Name; Diag(PrevDecl->getLocation(), diag::note_previous_use); - if (SafeToContinue) + if (SafeToContinue) Kind = PrevTagDecl->getTagKind(); else { // Recover by making this an anonymous redefinition. @@ -4151,7 +4151,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, TagType *Tag = cast<TagType>(Context.getTagDeclType(PrevTagDecl)); if (Tag->isBeingDefined()) { Diag(NameLoc, diag::err_nested_redefinition) << Name; - Diag(PrevTagDecl->getLocation(), + Diag(PrevTagDecl->getLocation(), diag::note_previous_definition); Name = 0; PrevDecl = 0; @@ -4168,7 +4168,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, } else { // If we get here, this is a definition of a new tag type in a nested - // scope, e.g. "struct foo; void bar() { struct foo; }", just create a + // scope, e.g. "struct foo; void bar() { struct foo; }", just create a // new decl/type. We set PrevDecl to NULL so that the entities // have distinct types. PrevDecl = 0; @@ -4196,7 +4196,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, } else if (TUK == TUK_Reference && SS.isEmpty() && Name && (Kind != TagDecl::TK_enum || !getLangOptions().CPlusPlus)) { // C++ [basic.scope.pdecl]p5: - // -- for an elaborated-type-specifier of the form + // -- for an elaborated-type-specifier of the form // // class-key identifier // @@ -4217,15 +4217,15 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, // // Find the context where we'll be declaring the tag. // FIXME: We would like to maintain the current DeclContext as the - // lexical context, + // lexical context, while (SearchDC->isRecord()) SearchDC = SearchDC->getParent(); // Find the scope where we'll be declaring the tag. - while (S->isClassScope() || + while (S->isClassScope() || (getLangOptions().CPlusPlus && S->isFunctionPrototypeScope()) || ((S->getFlags() & Scope::DeclScope) == 0) || - (S->getEntity() && + (S->getEntity() && ((DeclContext *)S->getEntity())->isTransparentContext())) S = S->getParent(); @@ -4243,12 +4243,12 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, } CreateNewDecl: - + // If there is an identifier, use the location of the identifier as the // location of the decl, otherwise use the location of the struct/union // keyword. SourceLocation Loc = NameLoc.isValid() ? NameLoc : KWLoc; - + // Otherwise, create a new declaration. If there is a previous // declaration of the same entity, the two will be linked via // PrevDecl. @@ -4342,7 +4342,7 @@ CreateNewDecl: if (TUK == TUK_Definition) New->startDefinition(); - + // If this has an identifier, add it to the scope stack. if (TUK == TUK_Friend) { // We might be replacing an existing declaration in the lookup tables; @@ -4370,7 +4370,7 @@ CreateNewDecl: New->getDeclContext()->getLookupContext()->isTranslationUnit() && II->isStr("FILE")) Context.setFILEDecl(New); - + OwnedDecl = true; return DeclPtrTy::make(New); } @@ -4386,7 +4386,7 @@ void Sema::ActOnTagStartDefinition(Scope *S, DeclPtrTy TagD) { FieldCollector->StartClass(); if (Record->getIdentifier()) { - // C++ [class]p2: + // C++ [class]p2: // [...] The class-name is also inserted into the scope of the // class itself; this is known as the injected-class-name. For // purposes of access checking, the injected-class-name is treated @@ -4402,7 +4402,7 @@ void Sema::ActOnTagStartDefinition(Scope *S, DeclPtrTy TagD) { if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) InjectedClassName->setDescribedClassTemplate(Template); PushOnScopeChains(InjectedClassName, S); - assert(InjectedClassName->isInjectedClassName() && + assert(InjectedClassName->isInjectedClassName() && "Broken injected-class-name"); } } @@ -4425,7 +4425,7 @@ void Sema::ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagD, } // Note that FieldName may be null for anonymous bitfields. -bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, +bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, QualType FieldTy, const Expr *BitWidth, bool *ZeroWidth) { // Default to true; that shouldn't confuse checks for emptiness @@ -4460,10 +4460,10 @@ bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, // Zero-width bitfield is ok for anonymous field. if (Value == 0 && FieldName) return Diag(FieldLoc, diag::err_bitfield_has_zero_width) << FieldName; - + if (Value.isSigned() && Value.isNegative()) { if (FieldName) - return Diag(FieldLoc, diag::err_bitfield_has_negative_width) + return Diag(FieldLoc, diag::err_bitfield_has_negative_width) << FieldName << Value.toString(10); return Diag(FieldLoc, diag::err_anon_bitfield_has_negative_width) << Value.toString(10); @@ -4486,7 +4486,7 @@ bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, /// ActOnField - Each field of a struct/union/class is passed into this in order /// to create a FieldDecl object for it. Sema::DeclPtrTy Sema::ActOnField(Scope *S, DeclPtrTy TagD, - SourceLocation DeclStart, + SourceLocation DeclStart, Declarator &D, ExprTy *BitfieldWidth) { FieldDecl *Res = HandleField(S, cast_or_null<RecordDecl>(TagD.getAs<Decl>()), DeclStart, D, static_cast<Expr*>(BitfieldWidth), @@ -4503,7 +4503,7 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record, IdentifierInfo *II = D.getIdentifier(); SourceLocation Loc = DeclStart; if (II) Loc = D.getIdentifierLoc(); - + DeclaratorInfo *DInfo = 0; QualType T = GetTypeForDeclarator(D, S, &DInfo); if (getLangOptions().CPlusPlus) @@ -4552,11 +4552,11 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record, /// /// \returns a new FieldDecl. /// -/// \todo The Declarator argument is a hack. It will be removed once +/// \todo The Declarator argument is a hack. It will be removed once FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T, - DeclaratorInfo *DInfo, + DeclaratorInfo *DInfo, RecordDecl *Record, SourceLocation Loc, - bool Mutable, Expr *BitWidth, + bool Mutable, Expr *BitWidth, SourceLocation TSSL, AccessSpecifier AS, NamedDecl *PrevDecl, Declarator *D) { @@ -4588,12 +4588,12 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T, InvalidDecl = true; } } - + // Fields can not have abstract class types - if (RequireNonAbstractType(Loc, T, diag::err_abstract_type_in_decl, + if (RequireNonAbstractType(Loc, T, diag::err_abstract_type_in_decl, AbstractFieldType)) InvalidDecl = true; - + bool ZeroWidth = false; // If this is declared as a bit-field, check the bit-field. if (BitWidth && VerifyBitField(Loc, II, T, BitWidth, &ZeroWidth)) { @@ -4602,7 +4602,7 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T, BitWidth = 0; ZeroWidth = false; } - + FieldDecl *NewFD = FieldDecl::Create(Context, Record, Loc, II, T, DInfo, BitWidth, Mutable); if (InvalidDecl) @@ -4771,7 +4771,7 @@ void Sema::DiagnoseNontrivial(const RecordType* T, CXXSpecialMember member) { } } } - + bool (CXXRecordDecl::*hasTrivial)() const; switch (member) { case CXXDefaultConstructor: @@ -4798,7 +4798,7 @@ void Sema::DiagnoseNontrivial(const RecordType* T, CXXSpecialMember member) { return; } } - + // Check for nontrivial members (and recurse). typedef RecordDecl::field_iterator field_iter; for (field_iter fi = RD->field_begin(), fe = RD->field_end(); fi != fe; @@ -4819,7 +4819,7 @@ void Sema::DiagnoseNontrivial(const RecordType* T, CXXSpecialMember member) { assert(0 && "found no explanation for non-trivial member"); } -/// TranslateIvarVisibility - Translate visibility from a token ID to an +/// TranslateIvarVisibility - Translate visibility from a token ID to an /// AST enum value. static ObjCIvarDecl::AccessControl TranslateIvarVisibility(tok::ObjCKeywordKind ivarVisibility) { @@ -4832,25 +4832,25 @@ TranslateIvarVisibility(tok::ObjCKeywordKind ivarVisibility) { } } -/// ActOnIvar - Each ivar field of an objective-c class is passed into this +/// ActOnIvar - Each ivar field of an objective-c class is passed into this /// in order to create an IvarDecl object for it. Sema::DeclPtrTy Sema::ActOnIvar(Scope *S, - SourceLocation DeclStart, + SourceLocation DeclStart, DeclPtrTy IntfDecl, Declarator &D, ExprTy *BitfieldWidth, tok::ObjCKeywordKind Visibility) { - + IdentifierInfo *II = D.getIdentifier(); Expr *BitWidth = (Expr*)BitfieldWidth; SourceLocation Loc = DeclStart; if (II) Loc = D.getIdentifierLoc(); - + // FIXME: Unnamed fields can be handled in various different ways, for // example, unnamed unions inject all members into the struct namespace! - + DeclaratorInfo *DInfo = 0; QualType T = GetTypeForDeclarator(D, S, &DInfo); - + if (BitWidth) { // 6.7.2.1p3, 6.7.2.1p4 if (VerifyBitField(Loc, II, T, BitWidth)) { @@ -4860,26 +4860,26 @@ Sema::DeclPtrTy Sema::ActOnIvar(Scope *S, } } else { // Not a bitfield. - + // validate II. - + } - + // C99 6.7.2.1p8: A member of a structure or union may have any type other // than a variably modified type. if (T->isVariablyModifiedType()) { Diag(Loc, diag::err_typecheck_ivar_variable_size); D.setInvalidType(); } - + // Get the visibility (access control) for this ivar. - ObjCIvarDecl::AccessControl ac = + ObjCIvarDecl::AccessControl ac = Visibility != tok::objc_not_keyword ? TranslateIvarVisibility(Visibility) : ObjCIvarDecl::None; // Must set ivar's DeclContext to its enclosing interface. Decl *EnclosingDecl = IntfDecl.getAs<Decl>(); DeclContext *EnclosingContext; - if (ObjCImplementationDecl *IMPDecl = + if (ObjCImplementationDecl *IMPDecl = dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) { // Case of ivar declared in an implementation. Context is that of its class. ObjCInterfaceDecl* IDecl = IMPDecl->getClassInterface(); @@ -4888,12 +4888,12 @@ Sema::DeclPtrTy Sema::ActOnIvar(Scope *S, } else EnclosingContext = dyn_cast<DeclContext>(EnclosingDecl); assert(EnclosingContext && "null DeclContext for ivar - ActOnIvar"); - + // Construct the decl. - ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, + ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, EnclosingContext, Loc, II, T, DInfo, ac, (Expr *)BitfieldWidth); - + if (II) { NamedDecl *PrevDecl = LookupName(S, II, LookupMemberName, true); if (PrevDecl && isDeclInScope(PrevDecl, EnclosingContext, S) @@ -4906,7 +4906,7 @@ Sema::DeclPtrTy Sema::ActOnIvar(Scope *S, // Process attributes attached to the ivar. ProcessDeclAttributes(S, NewID, D); - + if (D.isInvalidType()) NewID->setInvalidDecl(); @@ -4927,7 +4927,7 @@ void Sema::ActOnFields(Scope* S, AttributeList *Attr) { Decl *EnclosingDecl = RecDecl.getAs<Decl>(); assert(EnclosingDecl && "missing record or interface decl"); - + // If the decl this is being inserted into is invalid, then it may be a // redeclaration or some other bogus case. Don't try to add fields to it. if (EnclosingDecl->isInvalidDecl()) { @@ -4935,7 +4935,7 @@ void Sema::ActOnFields(Scope* S, return; } - + // Verify that all the fields are okay. unsigned NumNamedMembers = 0; llvm::SmallVector<FieldDecl*, 32> RecFields; @@ -4943,7 +4943,7 @@ void Sema::ActOnFields(Scope* S, RecordDecl *Record = dyn_cast<RecordDecl>(EnclosingDecl); for (unsigned i = 0; i != NumFields; ++i) { FieldDecl *FD = cast<FieldDecl>(Fields[i].getAs<Decl>()); - + // Get the type for the field. Type *FDTy = FD->getType().getTypePtr(); @@ -4951,12 +4951,12 @@ void Sema::ActOnFields(Scope* S, // Remember all fields written by the user. RecFields.push_back(FD); } - + // If the field is already invalid for some reason, don't emit more // diagnostics about it. if (FD->isInvalidDecl()) continue; - + // C99 6.7.2.1p2: // A structure or union shall not contain a member with // incomplete or function type (hence, a structure shall not @@ -4988,7 +4988,7 @@ void Sema::ActOnFields(Scope* S, if (Record) Record->setHasFlexibleArrayMember(true); } else if (!FDTy->isDependentType() && - RequireCompleteType(FD->getLocation(), FD->getType(), + RequireCompleteType(FD->getLocation(), FD->getType(), diag::err_field_incomplete)) { // Incomplete type FD->setInvalidDecl(); @@ -5052,7 +5052,7 @@ void Sema::ActOnFields(Scope* S, // Must enforce the rule that ivars in the base classes may not be // duplicates. if (ID->getSuperClass()) { - for (ObjCInterfaceDecl::ivar_iterator IVI = ID->ivar_begin(), + for (ObjCInterfaceDecl::ivar_iterator IVI = ID->ivar_begin(), IVE = ID->ivar_end(); IVI != IVE; ++IVI) { ObjCIvarDecl* Ivar = (*IVI); @@ -5066,7 +5066,7 @@ void Sema::ActOnFields(Scope* S, } } } - } else if (ObjCImplementationDecl *IMPDecl = + } else if (ObjCImplementationDecl *IMPDecl = dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) { assert(IMPDecl && "ActOnFields - missing ObjCImplementationDecl"); for (unsigned I = 0, N = RecFields.size(); I != N; ++I) @@ -5107,7 +5107,7 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, EltTy = Val->getType(); } } - + if (!Val) { if (LastEnumConst) { // Assign the last value + 1. @@ -5117,7 +5117,7 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, // Check for overflow on increment. if (EnumVal < LastEnumConst->getInitVal()) Diag(IdLoc, diag::warn_enum_value_overflow); - + EltTy = LastEnumConst->getType(); } else { // First value, set to zero. @@ -5125,10 +5125,10 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, EnumVal.zextOrTrunc(static_cast<uint32_t>(Context.getTypeSize(EltTy))); } } - + val.release(); return EnumConstantDecl::Create(Context, Enum, IdLoc, Id, EltTy, - Val, EnumVal); + Val, EnumVal); } @@ -5145,7 +5145,7 @@ Sema::DeclPtrTy Sema::ActOnEnumConstant(Scope *S, DeclPtrTy theEnumDecl, // The scope passed in may not be a decl scope. Zip up the scope tree until // we find one that is. S = getNonFieldDeclScope(S); - + // Verify that there isn't already something declared with this name in this // scope. NamedDecl *PrevDecl = LookupName(S, Id, LookupOrdinaryName); @@ -5191,27 +5191,27 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, if (Attr) ProcessDeclAttributeList(S, Enum, Attr); - + // TODO: If the result value doesn't fit in an int, it must be a long or long // long value. ISO C does not support this, but GCC does as an extension, // emit a warning. unsigned IntWidth = Context.Target.getIntWidth(); unsigned CharWidth = Context.Target.getCharWidth(); unsigned ShortWidth = Context.Target.getShortWidth(); - + // Verify that all the values are okay, compute the size of the values, and // reverse the list. unsigned NumNegativeBits = 0; unsigned NumPositiveBits = 0; - + // Keep track of whether all elements have type int. bool AllElementsInt = true; - + for (unsigned i = 0; i != NumElements; ++i) { EnumConstantDecl *ECD = cast_or_null<EnumConstantDecl>(Elements[i].getAs<Decl>()); if (!ECD) continue; // Already issued a diagnostic. - + // If the enum value doesn't fit in an int, emit an extension warning. const llvm::APSInt &InitVal = ECD->getInitVal(); assert(InitVal.getBitWidth() >= IntWidth && @@ -5224,7 +5224,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, Diag(ECD->getLocation(), diag::ext_enum_value_not_int) << InitVal.toString(10); } - + // Keep track of the size of positive and negative values. if (InitVal.isUnsigned() || InitVal.isNonNegative()) NumPositiveBits = std::max(NumPositiveBits, @@ -5235,9 +5235,9 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, // Keep track of whether every enum element has type int (very commmon). if (AllElementsInt) - AllElementsInt = ECD->getType() == Context.IntTy; + AllElementsInt = ECD->getType() == Context.IntTy; } - + // Figure out the type that should be used for this enum. // FIXME: Support -fshort-enums. QualType BestType; @@ -5246,13 +5246,13 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, bool Packed = Enum->getAttr<PackedAttr>() ? true : false; if (NumNegativeBits) { - // If there is a negative value, figure out the smallest integer type (of + // If there is a negative value, figure out the smallest integer type (of // int/long/longlong) that fits. // If it's packed, check also if it fits a char or a short. if (Packed && NumNegativeBits <= CharWidth && NumPositiveBits < CharWidth) { BestType = Context.SignedCharTy; BestWidth = CharWidth; - } else if (Packed && NumNegativeBits <= ShortWidth && + } else if (Packed && NumNegativeBits <= ShortWidth && NumPositiveBits < ShortWidth) { BestType = Context.ShortTy; BestWidth = ShortWidth; @@ -5262,12 +5262,12 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, BestWidth = IntWidth; } else { BestWidth = Context.Target.getLongWidth(); - + if (NumNegativeBits <= BestWidth && NumPositiveBits < BestWidth) BestType = Context.LongTy; else { BestWidth = Context.Target.getLongLongWidth(); - + if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth) Diag(Enum->getLocation(), diag::warn_enum_too_large); BestType = Context.LongLongTy; @@ -5297,7 +5297,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, BestType = Context.UnsignedLongLongTy; } } - + // Loop over all of the enumerator constants, changing their types to match // the type of the enum if needed. for (unsigned i = 0; i != NumElements; ++i) { @@ -5319,7 +5319,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, if (getLangOptions().CPlusPlus) // C++ [dcl.enum]p4: Following the closing brace of an // enum-specifier, each enumerator has the type of its - // enumeration. + // enumeration. ECD->setType(EnumType); continue; // Already int type. } @@ -5346,7 +5346,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, if (getLangOptions().CPlusPlus) // C++ [dcl.enum]p4: Following the closing brace of an // enum-specifier, each enumerator has the type of its - // enumeration. + // enumeration. ECD->setType(EnumType); continue; } else { @@ -5359,22 +5359,22 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, InitVal.extOrTrunc(NewWidth); InitVal.setIsSigned(NewSign); ECD->setInitVal(InitVal); - + // Adjust the Expr initializer and type. if (ECD->getInitExpr()) - ECD->setInitExpr(new (Context) ImplicitCastExpr(NewTy, - CastExpr::CK_Unknown, - ECD->getInitExpr(), + ECD->setInitExpr(new (Context) ImplicitCastExpr(NewTy, + CastExpr::CK_Unknown, + ECD->getInitExpr(), /*isLvalue=*/false)); if (getLangOptions().CPlusPlus) // C++ [dcl.enum]p4: Following the closing brace of an // enum-specifier, each enumerator has the type of its - // enumeration. + // enumeration. ECD->setType(EnumType); else ECD->setType(NewTy); } - + Enum->completeDefinition(Context, BestType); } diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index df2fa16aba..5987c96c2f 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -437,9 +437,9 @@ static void HandleMallocAttr(Decl *d, const AttributeList &Attr, Sema &S) { S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; return; } - + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(d)) { - QualType RetTy = FD->getResultType(); + QualType RetTy = FD->getResultType(); if (RetTy->isAnyPointerType() || RetTy->isBlockPointerType()) { d->addAttr(::new (S.Context) MallocAttr()); return; @@ -989,7 +989,7 @@ static void HandleSectionAttr(Decl *D, const AttributeList &Attr, Sema &S) { S.Diag(ArgExpr->getLocStart(), diag::err_attribute_not_string) << "section"; return; } - + std::string SectionStr(SE->getStrData(), SE->getByteLength()); // If the target wants to validate the section specifier, make it happen. @@ -998,10 +998,10 @@ static void HandleSectionAttr(Decl *D, const AttributeList &Attr, Sema &S) { D->addAttr(::new (S.Context) SectionAttr(SectionStr)); return; } - + S.Diag(SE->getLocStart(), diag::err_attribute_section_invalid_for_target) << Error; - + } static void HandleStdCallAttr(Decl *d, const AttributeList &Attr, Sema &S) { @@ -1277,7 +1277,7 @@ static void HandleFormatAttr(Decl *d, const AttributeList &Attr, Sema &S) { NumArgs++; } } - + if (Idx.getZExtValue() < FirstIdx || Idx.getZExtValue() > NumArgs) { S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds) << "format" << 2 << IdxExpr->getSourceRange(); @@ -1288,7 +1288,7 @@ static void HandleFormatAttr(Decl *d, const AttributeList &Attr, Sema &S) { unsigned ArgIdx = Idx.getZExtValue() - 1; if (HasImplicitThisParam) ArgIdx--; - + // make sure the format string is really a string QualType Ty = getFunctionOrMethodArgType(d, ArgIdx); @@ -1867,8 +1867,7 @@ void Sema::ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *Attr /// DeclClonePragmaWeak - clone existing decl (maybe definition), /// #pragma weak needs a non-definition decl and source may not have one -NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II) -{ +NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II) { assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND)); NamedDecl *NewD = 0; if (FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) { 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) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 988680a981..5b52ba9c8c 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -28,7 +28,7 @@ bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property, if (property->getType()->isObjCObjectPointerType()) result = CheckAssignmentConstraints(GetterMethod->getResultType(), property->getType()); if (result != Compatible) { - Diag(Loc, diag::warn_accessor_property_type_mismatch) + Diag(Loc, diag::warn_accessor_property_type_mismatch) << property->getDeclName() << GetterMethod->getSelector(); Diag(GetterMethod->getLocation(), diag::note_declared_at); @@ -43,7 +43,7 @@ bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property, void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclPtrTy D) { assert(getCurMethodDecl() == 0 && "Method parsing confused"); ObjCMethodDecl *MDecl = dyn_cast_or_null<ObjCMethodDecl>(D.getAs<Decl>()); - + // If we don't have a valid method decl, simply return. if (!MDecl) return; @@ -55,7 +55,7 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclPtrTy D) { AddInstanceMethodToGlobalPool(MDecl); else AddFactoryMethodToGlobalPool(MDecl); - + // Allow all of Sema to see that we are entering a method definition. PushDeclContext(FnBodyScope, MDecl); @@ -64,7 +64,7 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclPtrTy D) { // Insert the invisible arguments, self and _cmd! MDecl->createImplicitParams(Context, MDecl->getClassInterface()); - + PushOnScopeChains(MDecl->getSelfDecl(), FnBodyScope); PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope); @@ -82,7 +82,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, const DeclPtrTy *ProtoRefs, unsigned NumProtoRefs, SourceLocation EndProtoLoc, AttributeList *AttrList) { assert(ClassName && "Missing class identifier"); - + // Check for another declaration kind with the same name. NamedDecl *PrevDecl = LookupName(TUScope, ClassName, LookupOrdinaryName); if (PrevDecl && PrevDecl->isTemplateParameter()) { @@ -96,7 +96,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName; Diag(PrevDecl->getLocation(), diag::note_previous_definition); } - + ObjCInterfaceDecl* IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); if (IDecl) { // Class already seen. Is it a forward declaration? @@ -113,14 +113,14 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, IDecl->setForwardDecl(false); } } else { - IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtInterfaceLoc, + IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtInterfaceLoc, ClassName, ClassLoc); if (AttrList) ProcessDeclAttributeList(TUScope, IDecl, AttrList); - + PushOnScopeChains(IDecl, TUScope); } - + if (SuperName) { // Check if a different kind of symbol declared in this scope. PrevDecl = LookupName(TUScope, SuperName, LookupOrdinaryName); @@ -129,13 +129,13 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc); IDecl->setLocEnd(ClassLoc); } else { - ObjCInterfaceDecl *SuperClassDecl = + ObjCInterfaceDecl *SuperClassDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); // Diagnose classes that inherit from deprecated classes. if (SuperClassDecl) (void)DiagnoseUseOfDecl(SuperClassDecl, SuperLoc); - + if (PrevDecl && SuperClassDecl == 0) { // The previous declaration was not a class decl. Check if we have a // typedef. If we do, get the underlying class type. @@ -146,7 +146,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, SuperClassDecl = dyn_cast<ObjCInterfaceDecl>(IDecl); } } - + // This handles the following case: // // typedef int SuperClass; @@ -157,7 +157,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, Diag(PrevDecl->getLocation(), diag::note_previous_definition); } } - + if (!dyn_cast_or_null<TypedefDecl>(PrevDecl)) { if (!SuperClassDecl) Diag(SuperLoc, diag::err_undef_superclass) @@ -174,14 +174,14 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, } else { // we have a root class. IDecl->setLocEnd(ClassLoc); } - + /// Check then save referenced protocols. if (NumProtoRefs) { IDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs, Context); IDecl->setLocEnd(EndProtoLoc); } - + CheckObjCDeclScope(IDecl); return DeclPtrTy::make(IDecl); } @@ -189,7 +189,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, /// ActOnCompatiblityAlias - this action is called after complete parsing of /// @compatibility_alias declaration. It sets up the alias relationships. Sema::DeclPtrTy Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, - IdentifierInfo *AliasName, + IdentifierInfo *AliasName, SourceLocation AliasLocation, IdentifierInfo *ClassName, SourceLocation ClassLocation) { @@ -221,11 +221,11 @@ Sema::DeclPtrTy Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, Diag(CDeclU->getLocation(), diag::note_previous_declaration); return DeclPtrTy(); } - + // Everything checked out, instantiate a new alias declaration AST. - ObjCCompatibleAliasDecl *AliasDecl = + ObjCCompatibleAliasDecl *AliasDecl = ObjCCompatibleAliasDecl::Create(Context, CurContext, AtLoc, AliasName, CDecl); - + if (!CheckObjCDeclScope(AliasDecl)) PushOnScopeChains(AliasDecl, TUScope); @@ -235,17 +235,16 @@ Sema::DeclPtrTy Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, void Sema::CheckForwardProtocolDeclarationForCircularDependency( IdentifierInfo *PName, SourceLocation &Ploc, SourceLocation PrevLoc, - const ObjCList<ObjCProtocolDecl> &PList) -{ + const ObjCList<ObjCProtocolDecl> &PList) { for (ObjCList<ObjCProtocolDecl>::iterator I = PList.begin(), E = PList.end(); I != E; ++I) { - + if (ObjCProtocolDecl *PDecl = LookupProtocol((*I)->getIdentifier())) { if (PDecl->getIdentifier() == PName) { Diag(Ploc, diag::err_protocol_has_circular_dependency); Diag(PrevLoc, diag::note_previous_definition); } - CheckForwardProtocolDeclarationForCircularDependency(PName, Ploc, + CheckForwardProtocolDeclarationForCircularDependency(PName, Ploc, PDecl->getLocation(), PDecl->getReferencedProtocols()); } } @@ -272,16 +271,16 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc, return DeclPtrTy::make(PDecl); } ObjCList<ObjCProtocolDecl> PList; - PList.set((ObjCProtocolDecl *const*)ProtoRefs, NumProtoRefs, Context); + PList.set((ObjCProtocolDecl *const*)ProtoRefs, NumProtoRefs, Context); CheckForwardProtocolDeclarationForCircularDependency( ProtocolName, ProtocolLoc, PDecl->getLocation(), PList); PList.Destroy(Context); - + // Make sure the cached decl gets a valid start location. PDecl->setLocation(AtProtoInterfaceLoc); PDecl->setForwardDecl(false); } else { - PDecl = ObjCProtocolDecl::Create(Context, CurContext, + PDecl = ObjCProtocolDecl::Create(Context, CurContext, AtProtoInterfaceLoc,ProtocolName); PushOnScopeChains(PDecl, TUScope); PDecl->setForwardDecl(false); @@ -293,8 +292,8 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc, PDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs,Context); PDecl->setLocEnd(EndProtoLoc); } - - CheckObjCDeclScope(PDecl); + + CheckObjCDeclScope(PDecl); return DeclPtrTy::make(PDecl); } @@ -313,7 +312,7 @@ Sema::FindProtocolDeclaration(bool WarnOnDeclarations, << ProtocolId[i].first; continue; } - + (void)DiagnoseUseOfDecl(PDecl, ProtocolId[i].second); // If this is a forward declaration and we are supposed to warn in this @@ -329,12 +328,12 @@ Sema::FindProtocolDeclaration(bool WarnOnDeclarations, /// attributes and types and warns on a variety of inconsistencies. /// void -Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property, +Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property, ObjCPropertyDecl *SuperProperty, const IdentifierInfo *inheritedName) { - ObjCPropertyDecl::PropertyAttributeKind CAttr = + ObjCPropertyDecl::PropertyAttributeKind CAttr = Property->getPropertyAttributes(); - ObjCPropertyDecl::PropertyAttributeKind SAttr = + ObjCPropertyDecl::PropertyAttributeKind SAttr = SuperProperty->getPropertyAttributes(); if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly) && (SAttr & ObjCPropertyDecl::OBJC_PR_readwrite)) @@ -348,23 +347,23 @@ Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property, != (SAttr & ObjCPropertyDecl::OBJC_PR_retain)) Diag(Property->getLocation(), diag::warn_property_attribute) << Property->getDeclName() << "retain" << inheritedName; - + if ((CAttr & ObjCPropertyDecl::OBJC_PR_nonatomic) != (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)) Diag(Property->getLocation(), diag::warn_property_attribute) << Property->getDeclName() << "atomic" << inheritedName; if (Property->getSetterName() != SuperProperty->getSetterName()) Diag(Property->getLocation(), diag::warn_property_attribute) - << Property->getDeclName() << "setter" << inheritedName; + << Property->getDeclName() << "setter" << inheritedName; if (Property->getGetterName() != SuperProperty->getGetterName()) Diag(Property->getLocation(), diag::warn_property_attribute) << Property->getDeclName() << "getter" << inheritedName; - QualType LHSType = + QualType LHSType = Context.getCanonicalType(SuperProperty->getType()); - QualType RHSType = + QualType RHSType = Context.getCanonicalType(Property->getType()); - + if (!Context.typesAreCompatible(LHSType, RHSType)) { // FIXME: Incorporate this test with typesAreCompatible. if (LHSType->isObjCQualifiedIdType() && RHSType->isObjCQualifiedIdType()) @@ -392,7 +391,7 @@ void Sema::ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl) { E = IDecl->prop_end(); I != E; ++I) { ObjCPropertyDecl *PDecl = (*I); if (SuperPDecl->getIdentifier() == PDecl->getIdentifier()) - DiagnosePropertyMismatch(PDecl, SuperPDecl, + DiagnosePropertyMismatch(PDecl, SuperPDecl, SDecl->getIdentifier()); } } @@ -455,7 +454,7 @@ void Sema::MergeProtocolPropertiesIntoClass(Decl *CDecl, E = MDecl->protocol_end(); P != E; ++P) // Merge properties of category (*P) into IDECL's MergeOneProtocolPropertiesIntoClass(CatDecl, *P); - + // Go thru the list of protocols for this category and recursively merge // their properties into this class as well. for (ObjCCategoryDecl::protocol_iterator P = CatDecl->protocol_begin(), @@ -475,7 +474,7 @@ void Sema::MergeProtocolPropertiesIntoClass(Decl *CDecl, E = MDecl->protocol_end(); P != E; ++P) // Merge properties of class (*P) into IDECL's MergeOneProtocolPropertiesIntoClass(IDecl, *P); - + // Go thru the list of protocols for this class and recursively merge // their properties into this class as well. for (ObjCInterfaceDecl::protocol_iterator P = IDecl->protocol_begin(), @@ -492,7 +491,7 @@ void Sema::MergeProtocolPropertiesIntoClass(Decl *CDecl, /// DiagnoseClassExtensionDupMethods - Check for duplicate declaration of /// a class method in its extension. /// -void Sema::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, +void Sema::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, ObjCInterfaceDecl *ID) { if (!ID) return; // Possibly due to previous error @@ -525,12 +524,12 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, unsigned NumElts, AttributeList *attrList) { llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols; - + for (unsigned i = 0; i != NumElts; ++i) { IdentifierInfo *Ident = IdentList[i].first; ObjCProtocolDecl *PDecl = LookupProtocol(Ident); if (PDecl == 0) { // Not already seen? - PDecl = ObjCProtocolDecl::Create(Context, CurContext, + PDecl = ObjCProtocolDecl::Create(Context, CurContext, IdentList[i].second, Ident); PushOnScopeChains(PDecl, TUScope); } @@ -538,8 +537,8 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, ProcessDeclAttributeList(TUScope, PDecl, attrList); Protocols.push_back(PDecl); } - - ObjCForwardProtocolDecl *PDecl = + + ObjCForwardProtocolDecl *PDecl = ObjCForwardProtocolDecl::Create(Context, CurContext, AtProtocolLoc, &Protocols[0], Protocols.size()); CurContext->addDecl(PDecl); @@ -555,7 +554,7 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, const DeclPtrTy *ProtoRefs, unsigned NumProtoRefs, SourceLocation EndProtoLoc) { - ObjCCategoryDecl *CDecl = + ObjCCategoryDecl *CDecl = ObjCCategoryDecl::Create(Context, CurContext, AtInterfaceLoc, CategoryName); // FIXME: PushOnScopeChains? CurContext->addDecl(CDecl); @@ -569,7 +568,7 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, } CDecl->setClassInterface(IDecl); - + // If the interface is deprecated, warn about it. (void)DiagnoseUseOfDecl(IDecl, ClassLoc); @@ -591,7 +590,7 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, CDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs,Context); CDecl->setLocEnd(EndProtoLoc); } - + CheckObjCDeclScope(CDecl); return DeclPtrTy::make(CDecl); } @@ -617,7 +616,7 @@ Sema::DeclPtrTy Sema::ActOnStartCategoryImplementation( } } - ObjCCategoryImplDecl *CDecl = + ObjCCategoryImplDecl *CDecl = ObjCCategoryImplDecl::Create(Context, CurContext, AtCatImplLoc, CatName, IDecl); /// Check that class of this category is already completely declared. @@ -637,7 +636,7 @@ Sema::DeclPtrTy Sema::ActOnStartCategoryImplementation( } else CatIDecl->setImplementation(CDecl); } - + CheckObjCDeclScope(CDecl); return DeclPtrTy::make(CDecl); } @@ -645,7 +644,7 @@ Sema::DeclPtrTy Sema::ActOnStartCategoryImplementation( Sema::DeclPtrTy Sema::ActOnStartClassImplementation( SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, - IdentifierInfo *SuperClassname, + IdentifierInfo *SuperClassname, SourceLocation SuperClassLoc) { ObjCInterfaceDecl* IDecl = 0; // Check for another declaration kind with the same name. @@ -655,13 +654,13 @@ Sema::DeclPtrTy Sema::ActOnStartClassImplementation( Diag(PrevDecl->getLocation(), diag::note_previous_definition); } else { // Is there an interface declaration of this class; if not, warn! - IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); + IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); if (!IDecl || IDecl->isForwardDecl()) { Diag(ClassLoc, diag::warn_undef_interface) << ClassName; IDecl = 0; } } - + // Check that super class name is valid class name ObjCInterfaceDecl* SDecl = 0; if (SuperClassname) { @@ -672,7 +671,7 @@ Sema::DeclPtrTy Sema::ActOnStartClassImplementation( << SuperClassname; Diag(PrevDecl->getLocation(), diag::note_previous_definition); } else { - SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); + SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); if (!SDecl) Diag(SuperClassLoc, diag::err_undef_superclass) << SuperClassname << ClassName; @@ -685,14 +684,14 @@ Sema::DeclPtrTy Sema::ActOnStartClassImplementation( } } } - + if (!IDecl) { // Legacy case of @implementation with no corresponding @interface. // Build, chain & install the interface decl into the identifier. // FIXME: Do we support attributes on the @implementation? If so we should // copy them over. - IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassImplLoc, + IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassImplLoc, ClassName, ClassLoc, false, true); IDecl->setSuperClass(SDecl); IDecl->setLocEnd(ClassLoc); @@ -704,14 +703,14 @@ Sema::DeclPtrTy Sema::ActOnStartClassImplementation( // declaration; the user cannot reopen it. IDecl->setForwardDecl(false); } - - ObjCImplementationDecl* IMPDecl = - ObjCImplementationDecl::Create(Context, CurContext, AtClassImplLoc, + + ObjCImplementationDecl* IMPDecl = + ObjCImplementationDecl::Create(Context, CurContext, AtClassImplLoc, IDecl, SDecl); - + if (CheckObjCDeclScope(IMPDecl)) return DeclPtrTy::make(IMPDecl); - + // Check that there is no duplicate implementation of this class. if (IDecl->getImplementation()) { // FIXME: Don't leak everything! @@ -743,21 +742,21 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, // If implementation has empty ivar list, just return. if (numIvars == 0) return; - + assert(ivars && "missing @implementation ivars"); - + // Check interface's Ivar list against those in the implementation. // names and types must match. // unsigned j = 0; - ObjCInterfaceDecl::ivar_iterator + ObjCInterfaceDecl::ivar_iterator IVI = IDecl->ivar_begin(), IVE = IDecl->ivar_end(); for (; numIvars > 0 && IVI != IVE; ++IVI) { ObjCIvarDecl* ImplIvar = ivars[j++]; ObjCIvarDecl* ClsIvar = *IVI; assert (ImplIvar && "missing implementation ivar"); assert (ClsIvar && "missing class ivar"); - + // First, make sure the types match. if (Context.getCanonicalType(ImplIvar->getType()) != Context.getCanonicalType(ClsIvar->getType())) { @@ -774,7 +773,7 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, << ImplIvar->getIdentifier(); Diag(ClsBitWidth->getLocStart(), diag::note_previous_definition); } - } + } // Make sure the names are identical. if (ImplIvar->getIdentifier() != ClsIvar->getIdentifier()) { Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_name) @@ -783,7 +782,7 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, } --numIvars; } - + if (numIvars > 0) Diag(ivars[j]->getLocation(), diag::err_inconsistant_ivar_count); else if (IVI != IVE) @@ -805,21 +804,21 @@ void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl, ImpMethodDecl->getResultType()) && !Context.QualifiedIdConformsQualifiedId(IntfMethodDecl->getResultType(), ImpMethodDecl->getResultType())) { - Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_ret_types) + Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_ret_types) << ImpMethodDecl->getDeclName() << IntfMethodDecl->getResultType() << ImpMethodDecl->getResultType(); Diag(IntfMethodDecl->getLocation(), diag::note_previous_definition); } - + for (ObjCMethodDecl::param_iterator IM = ImpMethodDecl->param_begin(), IF = IntfMethodDecl->param_begin(), EM = ImpMethodDecl->param_end(); IM != EM; ++IM, ++IF) { if (Context.typesAreCompatible((*IF)->getType(), (*IM)->getType()) || - Context.QualifiedIdConformsQualifiedId((*IF)->getType(), + Context.QualifiedIdConformsQualifiedId((*IF)->getType(), (*IM)->getType())) continue; - - Diag((*IM)->getLocation(), diag::warn_conflicting_param_types) + + Diag((*IM)->getLocation(), diag::warn_conflicting_param_types) << ImpMethodDecl->getDeclName() << (*IF)->getType() << (*IM)->getType(); Diag((*IF)->getLocation(), diag::note_previous_definition); @@ -834,34 +833,34 @@ bool Sema::isPropertyReadonly(ObjCPropertyDecl *PDecl, // by far the most common case. if (!PDecl->isReadOnly()) return false; - // Even if property is ready only, if interface has a user defined setter, + // Even if property is ready only, if interface has a user defined setter, // it is not considered read only. if (IDecl->getInstanceMethod(PDecl->getSetterName())) return false; - + // Main class has the property as 'readonly'. Must search - // through the category list to see if the property's + // through the category list to see if the property's // attribute has been over-ridden to 'readwrite'. for (ObjCCategoryDecl *Category = IDecl->getCategoryList(); Category; Category = Category->getNextClassCategory()) { - // Even if property is ready only, if a category has a user defined setter, - // it is not considered read only. + // Even if property is ready only, if a category has a user defined setter, + // it is not considered read only. if (Category->getInstanceMethod(PDecl->getSetterName())) return false; - ObjCPropertyDecl *P = + ObjCPropertyDecl *P = Category->FindPropertyDeclaration(PDecl->getIdentifier()); if (P && !P->isReadOnly()) return false; } - + // Also, check for definition of a setter method in the implementation if // all else failed. if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(CurContext)) { - if (ObjCImplementationDecl *IMD = + if (ObjCImplementationDecl *IMD = dyn_cast<ObjCImplementationDecl>(OMD->getDeclContext())) { if (IMD->getInstanceMethod(PDecl->getSetterName())) return false; - } else if (ObjCCategoryImplDecl *CIMD = + } else if (ObjCCategoryImplDecl *CIMD = dyn_cast<ObjCCategoryImplDecl>(OMD->getDeclContext())) { if (CIMD->getInstanceMethod(PDecl->getSetterName())) return false; @@ -894,11 +893,11 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc, ObjCInterfaceDecl *Super = IDecl->getSuperClass(); ObjCInterfaceDecl *NSIDecl = 0; if (getLangOptions().NeXTRuntime) { - // check to see if class implements forwardInvocation method and objects - // of this class are derived from 'NSProxy' so that to forward requests + // check to see if class implements forwardInvocation method and objects + // of this class are derived from 'NSProxy' so that to forward requests // from one object to another. - // Under such conditions, which means that every method possible is - // implemented in the class, we should not issue "Method definition not + // Under such conditions, which means that every method possible is + // implemented in the class, we should not issue "Method definition not // found" warnings. // FIXME: Use a general GetUnarySelector method for this. IdentifierInfo* II = &Context.Idents.get("forwardInvocation"); @@ -908,7 +907,7 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc, // need be implemented in the implementation. NSIDecl = IDecl->lookupInheritedClass(&Context.Idents.get("NSProxy")); } - + // If a method lookup fails locally we still need to look and see if // the method was implemented by a base class or an inherited // protocol. This lookup is slow, but occurs rarely in correct code @@ -916,24 +915,24 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc, // check unimplemented instance methods. if (!NSIDecl) - for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(), + for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(), E = PDecl->instmeth_end(); I != E; ++I) { ObjCMethodDecl *method = *I; - if (method->getImplementationControl() != ObjCMethodDecl::Optional && + if (method->getImplementationControl() != ObjCMethodDecl::Optional && !method->isSynthesized() && !InsMap.count(method->getSelector()) && - (!Super || + (!Super || !Super->lookupInstanceMethod(method->getSelector()))) { // Ugly, but necessary. Method declared in protcol might have // have been synthesized due to a property declared in the class which // uses the protocol. - ObjCMethodDecl *MethodInClass = + ObjCMethodDecl *MethodInClass = IDecl->lookupInstanceMethod(method->getSelector()); if (!MethodInClass || !MethodInClass->isSynthesized()) WarnUndefinedMethod(ImpLoc, method, IncompleteImpl); } } // check unimplemented class methods - for (ObjCProtocolDecl::classmeth_iterator + for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(), E = PDecl->classmeth_end(); I != E; ++I) { ObjCMethodDecl *method = *I; @@ -958,8 +957,7 @@ void Sema::MatchAllMethodDeclarations(const llvm::DenseSet<Selector> &InsMap, ObjCImplDecl* IMPDecl, ObjCContainerDecl* CDecl, bool &IncompleteImpl, - bool ImmediateClass) -{ + bool ImmediateClass) { // Check and see if instance methods in class interface have been // implemented in the implementation class. If so, their types match. for (ObjCInterfaceDecl::instmeth_iterator I = CDecl->instmeth_begin(), @@ -967,27 +965,27 @@ void Sema::MatchAllMethodDeclarations(const llvm::DenseSet<Selector> &InsMap, if (InsMapSeen.count((*I)->getSelector())) continue; InsMapSeen.insert((*I)->getSelector()); - if (!(*I)->isSynthesized() && + if (!(*I)->isSynthesized() && !InsMap.count((*I)->getSelector())) { if (ImmediateClass) WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl); continue; } else { - ObjCMethodDecl *ImpMethodDecl = + ObjCMethodDecl *ImpMethodDecl = IMPDecl->getInstanceMethod((*I)->getSelector()); - ObjCMethodDecl *IntfMethodDecl = + ObjCMethodDecl *IntfMethodDecl = CDecl->getInstanceMethod((*I)->getSelector()); - assert(IntfMethodDecl && + assert(IntfMethodDecl && "IntfMethodDecl is null in ImplMethodsVsClassMethods"); // ImpMethodDecl may be null as in a @dynamic property. if (ImpMethodDecl) WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl); } } - + // Check and see if class methods in class interface have been // implemented in the implementation class. If so, their types match. - for (ObjCInterfaceDecl::classmeth_iterator + for (ObjCInterfaceDecl::classmeth_iterator I = CDecl->classmeth_begin(), E = CDecl->classmeth_end(); I != E; ++I) { if (ClsMapSeen.count((*I)->getSelector())) continue; @@ -998,7 +996,7 @@ void Sema::MatchAllMethodDeclarations(const llvm::DenseSet<Selector> &InsMap, } else { ObjCMethodDecl *ImpMethodDecl = IMPDecl->getClassMethod((*I)->getSelector()); - ObjCMethodDecl *IntfMethodDecl = + ObjCMethodDecl *IntfMethodDecl = CDecl->getClassMethod((*I)->getSelector()); WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl); } @@ -1007,26 +1005,26 @@ void Sema::MatchAllMethodDeclarations(const llvm::DenseSet<Selector> &InsMap, // Check for any implementation of a methods declared in protocol. for (ObjCInterfaceDecl::protocol_iterator PI = I->protocol_begin(), E = I->protocol_end(); PI != E; ++PI) - MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen, - IMPDecl, + MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen, + IMPDecl, (*PI), IncompleteImpl, false); if (I->getSuperClass()) MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen, - IMPDecl, + IMPDecl, I->getSuperClass(), IncompleteImpl, false); } } -void Sema::ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, - ObjCContainerDecl* CDecl, +void Sema::ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, + ObjCContainerDecl* CDecl, bool IncompleteImpl) { llvm::DenseSet<Selector> InsMap; // Check and see if instance methods in class interface have been // implemented in the implementation class. - for (ObjCImplementationDecl::instmeth_iterator + for (ObjCImplementationDecl::instmeth_iterator I = IMPDecl->instmeth_begin(), E = IMPDecl->instmeth_end(); I!=E; ++I) InsMap.insert((*I)->getSelector()); - + // Check and see if properties declared in the interface have either 1) // an implementation or 2) there is a @synthesize/@dynamic implementation // of the property in the @implementation. @@ -1038,7 +1036,7 @@ void Sema::ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, continue; ObjCPropertyImplDecl *PI = 0; // Is there a matching propery synthesize/dynamic? - for (ObjCImplDecl::propimpl_iterator + for (ObjCImplDecl::propimpl_iterator I = IMPDecl->propimpl_begin(), EI = IMPDecl->propimpl_end(); I != EI; ++I) if ((*I)->getPropertyDecl() == Prop) { @@ -1048,44 +1046,44 @@ void Sema::ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, if (PI) continue; if (!InsMap.count(Prop->getGetterName())) { - Diag(Prop->getLocation(), - diag::warn_setter_getter_impl_required) + Diag(Prop->getLocation(), + diag::warn_setter_getter_impl_required) << Prop->getDeclName() << Prop->getGetterName(); Diag(IMPDecl->getLocation(), diag::note_property_impl_required); } - + if (!Prop->isReadOnly() && !InsMap.count(Prop->getSetterName())) { - Diag(Prop->getLocation(), - diag::warn_setter_getter_impl_required) + Diag(Prop->getLocation(), + diag::warn_setter_getter_impl_required) << Prop->getDeclName() << Prop->getSetterName(); Diag(IMPDecl->getLocation(), diag::note_property_impl_required); } } - + llvm::DenseSet<Selector> ClsMap; - for (ObjCImplementationDecl::classmeth_iterator + for (ObjCImplementationDecl::classmeth_iterator I = IMPDecl->classmeth_begin(), E = IMPDecl->classmeth_end(); I != E; ++I) ClsMap.insert((*I)->getSelector()); - + // Check for type conflict of methods declared in a class/protocol and // its implementation; if any. llvm::DenseSet<Selector> InsMapSeen, ClsMapSeen; - MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen, - IMPDecl, CDecl, + MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen, + IMPDecl, CDecl, IncompleteImpl, true); - + // Check the protocol list for unimplemented methods in the @implementation // class. // Check and see if class methods in class interface have been // implemented in the implementation class. - + if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl> (CDecl)) { for (ObjCInterfaceDecl::protocol_iterator PI = I->protocol_begin(), E = I->protocol_end(); PI != E; ++PI) - CheckProtocolMethodDefs(IMPDecl->getLocation(), *PI, IncompleteImpl, + CheckProtocolMethodDefs(IMPDecl->getLocation(), *PI, IncompleteImpl, InsMap, ClsMap, I); // Check class extensions (unnamed categories) for (ObjCCategoryDecl *Categories = I->getCategoryList(); @@ -1098,19 +1096,19 @@ void Sema::ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, } else if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl)) { for (ObjCCategoryDecl::protocol_iterator PI = C->protocol_begin(), E = C->protocol_end(); PI != E; ++PI) - CheckProtocolMethodDefs(IMPDecl->getLocation(), *PI, IncompleteImpl, + CheckProtocolMethodDefs(IMPDecl->getLocation(), *PI, IncompleteImpl, InsMap, ClsMap, C->getClassInterface()); } else assert(false && "invalid ObjCContainerDecl type."); } -/// ActOnForwardClassDeclaration - +/// ActOnForwardClassDeclaration - Action::DeclPtrTy Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, IdentifierInfo **IdentList, unsigned NumElts) { llvm::SmallVector<ObjCInterfaceDecl*, 32> Interfaces; - + for (unsigned i = 0; i != NumElts; ++i) { // Check for another declaration kind with the same name. NamedDecl *PrevDecl = LookupName(TUScope, IdentList[i], LookupOrdinaryName); @@ -1127,7 +1125,7 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, // typedef NSObject < XCElementTogglerP > XCElementToggler; // @class XCElementToggler; // - // FIXME: Make an extension? + // FIXME: Make an extension? TypedefDecl *TDD = dyn_cast<TypedefDecl>(PrevDecl); if (!TDD || !isa<ObjCInterfaceType>(TDD->getUnderlyingType())) { Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i]; @@ -1135,21 +1133,21 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, } else if (TDD) { // a forward class declaration matching a typedef name of a class refers // to the underlying class. - if (ObjCInterfaceType * OI = + if (ObjCInterfaceType * OI = dyn_cast<ObjCInterfaceType>(TDD->getUnderlyingType())) PrevDecl = OI->getDecl(); } } - ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); + ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); if (!IDecl) { // Not already seen? Make a forward decl. - IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassLoc, + IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassLoc, IdentList[i], SourceLocation(), true); PushOnScopeChains(IDecl, TUScope); } Interfaces.push_back(IDecl); } - + ObjCClassDecl *CDecl = ObjCClassDecl::Create(Context, CurContext, AtClassLoc, &Interfaces[0], Interfaces.size()); @@ -1162,12 +1160,12 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, /// MatchTwoMethodDeclarations - Checks that two methods have matching type and /// returns true, or false, accordingly. /// TODO: Handle protocol list; such as id<p1,p2> in type comparisons -bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, +bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, const ObjCMethodDecl *PrevMethod, bool matchBasedOnSizeAndAlignment) { QualType T1 = Context.getCanonicalType(Method->getResultType()); QualType T2 = Context.getCanonicalType(PrevMethod->getResultType()); - + if (T1 != T2) { // The result types are different. if (!matchBasedOnSizeAndAlignment) @@ -1179,11 +1177,11 @@ bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2)) return false; } - + ObjCMethodDecl::param_iterator ParamI = Method->param_begin(), E = Method->param_end(); ObjCMethodDecl::param_iterator PrevI = PrevMethod->param_begin(); - + for (; ParamI != E; ++ParamI, ++PrevI) { assert(PrevI != PrevMethod->param_end() && "Param mismatch"); T1 = Context.getCanonicalType((*ParamI)->getType()); @@ -1208,7 +1206,7 @@ bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, /// /// This routine should only be called once, when neither the instance /// nor the factory method pool has an entry for this selector. -Sema::MethodPool::iterator Sema::ReadMethodPool(Selector Sel, +Sema::MethodPool::iterator Sema::ReadMethodPool(Selector Sel, bool isInstance) { assert(ExternalSource && "We need an external AST source"); assert(InstanceMethodPool.find(Sel) == InstanceMethodPool.end() && @@ -1219,12 +1217,12 @@ Sema::MethodPool::iterator Sema::ReadMethodPool(Selector Sel, // Read the method list from the external source. std::pair<ObjCMethodList, ObjCMethodList> Methods = ExternalSource->ReadMethodPool(Sel); - + if (isInstance) { if (Methods.second.Method) FactoryMethodPool[Sel] = Methods.second; return InstanceMethodPool.insert(std::make_pair(Sel, Methods.first)).first; - } + } if (Methods.first.Method) InstanceMethodPool[Sel] = Methods.first; @@ -1250,20 +1248,20 @@ void Sema::AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method) { Entry.Next = 0; return; } - + // We've seen a method with this name, see if we have already seen this type // signature. for (ObjCMethodList *List = &Entry; List; List = List->Next) if (MatchTwoMethodDeclarations(Method, List->Method)) return; - + // We have a new signature for an existing method - add it. // This is extremely rare. Only 1% of Cocoa selectors are "overloaded". Entry.Next = new ObjCMethodList(Method, Entry.Next); } // FIXME: Finish implementing -Wno-strict-selector-match. -ObjCMethodDecl *Sema::LookupInstanceMethodInGlobalPool(Selector Sel, +ObjCMethodDecl *Sema::LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, bool warn) { llvm::DenseMap<Selector, ObjCMethodList>::iterator Pos @@ -1277,7 +1275,7 @@ ObjCMethodDecl *Sema::LookupInstanceMethodInGlobalPool(Selector Sel, ObjCMethodList &MethList = Pos->second; bool issueWarning = false; - + if (MethList.Method && MethList.Next) { for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) // This checks if the methods differ by size & alignment. @@ -1314,11 +1312,11 @@ void Sema::AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method) { } else { // We've seen a method with this name, now check the type signature(s). bool match = MatchTwoMethodDeclarations(Method, FirstMethod.Method); - - for (ObjCMethodList *Next = FirstMethod.Next; !match && Next; + + for (ObjCMethodList *Next = FirstMethod.Next; !match && Next; Next = Next->Next) match = MatchTwoMethodDeclarations(Method, Next->Method); - + if (!match) { // We have a new signature for an existing method - add it. // This is extremely rare. Only 1% of Cocoa selectors are "overloaded". @@ -1328,12 +1326,12 @@ void Sema::AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method) { } } -ObjCMethodDecl *Sema::LookupFactoryMethodInGlobalPool(Selector Sel, +ObjCMethodDecl *Sema::LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R) { llvm::DenseMap<Selector, ObjCMethodList>::iterator Pos = FactoryMethodPool.find(Sel); if (Pos == FactoryMethodPool.end()) { - if (ExternalSource && !InstanceMethodPool.count(Sel)) + if (ExternalSource && !InstanceMethodPool.count(Sel)) Pos = ReadMethodPool(Sel, /*isInstance=*/false); else return 0; @@ -1341,7 +1339,7 @@ ObjCMethodDecl *Sema::LookupFactoryMethodInGlobalPool(Selector Sel, ObjCMethodList &MethList = Pos->second; bool issueWarning = false; - + if (MethList.Method && MethList.Next) { for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) // This checks if the methods differ by size & alignment. @@ -1359,28 +1357,28 @@ ObjCMethodDecl *Sema::LookupFactoryMethodInGlobalPool(Selector Sel, return MethList.Method; } -/// ProcessPropertyDecl - Make sure that any user-defined setter/getter methods +/// ProcessPropertyDecl - Make sure that any user-defined setter/getter methods /// have the property type and issue diagnostics if they don't. /// Also synthesize a getter/setter method if none exist (and update the /// appropriate lookup tables. FIXME: Should reconsider if adding synthesized /// methods is the "right" thing to do. -void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, +void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *CD) { ObjCMethodDecl *GetterMethod, *SetterMethod; - - GetterMethod = CD->getInstanceMethod(property->getGetterName()); + + GetterMethod = CD->getInstanceMethod(property->getGetterName()); SetterMethod = CD->getInstanceMethod(property->getSetterName()); - DiagnosePropertyAccessorMismatch(property, GetterMethod, + DiagnosePropertyAccessorMismatch(property, GetterMethod, property->getLocation()); - + if (SetterMethod) { - if (Context.getCanonicalType(SetterMethod->getResultType()) + if (Context.getCanonicalType(SetterMethod->getResultType()) != Context.VoidTy) Diag(SetterMethod->getLocation(), diag::err_setter_type_void); if (SetterMethod->param_size() != 1 || ((*SetterMethod->param_begin())->getType() != property->getType())) { - Diag(property->getLocation(), - diag::warn_accessor_property_type_mismatch) + Diag(property->getLocation(), + diag::warn_accessor_property_type_mismatch) << property->getDeclName() << SetterMethod->getSelector(); Diag(SetterMethod->getLocation(), diag::note_declared_at); @@ -1395,14 +1393,14 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, // declarations jive in that situation (which it is not currently). if (!GetterMethod) { // No instance method of same name as property getter name was found. - // Declare a getter method and add it to the list of methods + // Declare a getter method and add it to the list of methods // for this class. - GetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(), - property->getLocation(), property->getGetterName(), - property->getType(), CD, true, false, true, - (property->getPropertyImplementation() == - ObjCPropertyDecl::Optional) ? - ObjCMethodDecl::Optional : + GetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(), + property->getLocation(), property->getGetterName(), + property->getType(), CD, true, false, true, + (property->getPropertyImplementation() == + ObjCPropertyDecl::Optional) ? + ObjCMethodDecl::Optional : ObjCMethodDecl::Required); CD->addDecl(GetterMethod); } else @@ -1416,20 +1414,20 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, // Find the default setter and if one not found, add one. if (!SetterMethod) { // No instance method of same name as property setter name was found. - // Declare a setter method and add it to the list of methods + // Declare a setter method and add it to the list of methods // for this class. - SetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(), - property->getLocation(), - property->getSetterName(), + SetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(), + property->getLocation(), + property->getSetterName(), Context.VoidTy, CD, true, false, true, - (property->getPropertyImplementation() == - ObjCPropertyDecl::Optional) ? - ObjCMethodDecl::Optional : + (property->getPropertyImplementation() == + ObjCPropertyDecl::Optional) ? + ObjCMethodDecl::Optional : ObjCMethodDecl::Required); // Invent the arguments for the setter. We don't bother making a // nice name for the argument. ParmVarDecl *Argument = ParmVarDecl::Create(Context, SetterMethod, - property->getLocation(), + property->getLocation(), property->getIdentifier(), property->getType(), /*DInfo=*/0, @@ -1443,7 +1441,7 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, SetterMethod->setSynthesized(true); property->setSetterMethodDecl(SetterMethod); } - // Add any synthesized methods to the global pool. This allows us to + // Add any synthesized methods to the global pool. This allows us to // handle the following, which is supported by GCC (and part of the design). // // @interface Foo @@ -1456,9 +1454,9 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, // } // if (GetterMethod) - AddInstanceMethodToGlobalPool(GetterMethod); + AddInstanceMethodToGlobalPool(GetterMethod); if (SetterMethod) - AddInstanceMethodToGlobalPool(SetterMethod); + AddInstanceMethodToGlobalPool(SetterMethod); } /// CompareMethodParamsInBaseAndSuper - This routine compares methods with @@ -1469,9 +1467,9 @@ void Sema::CompareMethodParamsInBaseAndSuper(Decl *ClassDecl, bool IsInstance) { ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ClassDecl); if (ID == 0) return; - + while (ObjCInterfaceDecl *SD = ID->getSuperClass()) { - ObjCMethodDecl *SuperMethodDecl = + ObjCMethodDecl *SuperMethodDecl = SD->lookupMethod(Method->getSelector(), IsInstance); if (SuperMethodDecl == 0) { ID = SD; @@ -1488,7 +1486,7 @@ void Sema::CompareMethodParamsInBaseAndSuper(Decl *ClassDecl, // If type of arguement of method in this class does not match its // respective argument type in the super class method, issue warning; if (!Context.typesAreCompatible(T1, T2)) { - Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super) + Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super) << T1 << T2; Diag(SuperMethodDecl->getLocation(), diag::note_previous_declaration); return; @@ -1511,8 +1509,8 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, // should be true. if (!ClassDecl) return; - - bool isInterfaceDeclKind = + + bool isInterfaceDeclKind = isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl) || isa<ObjCProtocolDecl>(ClassDecl); bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl); @@ -1531,9 +1529,9 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, if (Method->isInstanceMethod()) { /// Check for instance method of the same name with incompatible types const ObjCMethodDecl *&PrevMethod = InsMap[Method->getSelector()]; - bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) + bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) : false; - if ((isInterfaceDeclKind && PrevMethod && !match) + if ((isInterfaceDeclKind && PrevMethod && !match) || (checkIdenticalMethods && match)) { Diag(Method->getLocation(), diag::err_duplicate_method_decl) << Method->getDeclName(); @@ -1543,16 +1541,16 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, InsMap[Method->getSelector()] = Method; /// The following allows us to typecheck messages to "id". AddInstanceMethodToGlobalPool(Method); - // verify that the instance method conforms to the same definition of + // verify that the instance method conforms to the same definition of // parent methods if it shadows one. CompareMethodParamsInBaseAndSuper(ClassDecl, Method, true); } } else { /// Check for class method of the same name with incompatible types const ObjCMethodDecl *&PrevMethod = ClsMap[Method->getSelector()]; - bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) + bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) : false; - if ((isInterfaceDeclKind && PrevMethod && !match) + if ((isInterfaceDeclKind && PrevMethod && !match) || (checkIdenticalMethods && match)) { Diag(Method->getLocation(), diag::err_duplicate_method_decl) << Method->getDeclName(); @@ -1562,20 +1560,20 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, ClsMap[Method->getSelector()] = Method; /// The following allows us to typecheck messages to "Class". AddFactoryMethodToGlobalPool(Method); - // verify that the class method conforms to the same definition of + // verify that the class method conforms to the same definition of // parent methods if it shadows one. CompareMethodParamsInBaseAndSuper(ClassDecl, Method, false); } } } if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) { - // Compares properties declared in this class to those of its + // Compares properties declared in this class to those of its // super class. ComparePropertiesInBaseAndSuper(I); MergeProtocolPropertiesIntoClass(I, DeclPtrTy::make(I)); } else if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(ClassDecl)) { // Categories are used to extend the class by declaring new methods. - // By the same token, they are also used to add new properties. No + // By the same token, they are also used to add new properties. No // need to compare the added property to those in the class. // Merge protocol properties into category @@ -1597,10 +1595,10 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, IC->setAtEndLoc(AtEndLoc); if (ObjCInterfaceDecl* IDecl = IC->getClassInterface()) ImplMethodsVsClassMethods(IC, IDecl); - } else if (ObjCCategoryImplDecl* CatImplClass = + } else if (ObjCCategoryImplDecl* CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) { CatImplClass->setAtEndLoc(AtEndLoc); - + // Find category interface decl and then check that all methods declared // in this interface are implemented in the category @implementation. if (ObjCInterfaceDecl* IDecl = CatImplClass->getClassInterface()) { @@ -1629,7 +1627,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, /// CvtQTToAstBitMask - utility routine to produce an AST bitmask for /// objective-c's type qualifier from the parser version of the same info. -static Decl::ObjCDeclQualifier +static Decl::ObjCDeclQualifier CvtQTToAstBitMask(ObjCDeclSpec::ObjCDeclQualifier PQTVal) { Decl::ObjCDeclQualifier ret = Decl::OBJC_TQ_None; if (PQTVal & ObjCDeclSpec::DQ_In) @@ -1668,10 +1666,10 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( return DeclPtrTy(); } QualType resultDeclType; - + if (ReturnType) { resultDeclType = GetTypeFromParser(ReturnType); - + // Methods cannot return interface types. All ObjC objects are // passed by reference. if (resultDeclType->isObjCInterfaceType()) { @@ -1681,21 +1679,21 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( } } else // get the type for "id". resultDeclType = Context.getObjCIdType(); - - ObjCMethodDecl* ObjCMethod = + + ObjCMethodDecl* ObjCMethod = ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, Sel, resultDeclType, - cast<DeclContext>(ClassDecl), + cast<DeclContext>(ClassDecl), MethodType == tok::minus, isVariadic, false, - MethodDeclKind == tok::objc_optional ? - ObjCMethodDecl::Optional : + MethodDeclKind == tok::objc_optional ? + ObjCMethodDecl::Optional : ObjCMethodDecl::Required); - + llvm::SmallVector<ParmVarDecl*, 16> Params; - + for (unsigned i = 0, e = Sel.getNumArgs(); i != e; ++i) { QualType ArgType, UnpromotedArgType; - + if (ArgInfo[i].Type == 0) { UnpromotedArgType = ArgType = Context.getObjCIdType(); } else { @@ -1703,7 +1701,7 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( // Perform the default array/function conversions (C99 6.7.5.3p[7,8]). ArgType = adjustParameterType(ArgType); } - + ParmVarDecl* Param; if (ArgType == UnpromotedArgType) Param = ParmVarDecl::Create(Context, ObjCMethod, ArgInfo[i].NameLoc, @@ -1717,20 +1715,20 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( /*DInfo=*/0, //FIXME: Pass info here. UnpromotedArgType, VarDecl::None, 0); - + if (ArgType->isObjCInterfaceType()) { Diag(ArgInfo[i].NameLoc, diag::err_object_cannot_be_passed_returned_by_value) << 1 << ArgType; Param->setInvalidDecl(); } - + Param->setObjCDeclQualifier( CvtQTToAstBitMask(ArgInfo[i].DeclSpec.getObjCDeclQualifier())); - + // Apply the attributes to the parameter. ProcessDeclAttributeList(TUScope, Param, ArgInfo[i].ArgAttrs); - + Params.push_back(Param); } @@ -1741,12 +1739,12 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( if (AttrList) ProcessDeclAttributeList(TUScope, ObjCMethod, AttrList); - - // For implementations (which can be very "coarse grain"), we add the - // method now. This allows the AST to implement lookup methods that work - // incrementally (without waiting until we parse the @end). It also allows + + // For implementations (which can be very "coarse grain"), we add the + // method now. This allows the AST to implement lookup methods that work + // incrementally (without waiting until we parse the @end). It also allows // us to flag multiple declaration errors as they occur. - if (ObjCImplementationDecl *ImpDecl = + if (ObjCImplementationDecl *ImpDecl = dyn_cast<ObjCImplementationDecl>(ClassDecl)) { if (MethodType == tok::minus) { PrevMethod = ImpDecl->getInstanceMethod(Sel); @@ -1757,7 +1755,7 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( } if (AttrList) Diag(EndLoc, diag::warn_attribute_method_def); - } else if (ObjCCategoryImplDecl *CatImpDecl = + } else if (ObjCCategoryImplDecl *CatImpDecl = dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) { if (MethodType == tok::minus) { PrevMethod = CatImpDecl->getInstanceMethod(Sel); @@ -1774,11 +1772,11 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( Diag(ObjCMethod->getLocation(), diag::err_duplicate_method_decl) << ObjCMethod->getDeclName(); Diag(PrevMethod->getLocation(), diag::note_previous_declaration); - } + } return DeclPtrTy::make(ObjCMethod); } -void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, +void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, SourceLocation Loc, unsigned &Attributes) { // FIXME: Improve the reported location. @@ -1795,8 +1793,8 @@ void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, "assign" : (Attributes & ObjCDeclSpec::DQ_PR_copy) ? "copy" : "retain"; - - Diag(Loc, (Attributes & (ObjCDeclSpec::DQ_PR_readwrite)) ? + + Diag(Loc, (Attributes & (ObjCDeclSpec::DQ_PR_readwrite)) ? diag::err_objc_property_attr_mutually_exclusive : diag::warn_objc_property_attr_mutually_exclusive) << "readonly" << which; @@ -1804,8 +1802,8 @@ void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, // Check for copy or retain on non-object types. if ((Attributes & (ObjCDeclSpec::DQ_PR_copy | ObjCDeclSpec::DQ_PR_retain)) && - !PropertyTy->isObjCObjectPointerType() && - !PropertyTy->isBlockPointerType() && + !PropertyTy->isObjCObjectPointerType() && + !PropertyTy->isBlockPointerType() && !Context.isObjCNSObjectType(PropertyTy)) { Diag(Loc, diag::err_objc_property_requires_object) << (Attributes & ObjCDeclSpec::DQ_PR_copy ? "copy" : "retain"); @@ -1818,7 +1816,7 @@ void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) << "assign" << "copy"; Attributes &= ~ObjCDeclSpec::DQ_PR_copy; - } + } if (Attributes & ObjCDeclSpec::DQ_PR_retain) { Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) << "assign" << "retain"; @@ -1839,13 +1837,13 @@ void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, !(Attributes & ObjCDeclSpec::DQ_PR_readonly) && PropertyTy->isObjCObjectPointerType()) { // Skip this warning in gc-only mode. - if (getLangOptions().getGCMode() != LangOptions::GCOnly) + if (getLangOptions().getGCMode() != LangOptions::GCOnly) Diag(Loc, diag::warn_objc_property_no_assignment_attribute); // If non-gc code warn that this is likely inappropriate. if (getLangOptions().getGCMode() == LangOptions::NonGC) Diag(Loc, diag::warn_objc_property_default_assign_on_object); - + // FIXME: Implement warning dependent on NSCopying being // implemented. See also: // <rdar://5168496&4855821&5607453&5096644&4947311&5698469&4947014&5168496> @@ -1858,7 +1856,7 @@ void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, Diag(Loc, diag::warn_objc_property_copy_missing_on_block); } -Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, +Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, FieldDeclarator &FD, ObjCDeclSpec &ODS, Selector GetterSel, @@ -1870,11 +1868,11 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, bool isReadWrite = ((Attributes & ObjCDeclSpec::DQ_PR_readwrite) || // default is readwrite! !(Attributes & ObjCDeclSpec::DQ_PR_readonly)); - // property is defaulted to 'assign' if it is readwrite and is + // property is defaulted to 'assign' if it is readwrite and is // not retain or copy bool isAssign = ((Attributes & ObjCDeclSpec::DQ_PR_assign) || - (isReadWrite && - !(Attributes & ObjCDeclSpec::DQ_PR_retain) && + (isReadWrite && + !(Attributes & ObjCDeclSpec::DQ_PR_retain) && !(Attributes & ObjCDeclSpec::DQ_PR_copy))); QualType T = GetTypeForDeclarator(FD.D, S); Decl *ClassDecl = ClassCategory.getAs<Decl>(); @@ -1883,20 +1881,20 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, CheckObjCPropertyAttributes(T, AtLoc, Attributes); if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) if (!CDecl->getIdentifier()) { - // This is a continuation class. property requires special + // This is a continuation class. property requires special // handling. if ((CCPrimary = CDecl->getClassInterface())) { // Find the property in continuation class's primary class only. ObjCPropertyDecl *PIDecl = 0; IdentifierInfo *PropertyId = FD.D.getIdentifier(); - for (ObjCInterfaceDecl::prop_iterator + for (ObjCInterfaceDecl::prop_iterator I = CCPrimary->prop_begin(), E = CCPrimary->prop_end(); I != E; ++I) if ((*I)->getIdentifier() == PropertyId) { PIDecl = *I; break; } - + if (PIDecl) { // property 'PIDecl's readonly attribute will be over-ridden // with continuation class's readwrite property attribute! @@ -1912,10 +1910,10 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy); PIDecl->setSetterName(SetterSel); } else - Diag(AtLoc, diag::err_use_continuation_class) + Diag(AtLoc, diag::err_use_continuation_class) << CCPrimary->getDeclName(); *isOverridingProperty = true; - // Make sure setter decl is synthesized, and added to primary + // Make sure setter decl is synthesized, and added to primary // class's list. ProcessPropertyDecl(PIDecl, CCPrimary); return DeclPtrTy(); @@ -1927,72 +1925,72 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, Diag(CDecl->getLocation(), diag::err_continuation_class); *isOverridingProperty = true; return DeclPtrTy(); - } + } } - + // Issue a warning if property is 'assign' as default and its object, which is - // gc'able conforms to NSCopying protocol + // gc'able conforms to NSCopying protocol if (getLangOptions().getGCMode() != LangOptions::NonGC && isAssign && !(Attributes & ObjCDeclSpec::DQ_PR_assign)) if (T->isObjCObjectPointerType()) { QualType InterfaceTy = T->getPointeeType(); - if (const ObjCInterfaceType *OIT = + if (const ObjCInterfaceType *OIT = InterfaceTy->getAsObjCInterfaceType()) { ObjCInterfaceDecl *IDecl = OIT->getDecl(); if (IDecl) - if (ObjCProtocolDecl* PNSCopying = + if (ObjCProtocolDecl* PNSCopying = LookupProtocol(&Context.Idents.get("NSCopying"))) if (IDecl->ClassImplementsProtocol(PNSCopying, true)) - Diag(AtLoc, diag::warn_implements_nscopying) + Diag(AtLoc, diag::warn_implements_nscopying) << FD.D.getIdentifier(); } } if (T->isObjCInterfaceType()) Diag(FD.D.getIdentifierLoc(), diag::err_statically_allocated_object); - + DeclContext *DC = dyn_cast<DeclContext>(ClassDecl); assert(DC && "ClassDecl is not a DeclContext"); ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC, - FD.D.getIdentifierLoc(), + FD.D.getIdentifierLoc(), FD.D.getIdentifier(), T); DC->addDecl(PDecl); - + if (T->isArrayType() || T->isFunctionType()) { Diag(AtLoc, diag::err_property_type) << T; PDecl->setInvalidDecl(); } - + ProcessDeclAttributes(S, PDecl, FD.D); // Regardless of setter/getter attribute, we save the default getter/setter // selector names in anticipation of declaration of setter/getter methods. PDecl->setGetterName(GetterSel); PDecl->setSetterName(SetterSel); - + if (Attributes & ObjCDeclSpec::DQ_PR_readonly) PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly); - + if (Attributes & ObjCDeclSpec::DQ_PR_getter) PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter); - + if (Attributes & ObjCDeclSpec::DQ_PR_setter) PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter); - + if (isReadWrite) PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite); - + if (Attributes & ObjCDeclSpec::DQ_PR_retain) PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain); - + if (Attributes & ObjCDeclSpec::DQ_PR_copy) PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy); - + if (isAssign) PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign); - + if (Attributes & ObjCDeclSpec::DQ_PR_nonatomic) PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic); - + if (MethodImplKind == tok::objc_required) PDecl->setPropertyImplementation(ObjCPropertyDecl::Required); else if (MethodImplKind == tok::objc_optional) @@ -2002,7 +2000,7 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, // Make sure setter/getters are declared here. if (CCPrimary) ProcessPropertyDecl(PDecl, CCPrimary); - + return DeclPtrTy::make(PDecl); } @@ -2010,9 +2008,9 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, /// builds the AST node for a property implementation declaration; declared /// as @synthesize or @dynamic. /// -Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, +Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, SourceLocation PropertyLoc, - bool Synthesize, + bool Synthesize, DeclPtrTy ClassCatImpDecl, IdentifierInfo *PropertyId, IdentifierInfo *PropertyIvar) { @@ -2032,9 +2030,9 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, IDecl = IC->getClassInterface(); // We always synthesize an interface for an implementation // without an interface decl. So, IDecl is always non-zero. - assert(IDecl && + assert(IDecl && "ActOnPropertyImplDecl - @implementation without @interface"); - + // Look for this property declaration in the @implementation's @interface property = IDecl->FindPropertyDeclaration(PropertyId); if (!property) { @@ -2045,15 +2043,15 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, if (Synthesize) { Diag(AtLoc, diag::error_synthesize_category_decl); return DeclPtrTy(); - } + } IDecl = CatImplClass->getClassInterface(); if (!IDecl) { Diag(AtLoc, diag::error_missing_property_interface); return DeclPtrTy(); } - ObjCCategoryDecl *Category = + ObjCCategoryDecl *Category = IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier()); - + // If category for this implementation not found, it is an error which // has already been reported eralier. if (!Category) @@ -2081,10 +2079,10 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, Ivar = IDecl->lookupInstanceVariable(PropertyIvar, ClassDeclared); if (!Ivar) { DeclContext *EnclosingContext = cast_or_null<DeclContext>(IDecl); - assert(EnclosingContext && + assert(EnclosingContext && "null DeclContext for synthesized ivar - ActOnPropertyImplDecl"); - Ivar = ObjCIvarDecl::Create(Context, EnclosingContext, PropertyLoc, - PropertyIvar, PropType, /*Dinfo=*/0, + Ivar = ObjCIvarDecl::Create(Context, EnclosingContext, PropertyLoc, + PropertyIvar, PropType, /*Dinfo=*/0, ObjCIvarDecl::Public, (Expr *)0); Ivar->setLexicalDeclContext(IDecl); @@ -2092,34 +2090,34 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, property->setPropertyIvarDecl(Ivar); if (!getLangOptions().ObjCNonFragileABI) Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId; - // Note! I deliberately want it to fall thru so, we have a + // Note! I deliberately want it to fall thru so, we have a // a property implementation and to avoid future warnings. } else if (getLangOptions().ObjCNonFragileABI && ClassDeclared != IDecl) { Diag(PropertyLoc, diag::error_ivar_in_superclass_use) - << property->getDeclName() << Ivar->getDeclName() + << property->getDeclName() << Ivar->getDeclName() << ClassDeclared->getDeclName(); Diag(Ivar->getLocation(), diag::note_previous_access_declaration) << Ivar << Ivar->getNameAsCString(); // Note! I deliberately want it to fall thru so more errors are caught. } QualType IvarType = Context.getCanonicalType(Ivar->getType()); - + // Check that type of property and its ivar are type compatible. if (PropType != IvarType) { if (CheckAssignmentConstraints(PropType, IvarType) != Compatible) { Diag(PropertyLoc, diag::error_property_ivar_type) << property->getDeclName() << Ivar->getDeclName(); - // Note! I deliberately want it to fall thru so, we have a + // Note! I deliberately want it to fall thru so, we have a // a property implementation and to avoid future warnings. } - + // FIXME! Rules for properties are somewhat different that those // for assignments. Use a new routine to consolidate all cases; // specifically for property redeclarations as well as for ivars. QualType lhsType =Context.getCanonicalType(PropType).getUnqualifiedType(); QualType rhsType =Context.getCanonicalType(IvarType).getUnqualifiedType(); - if (lhsType != rhsType && + if (lhsType != rhsType && lhsType->isArithmeticType()) { Diag(PropertyLoc, diag::error_property_ivar_type) << property->getDeclName() << Ivar->getDeclName(); @@ -2132,36 +2130,36 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, << property->getDeclName() << Ivar->getDeclName(); // Fall thru - see previous comment } - if ((property->getType()->isObjCObjectPointerType() || + if ((property->getType()->isObjCObjectPointerType() || PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak() && getLangOptions().getGCMode() != LangOptions::NonGC) { Diag(PropertyLoc, diag::error_strong_property) << property->getDeclName() << Ivar->getDeclName(); - // Fall thru - see previous comment + // Fall thru - see previous comment } } } else if (PropertyIvar) // @dynamic Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl); assert (property && "ActOnPropertyImplDecl - property declaration missing"); - ObjCPropertyImplDecl *PIDecl = - ObjCPropertyImplDecl::Create(Context, CurContext, AtLoc, PropertyLoc, - property, - (Synthesize ? - ObjCPropertyImplDecl::Synthesize + ObjCPropertyImplDecl *PIDecl = + ObjCPropertyImplDecl::Create(Context, CurContext, AtLoc, PropertyLoc, + property, + (Synthesize ? + ObjCPropertyImplDecl::Synthesize : ObjCPropertyImplDecl::Dynamic), Ivar); if (IC) { if (Synthesize) - if (ObjCPropertyImplDecl *PPIDecl = + if (ObjCPropertyImplDecl *PPIDecl = IC->FindPropertyImplIvarDecl(PropertyIvar)) { - Diag(PropertyLoc, diag::error_duplicate_ivar_use) - << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier() + Diag(PropertyLoc, diag::error_duplicate_ivar_use) + << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier() << PropertyIvar; Diag(PPIDecl->getLocation(), diag::note_previous_use); } - - if (ObjCPropertyImplDecl *PPIDecl + + if (ObjCPropertyImplDecl *PPIDecl = IC->FindPropertyImplDecl(PropertyId)) { Diag(PropertyLoc, diag::error_property_implemented) << PropertyId; Diag(PPIDecl->getLocation(), diag::note_previous_declaration); @@ -2170,39 +2168,39 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, IC->addPropertyImplementation(PIDecl); } else { if (Synthesize) - if (ObjCPropertyImplDecl *PPIDecl = + if (ObjCPropertyImplDecl *PPIDecl = CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) { - Diag(PropertyLoc, diag::error_duplicate_ivar_use) - << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier() + Diag(PropertyLoc, diag::error_duplicate_ivar_use) + << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier() << PropertyIvar; Diag(PPIDecl->getLocation(), diag::note_previous_use); } - - if (ObjCPropertyImplDecl *PPIDecl = + + if (ObjCPropertyImplDecl *PPIDecl = CatImplClass->FindPropertyImplDecl(PropertyId)) { Diag(PropertyLoc, diag::error_property_implemented) << PropertyId; Diag(PPIDecl->getLocation(), diag::note_previous_declaration); return DeclPtrTy(); - } + } CatImplClass->addPropertyImplementation(PIDecl); } - + return DeclPtrTy::make(PIDecl); } bool Sema::CheckObjCDeclScope(Decl *D) { if (isa<TranslationUnitDecl>(CurContext->getLookupContext())) return false; - + Diag(D->getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope); D->setInvalidDecl(); - + return true; } /// Called whenever @defs(ClassName) is encountered in the source. Inserts the /// instance variables of ClassName into Decls. -void Sema::ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, +void Sema::ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, IdentifierInfo *ClassName, llvm::SmallVectorImpl<DeclPtrTy> &Decls) { // Check that ClassName is a valid class @@ -2215,7 +2213,7 @@ void Sema::ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, Diag(DeclStart, diag::err_atdef_nonfragile_interface); return; } - + // Collect the instance variables llvm::SmallVector<FieldDecl*, 32> RecFields; Context.CollectObjCIvars(Class, RecFields); @@ -2228,7 +2226,7 @@ void Sema::ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, ID->getBitWidth()); Decls.push_back(Sema::DeclPtrTy::make(FD)); } - + // Introduce all of these fields into the appropriate scope. for (llvm::SmallVectorImpl<DeclPtrTy>::iterator D = Decls.begin(); D != Decls.end(); ++D) { diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 2644c1d6f7..c2a4119c53 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -46,12 +46,12 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) { // stuff. Don't warn if we are implementing a deprecated // construct. bool isSilenced = false; - + if (NamedDecl *ND = getCurFunctionOrMethodDecl()) { // If this reference happens *in* a deprecated function or method, don't // warn. isSilenced = ND->getAttr<DeprecatedAttr>(); - + // If this is an Objective-C method implementation, check to see if the // method was deprecated on the declaration, not the definition. if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(ND)) { @@ -59,14 +59,14 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) { // ObjCImplementationDecl. if (ObjCImplementationDecl *Impl = dyn_cast<ObjCImplementationDecl>(MD->getParent())) { - + MD = Impl->getClassInterface()->getMethod(MD->getSelector(), MD->isInstanceMethod()); isSilenced |= MD && MD->getAttr<DeprecatedAttr>(); } } } - + if (!isSilenced) Diag(Loc, diag::warn_deprecated) << D->getDeclName(); } @@ -90,18 +90,17 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) { } /// DiagnoseSentinelCalls - This routine checks on method dispatch calls -/// (and other functions in future), which have been declared with sentinel +/// (and other functions in future), which have been declared with sentinel /// attribute. It warns if call does not have the sentinel argument. /// void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, - Expr **Args, unsigned NumArgs) -{ + Expr **Args, unsigned NumArgs) { const SentinelAttr *attr = D->getAttr<SentinelAttr>(); - if (!attr) + if (!attr) return; int sentinelPos = attr->getSentinel(); int nullPos = attr->getNullPos(); - + // FIXME. ObjCMethodDecl and FunctionDecl need be derived from the same common // base class. Then we won't be needing two versions of the same code. unsigned int i = 0; @@ -132,7 +131,7 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, // block or function pointer call. QualType Ty = V->getType(); if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) { - const FunctionType *FT = Ty->isFunctionPointerType() + const FunctionType *FT = Ty->isFunctionPointerType() ? Ty->getAs<PointerType>()->getPointeeType()->getAsFunctionType() : Ty->getAs<BlockPointerType>()->getPointeeType()->getAsFunctionType(); if (const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FT)) { @@ -196,7 +195,7 @@ void Sema::DefaultFunctionArrayConversion(Expr *&E) { assert(!Ty.isNull() && "DefaultFunctionArrayConversion - missing type"); if (Ty->isFunctionType()) - ImpCastExprToType(E, Context.getPointerType(Ty), + ImpCastExprToType(E, Context.getPointerType(Ty), CastExpr::CK_FunctionToPointerDecay); else if (Ty->isArrayType()) { // In C90 mode, arrays only promote to pointers if the array expression is @@ -218,14 +217,14 @@ void Sema::DefaultFunctionArrayConversion(Expr *&E) { } /// UsualUnaryConversions - Performs various conversions that are common to most -/// operators (C99 6.3). The conversions of array and function types are +/// operators (C99 6.3). The conversions of array and function types are /// sometimes surpressed. For example, the array->pointer conversion doesn't /// apply if the array is an argument to the sizeof or address (&) operators. /// In these instances, this routine should *not* be called. Expr *Sema::UsualUnaryConversions(Expr *&Expr) { QualType Ty = Expr->getType(); assert(!Ty.isNull() && "UsualUnaryConversions - missing type"); - + // C99 6.3.1.1p2: // // The following may be used in an expression wherever an int or @@ -255,17 +254,17 @@ Expr *Sema::UsualUnaryConversions(Expr *&Expr) { } /// DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that -/// do not have a prototype. Arguments that have type float are promoted to +/// do not have a prototype. Arguments that have type float are promoted to /// double. All other argument types are converted by UsualUnaryConversions(). void Sema::DefaultArgumentPromotion(Expr *&Expr) { QualType Ty = Expr->getType(); assert(!Ty.isNull() && "DefaultArgumentPromotion - missing type"); - + // If this is a 'float' (CVR qualified or typedef) promote to double. if (const BuiltinType *BT = Ty->getAsBuiltinType()) if (BT->getKind() == BuiltinType::Float) return ImpCastExprToType(Expr, Context.DoubleTy); - + UsualUnaryConversions(Expr); } @@ -275,14 +274,14 @@ void Sema::DefaultArgumentPromotion(Expr *&Expr) { /// completely illegal. bool Sema::DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT) { DefaultArgumentPromotion(Expr); - + if (Expr->getType()->isObjCInterfaceType()) { Diag(Expr->getLocStart(), diag::err_cannot_pass_objc_interface_to_vararg) << Expr->getType() << CT; return true; } - + if (!Expr->getType()->isPODType()) Diag(Expr->getLocStart(), diag::warn_cannot_pass_non_pod_arg_to_vararg) << Expr->getType() << CT; @@ -293,7 +292,7 @@ bool Sema::DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT) { /// UsualArithmeticConversions - Performs various conversions that are common to /// binary operators (C99 6.3.1.8). If both operands aren't arithmetic, this -/// routine returns the first non-arithmetic type found. The client is +/// routine returns the first non-arithmetic type found. The client is /// responsible for emitting appropriate error diagnostics. /// FIXME: verify the conversion rules for "complex int" are consistent with /// GCC. @@ -304,11 +303,11 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr, UsualUnaryConversions(rhsExpr); - // For conversion purposes, we ignore any qualifiers. + // For conversion purposes, we ignore any qualifiers. // For example, "const float" and "float" are equivalent. QualType lhs = Context.getCanonicalType(lhsExpr->getType()).getUnqualifiedType(); - QualType rhs = + QualType rhs = Context.getCanonicalType(rhsExpr->getType()).getUnqualifiedType(); // If both types are identical, no conversion is needed. @@ -372,9 +371,9 @@ Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) { StrTy = Context.getConstantArrayType(StrTy, llvm::APInt(32, Literal.GetNumStringChars()+1), ArrayType::Normal, 0); - + // Pass &StringTokLocs[0], StringTokLocs.size() to factory! - return Owned(StringLiteral::Create(Context, Literal.GetString(), + return Owned(StringLiteral::Create(Context, Literal.GetString(), Literal.GetStringLength(), Literal.AnyWide, StrTy, &StringTokLocs[0], @@ -395,7 +394,7 @@ static bool ShouldSnapshotBlockValueReference(BlockSemaInfo *CurBlock, // we wanted to. if (CurBlock->TheDecl == VD->getDeclContext()) return false; - + // If this is an enum constant or function, it is constant, don't snapshot. if (isa<EnumConstantDecl>(VD) || isa<FunctionDecl>(VD)) return false; @@ -406,7 +405,7 @@ static bool ShouldSnapshotBlockValueReference(BlockSemaInfo *CurBlock, if (const VarDecl *Var = dyn_cast<VarDecl>(VD)) if (!Var->hasLocalStorage()) return false; - + // Blocks that have these can't be constant. CurBlock->hasBlockDeclRefExprs = true; @@ -420,15 +419,15 @@ static bool ShouldSnapshotBlockValueReference(BlockSemaInfo *CurBlock, // having a reference outside it. if (NextBlock->TheDecl == VD->getDeclContext()) break; - + // Otherwise, the DeclRef from the inner block causes the outer one to need // a snapshot as well. NextBlock->hasBlockDeclRefExprs = true; } - + return true; -} - +} + /// ActOnIdentifierExpr - The parser read an identifier in expression context, @@ -454,35 +453,35 @@ Sema::BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc, const CXXScopeSpec *SS) { if (Context.getCanonicalType(Ty) == Context.UndeducedAutoTy) { Diag(Loc, - diag::err_auto_variable_cannot_appear_in_own_initializer) + diag::err_auto_variable_cannot_appear_in_own_initializer) << D->getDeclName(); return ExprError(); } - + if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext)) { if (const FunctionDecl *FD = MD->getParent()->isLocalClass()) { if (VD->hasLocalStorage() && VD->getDeclContext() != CurContext) { - Diag(Loc, diag::err_reference_to_local_var_in_enclosing_function) + Diag(Loc, diag::err_reference_to_local_var_in_enclosing_function) << D->getIdentifier() << FD->getDeclName(); - Diag(D->getLocation(), diag::note_local_variable_declared_here) + Diag(D->getLocation(), diag::note_local_variable_declared_here) << D->getIdentifier(); return ExprError(); } } } } - + MarkDeclarationReferenced(Loc, D); - + Expr *E; if (SS && !SS->isEmpty()) { - E = new (Context) QualifiedDeclRefExpr(D, Ty, Loc, TypeDependent, + E = new (Context) QualifiedDeclRefExpr(D, Ty, Loc, TypeDependent, ValueDependent, SS->getRange(), static_cast<NestedNameSpecifier *>(SS->getScopeRep())); } else E = new (Context) DeclRefExpr(D, Ty, Loc, TypeDependent, ValueDependent); - + return Owned(E); } @@ -491,14 +490,14 @@ Sema::BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc, /// is Record. static Decl *getObjectForAnonymousRecordDecl(ASTContext &Context, RecordDecl *Record) { - assert(Record->isAnonymousStructOrUnion() && + assert(Record->isAnonymousStructOrUnion() && "Record must be an anonymous struct or union!"); - + // FIXME: Once Decls are directly linked together, this will be an O(1) // operation rather than a slow walk through DeclContext's vector (which // itself will be eliminated). DeclGroups might make this even better. DeclContext *Ctx = Record->getDeclContext(); - for (DeclContext::decl_iterator D = Ctx->decls_begin(), + for (DeclContext::decl_iterator D = Ctx->decls_begin(), DEnd = Ctx->decls_end(); D != DEnd; ++D) { if (*D == Record) { @@ -547,7 +546,7 @@ VarDecl *Sema::BuildAnonymousStructUnionMemberPath(FieldDecl *Field, break; } Ctx = Ctx->getParent(); - } while (Ctx->isRecord() && + } while (Ctx->isRecord() && cast<RecordDecl>(Ctx)->isAnonymousStructOrUnion()); return BaseObject; @@ -559,7 +558,7 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc, Expr *BaseObjectExpr, SourceLocation OpLoc) { llvm::SmallVector<FieldDecl *, 4> AnonFields; - VarDecl *BaseObject = BuildAnonymousStructUnionMemberPath(Field, + VarDecl *BaseObject = BuildAnonymousStructUnionMemberPath(Field, AnonFields); // Build the expression that refers to the base object, from @@ -575,7 +574,7 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc, MarkDeclarationReferenced(Loc, BaseObject); BaseObjectExpr = new (Context) DeclRefExpr(BaseObject,BaseObject->getType(), SourceLocation()); - ExtraQuals + ExtraQuals = Context.getCanonicalType(BaseObject->getType()).getCVRQualifiers(); } else if (BaseObjectExpr) { // The caller provided the base object expression. Determine @@ -593,11 +592,11 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc, // program our base object expression is "this". if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext)) { if (!MD->isStatic()) { - QualType AnonFieldType + QualType AnonFieldType = Context.getTagDeclType( cast<RecordDecl>(AnonFields.back()->getDeclContext())); QualType ThisType = Context.getTagDeclType(MD->getParent()); - if ((Context.getCanonicalType(AnonFieldType) + if ((Context.getCanonicalType(AnonFieldType) == Context.getCanonicalType(ThisType)) || IsDerivedFrom(ThisType, AnonFieldType)) { // Our base object expression is "this". @@ -612,7 +611,7 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc, ExtraQuals = MD->getTypeQualifiers(); } - if (!BaseObjectExpr) + if (!BaseObjectExpr) return ExprError(Diag(Loc, diag::err_invalid_non_static_member_use) << Field->getDeclName()); } @@ -626,7 +625,7 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc, FI != FIEnd; ++FI) { QualType MemberType = (*FI)->getType(); if (!(*FI)->isMutable()) { - unsigned combinedQualifiers + unsigned combinedQualifiers = MemberType.getCVRQualifiers() | ExtraQuals; MemberType = MemberType.getQualifiedType(combinedQualifiers); } @@ -665,7 +664,7 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc, Sema::OwningExprResult Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, DeclarationName Name, bool HasTrailingLParen, - const CXXScopeSpec *SS, + const CXXScopeSpec *SS, bool isAddressOfOperand) { // Could be enum-constant, value decl, instance variable, etc. if (SS && SS->isInvalid()) @@ -678,7 +677,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, // FIXME: Member of the current instantiation. if (SS && isDependentScopeSpecifier(*SS)) { return Owned(new (Context) UnresolvedDeclRefExpr(Name, Context.DependentTy, - Loc, SS->getRange(), + Loc, SS->getRange(), static_cast<NestedNameSpecifier *>(SS->getScopeRep()), isAddressOfOperand)); } @@ -692,7 +691,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, : SourceRange()); return ExprError(); } - + NamedDecl *D = Lookup.getAsDecl(); // If this reference is in an Objective-C method, then ivar lookup happens as @@ -701,8 +700,8 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, if (II && getCurMethodDecl()) { // There are two cases to handle here. 1) scoped lookup could have failed, // in which case we should look for an ivar. 2) scoped lookup could have - // found a decl, but that decl is outside the current instance method (i.e. - // a global variable). In these two cases, we do a lookup for an ivar with + // found a decl, but that decl is outside the current instance method (i.e. + // a global variable). In these two cases, we do a lookup for an ivar with // this name, if the lookup sucedes, we replace it our current decl. if (D == 0 || D->isDefinedOutsideFunctionOrMethod()) { ObjCInterfaceDecl *IFace = getCurMethodDecl()->getClassInterface(); @@ -711,12 +710,12 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, // Check if referencing a field with __attribute__((deprecated)). if (DiagnoseUseOfDecl(IV, Loc)) return ExprError(); - + // If we're referencing an invalid decl, just return this as a silent // error node. The error diagnostic was already emitted on the decl. if (IV->isInvalidDecl()) return ExprError(); - + bool IsClsMethod = getCurMethodDecl()->isClassMethod(); // If a class method attemps to use a free standing ivar, this is // an error. @@ -735,8 +734,8 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, OwningExprResult SelfExpr = ActOnIdentifierExpr(S, SourceLocation(), II, false); MarkDeclarationReferenced(Loc, IV); - return Owned(new (Context) - ObjCIvarRefExpr(IV, IV->getType(), Loc, + return Owned(new (Context) + ObjCIvarRefExpr(IV, IV->getType(), Loc, SelfExpr.takeAs<Expr>(), true, true)); } } @@ -753,7 +752,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, // Needed to implement property "super.method" notation. if (D == 0 && II->isStr("super")) { QualType T; - + if (getCurMethodDecl()->isInstanceMethod()) T = Context.getObjCObjectPointerType(Context.getObjCInterfaceType( getCurMethodDecl()->getClassInterface())); @@ -765,7 +764,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, // Determine whether this name might be a candidate for // argument-dependent lookup. - bool ADL = getLangOptions().CPlusPlus && (!SS || !SS->isSet()) && + bool ADL = getLangOptions().CPlusPlus && (!SS || !SS->isSet()) && HasTrailingLParen; if (ADL && D == 0) { @@ -791,7 +790,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, // If this name wasn't predeclared and if this is not a function call, // diagnose the problem. if (SS && !SS->isEmpty()) { - DiagnoseMissingMember(Loc, Name, + DiagnoseMissingMember(Loc, Name, (NestedNameSpecifier *)SS->getScopeRep(), SS->getRange()); return ExprError(); @@ -803,18 +802,18 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, return ExprError(Diag(Loc, diag::err_undeclared_var_use) << Name); } } - + if (VarDecl *Var = dyn_cast<VarDecl>(D)) { // Warn about constructs like: // if (void *X = foo()) { ... } else { X }. // In the else block, the pointer is always false. - + // FIXME: In a template instantiation, we don't have scope // information to check this property. if (Var->isDeclaredInCondition() && Var->getType()->isScalarType()) { Scope *CheckS = S; while (CheckS) { - if (CheckS->isWithinElse() && + if (CheckS->isWithinElse() && CheckS->getControlParent()->isDeclScope(DeclPtrTy::make(Var))) { if (Var->getType()->isBooleanType()) ExprError(Diag(Loc, diag::warn_value_always_false) @@ -824,7 +823,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, << Var->getDeclName()); break; } - + // Move up one more control parent to check again. CheckS = CheckS->getControlParent(); if (CheckS) @@ -848,16 +847,16 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, return BuildDeclRefExpr(Func, NoProtoType, Loc, false, false, SS); } } - + return BuildDeclarationNameExpr(Loc, D, HasTrailingLParen, SS, isAddressOfOperand); } /// \brief Cast member's object to its own class if necessary. bool Sema::PerformObjectMemberConversion(Expr *&From, NamedDecl *Member) { if (FieldDecl *FD = dyn_cast<FieldDecl>(Member)) - if (CXXRecordDecl *RD = + if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(FD->getDeclContext())) { - QualType DestType = + QualType DestType = Context.getCanonicalType(Context.getTypeDeclType(RD)); if (DestType->isDependentType() || From->getType()->isDependentType()) return false; @@ -880,17 +879,17 @@ Sema::PerformObjectMemberConversion(Expr *&From, NamedDecl *Member) { } /// \brief Build a MemberExpr AST node. -static MemberExpr *BuildMemberExpr(ASTContext &C, Expr *Base, bool isArrow, - const CXXScopeSpec *SS, NamedDecl *Member, +static MemberExpr *BuildMemberExpr(ASTContext &C, Expr *Base, bool isArrow, + const CXXScopeSpec *SS, NamedDecl *Member, SourceLocation Loc, QualType Ty) { if (SS && SS->isSet()) - return MemberExpr::Create(C, Base, isArrow, + return MemberExpr::Create(C, Base, isArrow, (NestedNameSpecifier *)SS->getScopeRep(), - SS->getRange(), Member, Loc, + SS->getRange(), Member, Loc, // FIXME: Explicit template argument lists false, SourceLocation(), 0, 0, SourceLocation(), Ty); - + return new (C) MemberExpr(Base, isArrow, Member, Loc, Ty); } @@ -898,11 +897,11 @@ static MemberExpr *BuildMemberExpr(ASTContext &C, Expr *Base, bool isArrow, Sema::OwningExprResult Sema::BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D, bool HasTrailingLParen, - const CXXScopeSpec *SS, + const CXXScopeSpec *SS, bool isAddressOfOperand) { assert(D && "Cannot refer to a NULL declaration"); DeclarationName Name = D->getDeclName(); - + // If this is an expression of the form &Class::member, don't build an // implicit member ref, because we want a pointer to the member in general, // not any specific instance's member. @@ -935,7 +934,7 @@ Sema::BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D, if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext)) { if (!MD->isStatic()) { - // C++ [class.mfct.nonstatic]p2: + // C++ [class.mfct.nonstatic]p2: // [...] if name lookup (3.4.1) resolves the name in the // id-expression to a nonstatic nontype member of class X or of // a base class of X, the id-expression is transformed into a @@ -950,7 +949,7 @@ Sema::BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D, if (const ReferenceType *RefType = MemberType->getAs<ReferenceType>()) MemberType = RefType->getPointeeType(); else if (!FD->isMutable()) { - unsigned combinedQualifiers + unsigned combinedQualifiers = MemberType.getCVRQualifiers() | MD->getTypeQualifiers(); MemberType = MemberType.getQualifiedType(combinedQualifiers); } @@ -959,25 +958,25 @@ Sema::BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D, Ctx = Method->getParent(); MemberType = Method->getType(); } - } else if (FunctionTemplateDecl *FunTmpl + } else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D)) { - if (CXXMethodDecl *Method + if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl())) { - if (!Method->isStatic()) { + if (!Method->isStatic()) { Ctx = Method->getParent(); MemberType = Context.OverloadTy; } } - } else if (OverloadedFunctionDecl *Ovl + } else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) { // FIXME: We need an abstraction for iterating over one or more function // templates or functions. This code is far too repetitive! - for (OverloadedFunctionDecl::function_iterator + for (OverloadedFunctionDecl::function_iterator Func = Ovl->function_begin(), FuncEnd = Ovl->function_end(); Func != FuncEnd; ++Func) { CXXMethodDecl *DMethod = 0; - if (FunctionTemplateDecl *FunTmpl + if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(*Func)) DMethod = dyn_cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl()); else @@ -994,7 +993,7 @@ Sema::BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D, if (Ctx && Ctx->isRecord()) { QualType CtxType = Context.getTagDeclType(cast<CXXRecordDecl>(Ctx)); QualType ThisType = Context.getTagDeclType(MD->getParent()); - if ((Context.getCanonicalType(CtxType) + if ((Context.getCanonicalType(CtxType) == Context.getCanonicalType(ThisType)) || IsDerivedFrom(ThisType, CtxType)) { // Build the implicit member access expression. @@ -1042,8 +1041,8 @@ Sema::BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D, return BuildDeclRefExpr(Template, Context.OverloadTy, Loc, false, false, SS); else if (UnresolvedUsingDecl *UD = dyn_cast<UnresolvedUsingDecl>(D)) - return BuildDeclRefExpr(UD, Context.DependentTy, Loc, - /*TypeDependent=*/true, + return BuildDeclRefExpr(UD, Context.DependentTy, Loc, + /*TypeDependent=*/true, /*ValueDependent=*/true, SS); ValueDecl *VD = cast<ValueDecl>(D); @@ -1052,7 +1051,7 @@ Sema::BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D, // this check when we're going to perform argument-dependent lookup // on this function name, because this might not be the function // that overload resolution actually selects. - bool ADL = getLangOptions().CPlusPlus && (!SS || !SS->isSet()) && + bool ADL = getLangOptions().CPlusPlus && (!SS || !SS->isSet()) && HasTrailingLParen; if (!(ADL && isa<FunctionDecl>(VD)) && DiagnoseUseOfDecl(VD, Loc)) return ExprError(); @@ -1078,9 +1077,9 @@ Sema::BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D, // This is to record that a 'const' was actually synthesize and added. bool constAdded = !ExprTy.isConstQualified(); // Variable will be bound by-copy, make it const within the closure. - + ExprTy.addConst(); - return Owned(new (Context) BlockDeclRefExpr(VD, ExprTy, Loc, false, + return Owned(new (Context) BlockDeclRefExpr(VD, ExprTy, Loc, false, constAdded)); } // If this reference is not in a block or if the referenced variable is @@ -1090,7 +1089,7 @@ Sema::BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D, bool ValueDependent = false; if (getLangOptions().CPlusPlus) { // C++ [temp.dep.expr]p3: - // An id-expression is type-dependent if it contains: + // An id-expression is type-dependent if it contains: // - an identifier that was declared with a dependent type, if (VD->getType()->isDependentType()) TypeDependent = true; @@ -1151,7 +1150,7 @@ Sema::OwningExprResult Sema::ActOnPredefinedExpr(SourceLocation Loc, // Pre-defined identifiers are of type char[x], where x is the length of the // string. - + Decl *currentDecl = getCurFunctionOrMethodDecl(); if (!currentDecl) { Diag(Loc, diag::ext_predef_outside_function); @@ -1203,7 +1202,7 @@ Action::OwningExprResult Sema::ActOnNumericConstant(const Token &Tok) { // Get the spelling of the token, which eliminates trigraphs, etc. unsigned ActualLength = PP.getSpelling(Tok, ThisTokBegin); - NumericLiteralParser Literal(ThisTokBegin, ThisTokBegin+ActualLength, + NumericLiteralParser Literal(ThisTokBegin, ThisTokBegin+ActualLength, Tok.getLocation(), PP); if (Literal.hadError) return ExprError(); @@ -1316,7 +1315,7 @@ Action::OwningExprResult Sema::ActOnNumericConstant(const Token &Tok) { // If this is an imaginary literal, create the ImaginaryLiteral wrapper. if (Literal.isImaginary) - Res = new (Context) ImaginaryLiteral(Res, + Res = new (Context) ImaginaryLiteral(Res, Context.getComplexType(Res->getType())); return Owned(Res); @@ -1345,27 +1344,27 @@ bool Sema::CheckSizeOfAlignOfOperand(QualType exprType, Diag(OpLoc, diag::ext_sizeof_function_type) << ExprRange; return false; } - + // Allow sizeof(void)/alignof(void) as an extension. if (exprType->isVoidType()) { Diag(OpLoc, diag::ext_sizeof_void_type) << (isSizeof ? "sizeof" : "__alignof") << ExprRange; return false; } - + if (RequireCompleteType(OpLoc, exprType, - isSizeof ? diag::err_sizeof_incomplete_type : + isSizeof ? diag::err_sizeof_incomplete_type : PDiag(diag::err_alignof_incomplete_type) << ExprRange)) return true; - + // Reject sizeof(interface) and sizeof(interface<proto>) in 64-bit mode. if (LangOpts.ObjCNonFragileABI && exprType->isObjCInterfaceType()) { Diag(OpLoc, diag::err_sizeof_nonfragile_interface) << exprType << isSizeof << ExprRange; return true; } - + return false; } @@ -1373,7 +1372,7 @@ bool Sema::CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &ExprRange) { E = E->IgnoreParens(); - // alignof decl is always ok. + // alignof decl is always ok. if (isa<DeclRefExpr>(E)) return false; @@ -1396,8 +1395,8 @@ bool Sema::CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, } /// \brief Build a sizeof or alignof expression given a type operand. -Action::OwningExprResult -Sema::CreateSizeOfAlignOfExpr(QualType T, SourceLocation OpLoc, +Action::OwningExprResult +Sema::CreateSizeOfAlignOfExpr(QualType T, SourceLocation OpLoc, bool isSizeOf, SourceRange R) { if (T.isNull()) return ExprError(); @@ -1414,8 +1413,8 @@ Sema::CreateSizeOfAlignOfExpr(QualType T, SourceLocation OpLoc, /// \brief Build a sizeof or alignof expression given an expression /// operand. -Action::OwningExprResult -Sema::CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc, +Action::OwningExprResult +Sema::CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc, bool isSizeOf, SourceRange R) { // Verify that the operand is valid. bool isInvalid = false; @@ -1452,7 +1451,7 @@ Sema::ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType, // FIXME: Preserve type source info. QualType ArgTy = GetTypeFromParser(TyOrEx); return CreateSizeOfAlignOfExpr(ArgTy, OpLoc, isSizeof, ArgRange); - } + } // Get the end location. Expr *ArgEx = (Expr *)TyOrEx; @@ -1468,15 +1467,15 @@ Sema::ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType, QualType Sema::CheckRealImagOperand(Expr *&V, SourceLocation Loc, bool isReal) { if (V->isTypeDependent()) return Context.DependentTy; - + // These operators return the element type of a complex type. if (const ComplexType *CT = V->getType()->getAsComplexType()) return CT->getElementType(); - + // Otherwise they pass through real integer and floating point types here. if (V->getType()->isArithmeticType()) return V->getType(); - + // Reject anything else. Diag(Loc, diag::err_realimag_invalid_type) << V->getType() << (isReal ? "__real" : "__imag"); @@ -1514,9 +1513,9 @@ Sema::ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, // for objects of that type. When the postfix increment is // called as a result of using the ++ operator, the int // argument will have value zero. - Expr *Args[2] = { - Arg, - new (Context) IntegerLiteral(llvm::APInt(Context.Target.getIntWidth(), 0, + Expr *Args[2] = { + Arg, + new (Context) IntegerLiteral(llvm::APInt(Context.Target.getIntWidth(), 0, /*isSigned=*/true), Context.IntTy, SourceLocation()) }; @@ -1560,7 +1559,7 @@ Sema::ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, Input.release(); Args[0] = Arg; return Owned(new (Context) CXXOperatorCallExpr(Context, OverOp, FnExpr, - Args, 2, ResultTy, + Args, 2, ResultTy, OpLoc)); } else { // We matched a built-in operator. Convert the arguments, then @@ -1613,7 +1612,7 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, Expr *LHSExp = static_cast<Expr*>(Base.get()), *RHSExp = static_cast<Expr*>(Idx.get()); - + if (getLangOptions().CPlusPlus && (LHSExp->isTypeDependent() || RHSExp->isTypeDependent())) { Base.release(); @@ -1622,12 +1621,12 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, Context.DependentTy, RLoc)); } - if (getLangOptions().CPlusPlus && + if (getLangOptions().CPlusPlus && (LHSExp->getType()->isRecordType() || LHSExp->getType()->isEnumeralType() || RHSExp->getType()->isRecordType() || RHSExp->getType()->isEnumeralType())) { - // Add the appropriate overloaded operators (C++ [over.match.oper]) + // Add the appropriate overloaded operators (C++ [over.match.oper]) // to the candidate set. OverloadCandidateSet CandidateSet; Expr *Args[2] = { LHSExp, RHSExp }; @@ -1648,7 +1647,7 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, // Convert the arguments. if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FnDecl)) { if (PerformObjectArgumentInitialization(LHSExp, Method) || - PerformCopyInitialization(RHSExp, + PerformCopyInitialization(RHSExp, FnDecl->getParamDecl(0)->getType(), "passing")) return ExprError(); @@ -1678,7 +1677,7 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, Args[0] = LHSExp; Args[1] = RHSExp; return Owned(new (Context) CXXOperatorCallExpr(Context, OO_Subscript, - FnExpr, Args, 2, + FnExpr, Args, 2, ResultTy, LLoc)); } else { // We matched a built-in operator. Convert the arguments, then @@ -1745,12 +1744,12 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, BaseExpr = RHSExp; IndexExpr = LHSExp; ResultType = PTy->getPointeeType(); - } else if (const ObjCObjectPointerType *PTy = + } else if (const ObjCObjectPointerType *PTy = LHSTy->getAsObjCObjectPointerType()) { BaseExpr = LHSExp; IndexExpr = RHSExp; ResultType = PTy->getPointeeType(); - } else if (const ObjCObjectPointerType *PTy = + } else if (const ObjCObjectPointerType *PTy = RHSTy->getAsObjCObjectPointerType()) { // Handle the uncommon case of "123[Ptr]". BaseExpr = RHSExp; @@ -1797,28 +1796,28 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, << IndexExpr->getSourceRange()); // C99 6.5.2.1p1: "shall have type "pointer to *object* type". Similarly, - // C++ [expr.sub]p1: The type "T" shall be a completely-defined object - // type. Note that Functions are not objects, and that (in C99 parlance) + // C++ [expr.sub]p1: The type "T" shall be a completely-defined object + // type. Note that Functions are not objects, and that (in C99 parlance) // incomplete types are not object types. if (ResultType->isFunctionType()) { Diag(BaseExpr->getLocStart(), diag::err_subscript_function_type) << ResultType << BaseExpr->getSourceRange(); return ExprError(); } - + if (!ResultType->isDependentType() && - RequireCompleteType(LLoc, ResultType, + RequireCompleteType(LLoc, ResultType, PDiag(diag::err_subscript_incomplete_type) << BaseExpr->getSourceRange())) return ExprError(); - + // Diagnose bad cases where we step over interface counts. if (ResultType->isObjCInterfaceType() && LangOpts.ObjCNonFragileABI) { Diag(LLoc, diag::err_subscript_nonfragile_interface) << ResultType << BaseExpr->getSourceRange(); return ExprError(); } - + Base.release(); Idx.release(); return Owned(new (Context) ArraySubscriptExpr(LHSExp, RHSExp, @@ -1827,7 +1826,7 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, QualType Sema:: CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc, - const IdentifierInfo *CompName, + const IdentifierInfo *CompName, SourceLocation CompLoc) { const ExtVectorType *vecType = baseType->getAsExtVectorType(); @@ -1918,15 +1917,15 @@ static Decl *FindGetterNameDeclFromProtocolList(const ObjCProtocolDecl*PDecl, IdentifierInfo *Member, const Selector &Sel, ASTContext &Context) { - + if (ObjCPropertyDecl *PD = PDecl->FindPropertyDeclaration(Member)) return PD; if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Sel)) return OMD; - + for (ObjCProtocolDecl::protocol_iterator I = PDecl->protocol_begin(), E = PDecl->protocol_end(); I != E; ++I) { - if (Decl *D = FindGetterNameDeclFromProtocolList(*I, Member, Sel, + if (Decl *D = FindGetterNameDeclFromProtocolList(*I, Member, Sel, Context)) return D; } @@ -1972,16 +1971,16 @@ ObjCMethodDecl *Sema::FindMethodInNestedImplementations( ObjCMethodDecl *Method = 0; if (ObjCImplementationDecl *ImpDecl = IFace->getImplementation()) Method = ImpDecl->getInstanceMethod(Sel); - + if (!Method && IFace->getSuperClass()) return FindMethodInNestedImplementations(IFace->getSuperClass(), Sel); return Method; } - -Action::OwningExprResult + +Action::OwningExprResult Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, tok::TokenKind OpKind, SourceLocation MemberLoc, - DeclarationName MemberName, + DeclarationName MemberName, bool HasExplicitTemplateArgs, SourceLocation LAngleLoc, const TemplateArgument *ExplicitTemplateArgs, @@ -1997,7 +1996,7 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, Expr *BaseExpr = Base.takeAs<Expr>(); assert(BaseExpr && "no base expression"); - + // Perform default conversions. DefaultFunctionArrayConversion(BaseExpr); @@ -2028,8 +2027,8 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, if (!FirstQualifierInScope) FirstQualifierInScope = FindFirstQualifierInScope(S, Qualifier); } - - return Owned(CXXUnresolvedMemberExpr::Create(Context, BaseExpr, true, + + return Owned(CXXUnresolvedMemberExpr::Create(Context, BaseExpr, true, OpLoc, Qualifier, SS? SS->getRange() : SourceRange(), FirstQualifierInScope, @@ -2051,17 +2050,17 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, << BaseType << BaseExpr->getSourceRange()); } else { if (BaseType->isDependentType()) { - // Require that the base type isn't a pointer type + // Require that the base type isn't a pointer type // (so we'll report an error for) // T* t; // t.f; - // + // // In Obj-C++, however, the above expression is valid, since it could be // accessing the 'f' property if T is an Obj-C interface. The extra check // allows this, while still reporting an error if T is a struct pointer. const PointerType *PT = BaseType->getAs<PointerType>(); - if (!PT || (getLangOptions().ObjC1 && + if (!PT || (getLangOptions().ObjC1 && !PT->getPointeeType()->isRecordType())) { NestedNameSpecifier *Qualifier = 0; if (SS) { @@ -2069,10 +2068,10 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, if (!FirstQualifierInScope) FirstQualifierInScope = FindFirstQualifierInScope(S, Qualifier); } - + return Owned(CXXUnresolvedMemberExpr::Create(Context, - BaseExpr, false, - OpLoc, + BaseExpr, false, + OpLoc, Qualifier, SS? SS->getRange() : SourceRange(), FirstQualifierInScope, @@ -2101,8 +2100,8 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, // If the member name was a qualified-id, look into the // nested-name-specifier. DC = computeDeclContext(*SS, false); - - // FIXME: If DC is not computable, we should build a + + // FIXME: If DC is not computable, we should build a // CXXUnresolvedMemberExpr. assert(DC && "Cannot handle non-computable dependent contexts in lookup"); } @@ -2119,22 +2118,22 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, BaseExpr->getSourceRange()); return ExprError(); } - + if (SS && SS->isSet()) { - QualType BaseTypeCanon + QualType BaseTypeCanon = Context.getCanonicalType(BaseType).getUnqualifiedType(); - QualType MemberTypeCanon + QualType MemberTypeCanon = Context.getCanonicalType( Context.getTypeDeclType( dyn_cast<TypeDecl>(Result.getAsDecl()->getDeclContext()))); - + if (BaseTypeCanon != MemberTypeCanon && !IsDerivedFrom(BaseTypeCanon, MemberTypeCanon)) return ExprError(Diag(SS->getBeginLoc(), diag::err_not_direct_base_or_virtual) << MemberTypeCanon << BaseTypeCanon); } - + NamedDecl *MemberDecl = Result; // If the decl being referenced had an error, return an error for this @@ -2172,10 +2171,10 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, MarkDeclarationReferenced(MemberLoc, FD); if (PerformObjectMemberConversion(BaseExpr, FD)) return ExprError(); - return Owned(BuildMemberExpr(Context, BaseExpr, OpKind == tok::arrow, SS, + return Owned(BuildMemberExpr(Context, BaseExpr, OpKind == tok::arrow, SS, FD, MemberLoc, MemberType)); } - + if (VarDecl *Var = dyn_cast<VarDecl>(MemberDecl)) { MarkDeclarationReferenced(MemberLoc, MemberDecl); return Owned(BuildMemberExpr(Context, BaseExpr, OpKind == tok::arrow, SS, @@ -2188,19 +2187,19 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, MemberFn, MemberLoc, MemberFn->getType())); } - if (FunctionTemplateDecl *FunTmpl + if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(MemberDecl)) { MarkDeclarationReferenced(MemberLoc, MemberDecl); - + if (HasExplicitTemplateArgs) - return Owned(MemberExpr::Create(Context, BaseExpr, OpKind == tok::arrow, - (NestedNameSpecifier *)(SS? SS->getScopeRep() : 0), + return Owned(MemberExpr::Create(Context, BaseExpr, OpKind == tok::arrow, + (NestedNameSpecifier *)(SS? SS->getScopeRep() : 0), SS? SS->getRange() : SourceRange(), - FunTmpl, MemberLoc, true, - LAngleLoc, ExplicitTemplateArgs, - NumExplicitTemplateArgs, RAngleLoc, + FunTmpl, MemberLoc, true, + LAngleLoc, ExplicitTemplateArgs, + NumExplicitTemplateArgs, RAngleLoc, Context.OverloadTy)); - + return Owned(BuildMemberExpr(Context, BaseExpr, OpKind == tok::arrow, SS, FunTmpl, MemberLoc, Context.OverloadTy)); @@ -2208,12 +2207,12 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(MemberDecl)) { if (HasExplicitTemplateArgs) - return Owned(MemberExpr::Create(Context, BaseExpr, OpKind == tok::arrow, - (NestedNameSpecifier *)(SS? SS->getScopeRep() : 0), + return Owned(MemberExpr::Create(Context, BaseExpr, OpKind == tok::arrow, + (NestedNameSpecifier *)(SS? SS->getScopeRep() : 0), SS? SS->getRange() : SourceRange(), - Ovl, MemberLoc, true, - LAngleLoc, ExplicitTemplateArgs, - NumExplicitTemplateArgs, RAngleLoc, + Ovl, MemberLoc, true, + LAngleLoc, ExplicitTemplateArgs, + NumExplicitTemplateArgs, RAngleLoc, Context.OverloadTy)); return Owned(BuildMemberExpr(Context, BaseExpr, OpKind == tok::arrow, SS, @@ -2241,13 +2240,13 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, // pseudo-destructor. if (MemberName.getNameKind() == DeclarationName::CXXDestructorName) { // C++ [expr.pseudo]p2: - // The left hand side of the dot operator shall be of scalar type. The - // left hand side of the arrow operator shall be of pointer to scalar + // The left hand side of the dot operator shall be of scalar type. The + // left hand side of the arrow operator shall be of pointer to scalar // type. if (!BaseType->isScalarType()) return Owned(Diag(OpLoc, diag::err_pseudo_dtor_base_not_scalar) << BaseType << BaseExpr->getSourceRange()); - + // [...] The type designated by the pseudo-destructor-name shall be the // same as the object type. if (!MemberName.getCXXNameType()->isDependentType() && @@ -2255,28 +2254,28 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, return Owned(Diag(OpLoc, diag::err_pseudo_dtor_type_mismatch) << BaseType << MemberName.getCXXNameType() << BaseExpr->getSourceRange() << SourceRange(MemberLoc)); - - // [...] Furthermore, the two type-names in a pseudo-destructor-name of + + // [...] Furthermore, the two type-names in a pseudo-destructor-name of // the form // - // ::[opt] nested-name-specifier[opt] type-name :: ̃ type-name - // + // ::[opt] nested-name-specifier[opt] type-name :: ̃ type-name + // // shall designate the same scalar type. // // FIXME: DPG can't see any way to trigger this particular clause, so it // isn't checked here. - + // FIXME: We've lost the precise spelling of the type by going through // DeclarationName. Can we do better? return Owned(new (Context) CXXPseudoDestructorExpr(Context, BaseExpr, - OpKind == tok::arrow, + OpKind == tok::arrow, OpLoc, - (NestedNameSpecifier *)(SS? SS->getScopeRep() : 0), + (NestedNameSpecifier *)(SS? SS->getScopeRep() : 0), SS? SS->getRange() : SourceRange(), MemberName.getCXXNameType(), MemberLoc)); } - + // Handle properties on ObjC 'Class' types. if (OpKind == tok::period && BaseType->isObjCClassType()) { // Also must look for a getter name which uses property syntax. @@ -2293,8 +2292,8 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, } // If we found a getter then this may be a valid dot-reference, we // will look for the matching setter, in case it is needed. - Selector SetterSel = - SelectorTable::constructSetterName(PP.getIdentifierTable(), + Selector SetterSel = + SelectorTable::constructSetterName(PP.getIdentifierTable(), PP.getSelectorTable(), Member); ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel); if (!Setter) { @@ -2330,7 +2329,7 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, if ((OpKind == tok::arrow && BaseType->isObjCObjectPointerType()) || (OpKind == tok::period && BaseType->isObjCInterfaceType())) { const ObjCObjectPointerType *OPT = BaseType->getAsObjCObjectPointerType(); - const ObjCInterfaceType *IFaceT = + const ObjCInterfaceType *IFaceT = OPT ? OPT->getInterfaceType() : BaseType->getAsObjCInterfaceType(); if (IFaceT) { IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); @@ -2338,7 +2337,7 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, ObjCInterfaceDecl *IDecl = IFaceT->getDecl(); ObjCInterfaceDecl *ClassDeclared; ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared); - + if (IV) { // If the decl being referenced had an error, return an error for this // sub-expr without emitting another error, in order to avoid cascading @@ -2362,22 +2361,22 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, // need be passed down in the AST node and somehow calculated from the // AST for a function decl. Decl *ImplDecl = ObjCImpDecl.getAs<Decl>(); - if (ObjCImplementationDecl *IMPD = + if (ObjCImplementationDecl *IMPD = dyn_cast<ObjCImplementationDecl>(ImplDecl)) ClassOfMethodDecl = IMPD->getClassInterface(); else if (ObjCCategoryImplDecl* CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ImplDecl)) ClassOfMethodDecl = CatImplClass->getClassInterface(); } - - if (IV->getAccessControl() == ObjCIvarDecl::Private) { - if (ClassDeclared != IDecl || + + if (IV->getAccessControl() == ObjCIvarDecl::Private) { + if (ClassDeclared != IDecl || ClassOfMethodDecl != ClassDeclared) - Diag(MemberLoc, diag::error_private_ivar_access) + Diag(MemberLoc, diag::error_private_ivar_access) << IV->getDeclName(); } else if (!IDecl->isSuperClassOf(ClassOfMethodDecl)) // @protected - Diag(MemberLoc, diag::error_protected_ivar_access) + Diag(MemberLoc, diag::error_protected_ivar_access) << IV->getDeclName(); } @@ -2391,11 +2390,11 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, } } // Handle properties on 'id' and qualified "id". - if (OpKind == tok::period && (BaseType->isObjCIdType() || + if (OpKind == tok::period && (BaseType->isObjCIdType() || BaseType->isObjCQualifiedIdType())) { const ObjCObjectPointerType *QIdTy = BaseType->getAsObjCObjectPointerType(); IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); - + // Check protocols on qualified interfaces. Selector Sel = PP.getSelectorTable().getNullarySelector(Member); if (Decl *PMDecl = FindGetterNameDecl(QIdTy, Member, Sel, Context)) { @@ -2403,7 +2402,7 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, // Check the use of this declaration if (DiagnoseUseOfDecl(PD, MemberLoc)) return ExprError(); - + return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(), MemberLoc, BaseExpr)); } @@ -2411,10 +2410,10 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, // Check the use of this method. if (DiagnoseUseOfDecl(OMD, MemberLoc)) return ExprError(); - + return Owned(new (Context) ObjCMessageExpr(BaseExpr, Sel, - OMD->getResultType(), - OMD, OpLoc, MemberLoc, + OMD->getResultType(), + OMD, OpLoc, MemberLoc, NULL, 0)); } } @@ -2425,12 +2424,12 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, // Handle Objective-C property access, which is "Obj.property" where Obj is a // pointer to a (potentially qualified) interface type. const ObjCObjectPointerType *OPT; - if (OpKind == tok::period && + if (OpKind == tok::period && (OPT = BaseType->getAsObjCInterfacePointerType())) { const ObjCInterfaceType *IFaceT = OPT->getInterfaceType(); ObjCInterfaceDecl *IFace = IFaceT->getDecl(); IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); - + // Search for a declared property first. if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(Member)) { // Check whether we can reference this property. @@ -2488,8 +2487,8 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, } // If we found a getter then this may be a valid dot-reference, we // will look for the matching setter, in case it is needed. - Selector SetterSel = - SelectorTable::constructSetterName(PP.getIdentifierTable(), + Selector SetterSel = + SelectorTable::constructSetterName(PP.getIdentifierTable(), PP.getSelectorTable(), Member); ObjCMethodDecl *Setter = IFace->lookupInstanceMethod(SetterSel); if (!Setter) { @@ -2519,9 +2518,9 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, return ExprError(Diag(MemberLoc, diag::err_property_not_found) << MemberName << BaseType); } - + // Handle the following exceptional case (*Obj).isa. - if (OpKind == tok::period && + if (OpKind == tok::period && BaseType->isSpecificBuiltinType(BuiltinType::ObjCId) && MemberName.getAsIdentifierInfo()->isStr("isa")) return Owned(new (Context) ObjCIsaExpr(BaseExpr, false, MemberLoc, @@ -2543,9 +2542,9 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, // If the user is trying to apply -> or . to a function or function // pointer, it's probably because they forgot parentheses to call // the function. Suggest the addition of those parentheses. - if (BaseType == Context.OverloadTy || + if (BaseType == Context.OverloadTy || BaseType->isFunctionType() || - (BaseType->isPointerType() && + (BaseType->isPointerType() && BaseType->getAs<PointerType>()->isFunctionType())) { SourceLocation Loc = PP.getLocForEndOfToken(BaseExpr->getLocEnd()); Diag(Loc, diag::note_member_reference_needs_call) @@ -2560,7 +2559,7 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, tok::TokenKind OpKind, SourceLocation MemberLoc, IdentifierInfo &Member, DeclPtrTy ObjCImpDecl, const CXXScopeSpec *SS) { - return BuildMemberReferenceExpr(S, move(Base), OpLoc, OpKind, MemberLoc, + return BuildMemberReferenceExpr(S, move(Base), OpLoc, OpKind, MemberLoc, DeclarationName(&Member), ObjCImpDecl, SS); } @@ -2571,7 +2570,7 @@ Sema::OwningExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc, Diag (CallLoc, diag::err_use_of_default_argument_to_function_declared_later) << FD << cast<CXXRecordDecl>(FD->getDeclContext())->getDeclName(); - Diag(UnparsedDefaultArgLocs[Param], + Diag(UnparsedDefaultArgLocs[Param], diag::note_default_argument_declared_here); } else { if (Param->hasUninstantiatedDefaultArg()) { @@ -2580,28 +2579,28 @@ Sema::OwningExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc, // Instantiate the expression. MultiLevelTemplateArgumentList ArgList = getTemplateInstantiationArgs(FD); - InstantiatingTemplate Inst(*this, CallLoc, Param, - ArgList.getInnermost().getFlatArgumentList(), + InstantiatingTemplate Inst(*this, CallLoc, Param, + ArgList.getInnermost().getFlatArgumentList(), ArgList.getInnermost().flat_size()); OwningExprResult Result = SubstExpr(UninstExpr, ArgList); - if (Result.isInvalid()) + if (Result.isInvalid()) return ExprError(); - - if (SetParamDefaultArgument(Param, move(Result), + + if (SetParamDefaultArgument(Param, move(Result), /*FIXME:EqualLoc*/ UninstExpr->getSourceRange().getBegin())) return ExprError(); } - + Expr *DefaultExpr = Param->getDefaultArg(); - + // If the default expression creates temporaries, we need to // push them to the current stack of expression temporaries so they'll // be properly destroyed. - if (CXXExprWithTemporaries *E + if (CXXExprWithTemporaries *E = dyn_cast_or_null<CXXExprWithTemporaries>(DefaultExpr)) { - assert(!E->shouldDestroyTemporaries() && + assert(!E->shouldDestroyTemporaries() && "Can't destroy temporaries in a default argument expr!"); for (unsigned I = 0, N = E->getNumTemporaries(); I != N; ++I) ExprTemporaries.push_back(E->getTemporary(I)); @@ -2676,16 +2675,16 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, return true; } else { ParmVarDecl *Param = FDecl->getParamDecl(i); - - OwningExprResult ArgExpr = + + OwningExprResult ArgExpr = BuildCXXDefaultArgExpr(Call->getSourceRange().getBegin(), FDecl, Param); if (ArgExpr.isInvalid()) return true; - + Arg = ArgExpr.takeAs<Expr>(); } - + Call->setArg(i, Arg); } @@ -2719,14 +2718,14 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, // Since this might be a postfix expression, get rid of ParenListExprs. fn = MaybeConvertParenListExprToParenExpr(S, move(fn)); - + Expr *Fn = fn.takeAs<Expr>(); Expr **Args = reinterpret_cast<Expr**>(args.release()); assert(Fn && "no function call expression"); FunctionDecl *FDecl = NULL; NamedDecl *NDecl = NULL; DeclarationName UnqualifiedName; - + if (getLangOptions().CPlusPlus) { // If this is a pseudo-destructor expression, build the call immediately. if (isa<CXXPseudoDestructorExpr>(Fn)) { @@ -2736,17 +2735,17 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, << CodeModificationHint::CreateRemoval( SourceRange(Args[0]->getLocStart(), Args[NumArgs-1]->getLocEnd())); - + for (unsigned I = 0; I != NumArgs; ++I) Args[I]->Destroy(Context); - + NumArgs = 0; } - + return Owned(new (Context) CallExpr(Context, Fn, 0, 0, Context.VoidTy, RParenLoc)); } - + // Determine whether this is a dependent call inside a C++ template, // in which case we won't do any semantic analysis now. // FIXME: Will need to cache the results of name lookup (including ADL) in @@ -2780,7 +2779,7 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, } // If we're directly calling a function, get the appropriate declaration. - // Also, in C++, keep track of whether we should perform argument-dependent + // Also, in C++, keep track of whether we should perform argument-dependent // lookup and whether there were any explicitly-specified template arguments. Expr *FnExpr = Fn; bool ADL = true; @@ -2808,7 +2807,7 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, = dyn_cast<UnresolvedFunctionNameExpr>(FnExpr)) { UnqualifiedName = DepName->getName(); break; - } else if (TemplateIdRefExpr *TemplateIdRef + } else if (TemplateIdRefExpr *TemplateIdRef = dyn_cast<TemplateIdRefExpr>(FnExpr)) { NDecl = TemplateIdRef->getTemplateName().getAsTemplateDecl(); if (!NDecl) @@ -2816,17 +2815,17 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, HasExplicitTemplateArgs = true; ExplicitTemplateArgs = TemplateIdRef->getTemplateArgs(); NumExplicitTemplateArgs = TemplateIdRef->getNumTemplateArgs(); - + // C++ [temp.arg.explicit]p6: // [Note: For simple function names, argument dependent lookup (3.4.2) - // applies even when the function name is not visible within the + // applies even when the function name is not visible within the // scope of the call. This is because the call still has the syntactic // form of a function call (3.4.1). But when a function template with // explicit template arguments is used, the call does not have the - // correct syntactic form unless there is a function template with - // that name visible at the point of the call. If no such name is - // visible, the call is not syntactically well-formed and - // argument-dependent lookup does not apply. If some such name is + // correct syntactic form unless there is a function template with + // that name visible at the point of the call. If no such name is + // visible, the call is not syntactically well-formed and + // argument-dependent lookup does not apply. If some such name is // visible, argument dependent lookup applies and additional function // templates may be found in other namespaces. // @@ -2855,7 +2854,7 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, Ovl = dyn_cast<OverloadedFunctionDecl>(NDecl); } - if (Ovl || FunctionTemplate || + if (Ovl || FunctionTemplate || (getLangOptions().CPlusPlus && (FDecl || UnqualifiedName))) { // We don't perform ADL for implicit declarations of builtins. if (FDecl && FDecl->getBuiltinID(Context) && FDecl->isImplicit()) @@ -2866,11 +2865,11 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, ADL = false; if (Ovl || FunctionTemplate || ADL) { - FDecl = ResolveOverloadedCallFn(Fn, NDecl, UnqualifiedName, + FDecl = ResolveOverloadedCallFn(Fn, NDecl, UnqualifiedName, HasExplicitTemplateArgs, ExplicitTemplateArgs, NumExplicitTemplateArgs, - LParenLoc, Args, NumArgs, CommaLocs, + LParenLoc, Args, NumArgs, CommaLocs, RParenLoc, ADL); if (!FDecl) return ExprError(); @@ -2972,13 +2971,13 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, // Check for sentinels if (NDecl) DiagnoseSentinelCalls(NDecl, LParenLoc, Args, NumArgs); - + // Do special checking on direct calls to functions. if (FDecl) { if (CheckFunctionCall(FDecl, TheCall.get())) return ExprError(); - - if (unsigned BuiltinID = FDecl->getBuiltinID(Context)) + + if (unsigned BuiltinID = FDecl->getBuiltinID(Context)) return CheckBuiltinFunctionCall(BuiltinID, TheCall.take()); } else if (NDecl) { if (CheckBlockCall(NDecl, TheCall.get())) @@ -3005,7 +3004,7 @@ Sema::ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, } else if (!literalType->isDependentType() && RequireCompleteType(LParenLoc, literalType, PDiag(diag::err_typecheck_decl_incomplete_type) - << SourceRange(LParenLoc, + << SourceRange(LParenLoc, literalExpr->getSourceRange().getEnd()))) return ExprError(); @@ -3040,7 +3039,7 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg initlist, /// CheckCastTypes - Check type constraints for casting between types. bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr, - CastExpr::CastKind& Kind, + CastExpr::CastKind& Kind, CXXMethodDecl *& ConversionDecl, bool FunctionalStyle) { if (getLangOptions().CPlusPlus) @@ -3137,7 +3136,7 @@ bool Sema::CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty) { bool Sema::CheckExtVectorCast(SourceRange R, QualType DestTy, QualType SrcTy) { assert(DestTy->isExtVectorType() && "Not an extended vector type!"); - + // If SrcTy is a VectorType, the total size must match to explicitly cast to // an ExtVectorType. if (SrcTy->isVectorType()) { @@ -3161,27 +3160,27 @@ Action::OwningExprResult Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc, TypeTy *Ty, SourceLocation RParenLoc, ExprArg Op) { CastExpr::CastKind Kind = CastExpr::CK_Unknown; - + assert((Ty != 0) && (Op.get() != 0) && "ActOnCastExpr(): missing type or expr"); Expr *castExpr = (Expr *)Op.get(); //FIXME: Preserve type source info. QualType castType = GetTypeFromParser(Ty); - + // If the Expr being casted is a ParenListExpr, handle it specially. if (isa<ParenListExpr>(castExpr)) return ActOnCastOfParenListExpr(S, LParenLoc, RParenLoc, move(Op),castType); CXXMethodDecl *ConversionDecl = 0; - if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), castType, castExpr, + if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), castType, castExpr, Kind, ConversionDecl)) return ExprError(); if (ConversionDecl) { // encounterred a c-style cast requiring a conversion function. if (CXXConversionDecl *CD = dyn_cast<CXXConversionDecl>(ConversionDecl)) { - castExpr = + castExpr = new (Context) CXXFunctionalCastExpr(castType.getNonReferenceType(), - castType, LParenLoc, + castType, LParenLoc, CastExpr::CK_UserDefinedConversion, castExpr, CD, RParenLoc); @@ -3189,10 +3188,10 @@ Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc, TypeTy *Ty, } // FIXME. AST for when dealing with conversion functions (FunctionDecl). } - + Op.release(); return Owned(new (Context) CStyleCastExpr(castType.getNonReferenceType(), - Kind, castExpr, castType, + Kind, castExpr, castType, LParenLoc, RParenLoc)); } @@ -3204,13 +3203,13 @@ Sema::MaybeConvertParenListExprToParenExpr(Scope *S, ExprArg EA) { ParenListExpr *E = dyn_cast<ParenListExpr>(expr); if (!E) return Owned(expr); - + OwningExprResult Result(*this, E->getExpr(0)); - + for (unsigned i = 1, e = E->getNumExprs(); i != e && !Result.isInvalid(); ++i) Result = ActOnBinOp(S, E->getExprLoc(), tok::comma, move(Result), Owned(E->getExpr(i))); - + return ActOnParenExpr(E->getLParenLoc(), E->getRParenLoc(), move(Result)); } @@ -3219,8 +3218,8 @@ Sema::ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc, SourceLocation RParenLoc, ExprArg Op, QualType Ty) { ParenListExpr *PE = (ParenListExpr *)Op.get(); - - // If this is an altivec initializer, '(' type ')' '(' init, ..., init ')' + + // If this is an altivec initializer, '(' type ')' '(' init, ..., init ')' // then handle it as such. if (getLangOptions().AltiVec && Ty->isVectorType()) { if (PE->getNumExprs() == 0) { @@ -3235,13 +3234,13 @@ Sema::ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc, // FIXME: This means that pretty-printing the final AST will produce curly // braces instead of the original commas. Op.release(); - InitListExpr *E = new (Context) InitListExpr(LParenLoc, &initExprs[0], + InitListExpr *E = new (Context) InitListExpr(LParenLoc, &initExprs[0], initExprs.size(), RParenLoc); E->setType(Ty); - return ActOnCompoundLiteral(LParenLoc, Ty.getAsOpaquePtr(), RParenLoc, + return ActOnCompoundLiteral(LParenLoc, Ty.getAsOpaquePtr(), RParenLoc, Owned(E)); } else { - // This is not an AltiVec-style cast, so turn the ParenListExpr into a + // This is not an AltiVec-style cast, so turn the ParenListExpr into a // sequence of BinOp comma operators. Op = MaybeConvertParenListExprToParenExpr(S, move(Op)); return ActOnCastExpr(S, LParenLoc, Ty.getAsOpaquePtr(), RParenLoc,move(Op)); @@ -3357,7 +3356,7 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, if (!LHSTy->isBlockPointerType() || !RHSTy->isBlockPointerType()) { if (LHSTy->isVoidPointerType() || RHSTy->isVoidPointerType()) { QualType destType = Context.getPointerType(Context.VoidTy); - ImpCastExprToType(LHS, destType); + ImpCastExprToType(LHS, destType); ImpCastExprToType(RHS, destType); return destType; } @@ -3393,7 +3392,7 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, } // Check constraints for Objective-C object pointers types. if (LHSTy->isObjCObjectPointerType() && RHSTy->isObjCObjectPointerType()) { - + if (Context.getCanonicalType(LHSTy) == Context.getCanonicalType(RHSTy)) { // Two identical object pointer types are always compatible. return LHSTy; @@ -3401,7 +3400,7 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, const ObjCObjectPointerType *LHSOPT = LHSTy->getAsObjCObjectPointerType(); const ObjCObjectPointerType *RHSOPT = RHSTy->getAsObjCObjectPointerType(); QualType compositeType = LHSTy; - + // If both operands are interfaces and either operand can be // assigned to the other, use that type as the composite // type. This allows @@ -3419,10 +3418,10 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, compositeType = RHSOPT->isObjCBuiltinType() ? RHSTy : LHSTy; } else if (Context.canAssignObjCInterfaces(RHSOPT, LHSOPT)) { compositeType = LHSOPT->isObjCBuiltinType() ? LHSTy : RHSTy; - } else if ((LHSTy->isObjCQualifiedIdType() || + } else if ((LHSTy->isObjCQualifiedIdType() || RHSTy->isObjCQualifiedIdType()) && Context.ObjCQualifiedIdTypesAreCompatible(LHSTy, RHSTy, true)) { - // Need to handle "id<xx>" explicitly. + // Need to handle "id<xx>" explicitly. // GCC allows qualified id and any Objective-C type to devolve to // id. Currently localizing to here until clear this should be // part of ObjCQualifiedIdTypesAreCompatible. @@ -3512,7 +3511,7 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, ImpCastExprToType(RHS, LHSTy); return LHSTy; } - + // GCC compatibility: soften pointer/integer mismatch. if (RHSTy->isPointerType() && LHSTy->isIntegerType()) { Diag(QuestionLoc, diag::warn_typecheck_cond_pointer_integer_mismatch) @@ -3641,7 +3640,7 @@ Sema::CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType) { return IncompatiblePointerSign; } // General pointer incompatibility takes priority over qualifiers. - return IncompatiblePointer; + return IncompatiblePointer; } return ConvTy; } @@ -3727,7 +3726,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (!rhsType->isVectorType() && rhsType->isArithmeticType()) return Compatible; } - + if (lhsType->isVectorType() || rhsType->isVectorType()) { // If we are allowing lax vector conversions, and LHS and RHS are both // vectors, the total size only needs to be the same. This is a bitcast; @@ -3788,7 +3787,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (isa<ObjCObjectPointerType>(lhsType)) { if (rhsType->isIntegerType()) return IntToPointer; - + // In general, C pointers are not compatible with ObjC object pointers. if (isa<PointerType>(rhsType)) { if (rhsType->isVoidPointerType()) // an exception to the rule. @@ -3858,7 +3857,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { /// \brief Constructs a transparent union from an expression that is /// used to initialize the transparent union. -static void ConstructTransparentUnion(ASTContext &C, Expr *&E, +static void ConstructTransparentUnion(ASTContext &C, Expr *&E, QualType UnionType, FieldDecl *Field) { // Build an initializer list that designates the appropriate member // of the transparent union. @@ -3878,7 +3877,7 @@ Sema::AssignConvertType Sema::CheckTransparentUnionArgumentConstraints(QualType ArgType, Expr *&rExpr) { QualType FromType = rExpr->getType(); - // If the ArgType is a Union type, we want to handle a potential + // If the ArgType is a Union type, we want to handle a potential // transparent_union GCC extension. const RecordType *UT = ArgType->getAsUnionType(); if (!UT || !UT->getDecl()->hasAttr<TransparentUnionAttr>()) @@ -3901,7 +3900,7 @@ Sema::CheckTransparentUnionArgumentConstraints(QualType ArgType, Expr *&rExpr) { InitField = *it; break; } - + if (rExpr->isNullPointerConstant(Context)) { ImpCastExprToType(rExpr, it->getType()); InitField = *it; @@ -3942,8 +3941,8 @@ Sema::CheckSingleAssignmentConstraints(QualType lhsType, Expr *&rExpr) { // C99 6.5.16.1p1: the left operand is a pointer and the right is // a null pointer constant. - if ((lhsType->isPointerType() || - lhsType->isObjCObjectPointerType() || + if ((lhsType->isPointerType() || + lhsType->isObjCObjectPointerType() || lhsType->isBlockPointerType()) && rExpr->isNullPointerConstant(Context)) { ImpCastExprToType(rExpr, lhsType); @@ -4014,7 +4013,7 @@ inline QualType Sema::CheckVectorOperands(SourceLocation Loc, Expr *&lex, std::swap(rex, lex); std::swap(rhsType, lhsType); } - + // Handle the case of an ext vector and scalar. if (const ExtVectorType *LV = lhsType->getAsExtVectorType()) { QualType EltTy = LV->getElementType(); @@ -4034,7 +4033,7 @@ inline QualType Sema::CheckVectorOperands(SourceLocation Loc, Expr *&lex, } } } - + // Vectors of different size or scalar and non-ext-vector are errors. Diag(Loc, diag::err_typecheck_vector_not_convertable) << lex->getType() << rex->getType() @@ -4043,8 +4042,7 @@ inline QualType Sema::CheckVectorOperands(SourceLocation Loc, Expr *&lex, } inline QualType Sema::CheckMultiplyDivideOperands( - Expr *&lex, Expr *&rex, SourceLocation Loc, bool isCompAssign) -{ + Expr *&lex, Expr *&rex, SourceLocation Loc, bool isCompAssign) { if (lex->getType()->isVectorType() || rex->getType()->isVectorType()) return CheckVectorOperands(Loc, lex, rex); @@ -4056,8 +4054,7 @@ inline QualType Sema::CheckMultiplyDivideOperands( } inline QualType Sema::CheckRemainderOperands( - Expr *&lex, Expr *&rex, SourceLocation Loc, bool isCompAssign) -{ + Expr *&lex, Expr *&rex, SourceLocation Loc, bool isCompAssign) { if (lex->getType()->isVectorType() || rex->getType()->isVectorType()) { if (lex->getType()->isIntegerType() && rex->getType()->isIntegerType()) return CheckVectorOperands(Loc, lex, rex); @@ -4072,8 +4069,7 @@ inline QualType Sema::CheckRemainderOperands( } inline QualType Sema::CheckAdditionOperands( // C99 6.5.6 - Expr *&lex, Expr *&rex, SourceLocation Loc, QualType* CompLHSTy) -{ + Expr *&lex, Expr *&rex, SourceLocation Loc, QualType* CompLHSTy) { if (lex->getType()->isVectorType() || rex->getType()->isVectorType()) { QualType compType = CheckVectorOperands(Loc, lex, rex); if (CompLHSTy) *CompLHSTy = compType; @@ -4095,10 +4091,10 @@ inline QualType Sema::CheckAdditionOperands( // C99 6.5.6 std::swap(PExp, IExp); if (PExp->getType()->isAnyPointerType()) { - + if (IExp->getType()->isIntegerType()) { QualType PointeeTy = PExp->getType()->getPointeeType(); - + // Check for arithmetic on pointers to incomplete types. if (PointeeTy->isVoidType()) { if (getLangOptions().CPlusPlus) { @@ -4122,12 +4118,12 @@ inline QualType Sema::CheckAdditionOperands( // C99 6.5.6 << lex->getType() << lex->getSourceRange(); } else { // Check if we require a complete type. - if (((PExp->getType()->isPointerType() && + if (((PExp->getType()->isPointerType() && !PExp->getType()->isDependentType()) || PExp->getType()->isObjCObjectPointerType()) && RequireCompleteType(Loc, PointeeTy, - PDiag(diag::err_typecheck_arithmetic_incomplete_type) - << PExp->getSourceRange() + PDiag(diag::err_typecheck_arithmetic_incomplete_type) + << PExp->getSourceRange() << PExp->getType())) return QualType(); } @@ -4137,7 +4133,7 @@ inline QualType Sema::CheckAdditionOperands( // C99 6.5.6 << PointeeTy << PExp->getSourceRange(); return QualType(); } - + if (CompLHSTy) { QualType LHSTy = Context.isPromotableBitField(lex); if (LHSTy.isNull()) { @@ -4173,7 +4169,7 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex, if (CompLHSTy) *CompLHSTy = compType; return compType; } - + // Either ptr - int or ptr - ptr. if (lex->getType()->isAnyPointerType()) { QualType lpointee = lex->getType()->getPointeeType(); @@ -4201,9 +4197,9 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex, // GNU C extension: arithmetic on pointer to function ComplainAboutFunc = lex; } else if (!lpointee->isDependentType() && - RequireCompleteType(Loc, lpointee, + RequireCompleteType(Loc, lpointee, PDiag(diag::err_typecheck_sub_ptr_object) - << lex->getSourceRange() + << lex->getSourceRange() << lex->getType())) return QualType(); @@ -4213,7 +4209,7 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex, << lpointee << lex->getSourceRange(); return QualType(); } - + // The result type of a pointer-int computation is the pointer type. if (rex->getType()->isIntegerType()) { if (ComplainAboutVoid) @@ -4221,7 +4217,7 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex, << lex->getSourceRange() << rex->getSourceRange(); if (ComplainAboutFunc) Diag(Loc, diag::ext_gnu_ptr_func_arith) - << ComplainAboutFunc->getType() + << ComplainAboutFunc->getType() << ComplainAboutFunc->getSourceRange(); if (CompLHSTy) *CompLHSTy = lex->getType(); @@ -4284,7 +4280,7 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex, << lex->getSourceRange() << rex->getSourceRange(); if (ComplainAboutFunc) Diag(Loc, diag::ext_gnu_ptr_func_arith) - << ComplainAboutFunc->getType() + << ComplainAboutFunc->getType() << ComplainAboutFunc->getSourceRange(); if (CompLHSTy) *CompLHSTy = lex->getType(); @@ -4356,7 +4352,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, // For non-floating point types, check for self-comparisons of the form // x == x, x != x, x < x, etc. These always evaluate to a constant, and // often indicate logic errors in the program. - // NOTE: Don't warn about comparisons of enum constants. These can arise + // NOTE: Don't warn about comparisons of enum constants. These can arise // from macro expansions, and are usually quite deliberate. Expr *LHSStripped = lex->IgnoreParens(); Expr *RHSStripped = rex->IgnoreParens(); @@ -4365,12 +4361,12 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, if (DRL->getDecl() == DRR->getDecl() && !isa<EnumConstantDecl>(DRL->getDecl())) Diag(Loc, diag::warn_selfcomparison); - + if (isa<CastExpr>(LHSStripped)) LHSStripped = LHSStripped->IgnoreParenCasts(); if (isa<CastExpr>(RHSStripped)) RHSStripped = RHSStripped->IgnoreParenCasts(); - + // Warn about comparisons against a string constant (unless the other // operand is null), the user probably wants strcmp. Expr *literalString = 0; @@ -4486,11 +4482,11 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, ImpCastExprToType(rex, lType); // promote the pointer to pointer return ResultTy; } - + if (getLangOptions().CPlusPlus) { - // Comparison of pointers with null pointer constants and equality + // Comparison of pointers with null pointer constants and equality // comparisons of member pointers to null pointer constants. - if (RHSIsNull && + if (RHSIsNull && (lType->isPointerType() || (!isRelational && lType->isMemberPointerType()))) { ImpCastExprToType(rex, lType, CastExpr::CK_NullToMemberPointer); @@ -4504,17 +4500,17 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, } // Comparison of member pointers. - if (!isRelational && + if (!isRelational && lType->isMemberPointerType() && rType->isMemberPointerType()) { // C++ [expr.eq]p2: - // In addition, pointers to members can be compared, or a pointer to - // member and a null pointer constant. Pointer to member conversions - // (4.11) and qualification conversions (4.4) are performed to bring - // them to a common type. If one operand is a null pointer constant, - // the common type is the type of the other operand. Otherwise, the - // common type is a pointer to member type similar (4.4) to the type - // of one of the operands, with a cv-qualification signature (4.4) - // that is the union of the cv-qualification signatures of the operand + // In addition, pointers to members can be compared, or a pointer to + // member and a null pointer constant. Pointer to member conversions + // (4.11) and qualification conversions (4.4) are performed to bring + // them to a common type. If one operand is a null pointer constant, + // the common type is the type of the other operand. Otherwise, the + // common type is a pointer to member type similar (4.4) to the type + // of one of the operands, with a cv-qualification signature (4.4) + // that is the union of the cv-qualification signatures of the operand // types. QualType T = FindCompositePointerType(lex, rex); if (T.isNull()) { @@ -4522,17 +4518,17 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, << lType << rType << lex->getSourceRange() << rex->getSourceRange(); return QualType(); } - + ImpCastExprToType(lex, T); ImpCastExprToType(rex, T); return ResultTy; } - + // Comparison of nullptr_t with itself. if (lType->isNullPtrType() && rType->isNullPtrType()) return ResultTy; } - + // Handle block pointer types. if (!isRelational && lType->isBlockPointerType() && rType->isBlockPointerType()) { QualType lpointee = lType->getAs<BlockPointerType>()->getPointeeType(); @@ -4596,7 +4592,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_integer; else DiagID = diag::ext_typecheck_comparison_of_pointer_integer; - + if (DiagID) { Diag(Loc, DiagID) << lType << rType << lex->getSourceRange() << rex->getSourceRange(); @@ -4613,7 +4609,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_integer; else DiagID = diag::ext_typecheck_comparison_of_pointer_integer; - + if (DiagID) { Diag(Loc, DiagID) << lType << rType << lex->getSourceRange() << rex->getSourceRange(); @@ -4686,8 +4682,7 @@ QualType Sema::CheckVectorCompareOperands(Expr *&lex, Expr *&rex, } inline QualType Sema::CheckBitwiseOperands( - Expr *&lex, Expr *&rex, SourceLocation Loc, bool isCompAssign) -{ + Expr *&lex, Expr *&rex, SourceLocation Loc, bool isCompAssign) { if (lex->getType()->isVectorType() || rex->getType()->isVectorType()) return CheckVectorOperands(Loc, lex, rex); @@ -4699,8 +4694,7 @@ inline QualType Sema::CheckBitwiseOperands( } inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14] - Expr *&lex, Expr *&rex, SourceLocation Loc) -{ + Expr *&lex, Expr *&rex, SourceLocation Loc) { UsualUnaryConversions(lex); UsualUnaryConversions(rex); @@ -4713,13 +4707,12 @@ inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14] /// is a read-only property; return true if so. A readonly property expression /// depends on various declarations and thus must be treated specially. /// -static bool IsReadonlyProperty(Expr *E, Sema &S) -{ +static bool IsReadonlyProperty(Expr *E, Sema &S) { if (E->getStmtClass() == Expr::ObjCPropertyRefExprClass) { const ObjCPropertyRefExpr* PropExpr = cast<ObjCPropertyRefExpr>(E); if (ObjCPropertyDecl *PDecl = PropExpr->getProperty()) { QualType BaseType = PropExpr->getBase()->getType(); - if (const ObjCObjectPointerType *OPT = + if (const ObjCObjectPointerType *OPT = BaseType->getAsObjCInterfacePointerType()) if (ObjCInterfaceDecl *IFace = OPT->getInterfaceDecl()) if (S.isPropertyReadonly(PDecl, IFace)) @@ -4733,7 +4726,7 @@ static bool IsReadonlyProperty(Expr *E, Sema &S) /// emit an error and return true. If so, return false. static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) { SourceLocation OrigLoc = Loc; - Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(S.Context, + Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(S.Context, &Loc); if (IsLV == Expr::MLV_Valid && IsReadonlyProperty(E, S)) IsLV = Expr::MLV_ReadonlyProperty; @@ -4784,7 +4777,7 @@ static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) { if (NeedType) S.Diag(Loc, Diag) << E->getType() << E->getSourceRange() << Assign; else - S.Diag(Loc, Diag) << E->getSourceRange() << Assign; + S.Diag(Loc, Diag) << E->getSourceRange() << Assign; return true; } @@ -4886,7 +4879,7 @@ QualType Sema::CheckIncrementDecrementOperand(Expr *Op, SourceLocation OpLoc, // OK! } else if (ResType->isAnyPointerType()) { QualType PointeeTy = ResType->getPointeeType(); - + // C99 6.5.2.4p2, 6.5.6p2 if (PointeeTy->isVoidType()) { if (getLangOptions().CPlusPlus) { @@ -4908,7 +4901,7 @@ QualType Sema::CheckIncrementDecrementOperand(Expr *Op, SourceLocation OpLoc, << ResType << Op->getSourceRange(); } else if (RequireCompleteType(OpLoc, PointeeTy, PDiag(diag::err_typecheck_arithmetic_incomplete_type) - << Op->getSourceRange() + << Op->getSourceRange() << ResType)) return QualType(); // Diagnose bad cases where we step over interface counts. @@ -5064,12 +5057,12 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) { DeclContext *Ctx = dcl->getDeclContext(); if (Ctx && Ctx->isRecord()) { if (FD->getType()->isReferenceType()) { - Diag(OpLoc, + Diag(OpLoc, diag::err_cannot_form_pointer_to_member_of_reference_type) << FD->getDeclName() << FD->getType(); return QualType(); } - + return Context.getMemberPointerType(op->getType(), Context.getTypeDeclType(cast<RecordDecl>(Ctx)).getTypePtr()); } @@ -5298,7 +5291,7 @@ Action::OwningExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc, assert((rhs != 0) && "ActOnBinOp(): missing right expression"); if (getLangOptions().CPlusPlus && - (lhs->getType()->isOverloadableType() || + (lhs->getType()->isOverloadableType() || rhs->getType()->isOverloadableType())) { // Find all of the overloaded operators visible from this // point. We perform both an operator-name lookup from the local @@ -5310,7 +5303,7 @@ Action::OwningExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc, LookupOverloadedOperatorName(OverOp, S, lhs->getType(), rhs->getType(), Functions); Expr *Args[2] = { lhs, rhs }; - DeclarationName OpName + DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(OverOp); ArgumentDependentLookup(OpName, Args, 2, Functions); } @@ -5325,7 +5318,7 @@ Action::OwningExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc, } Action::OwningExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc, - unsigned OpcIn, + unsigned OpcIn, ExprArg InputArg) { UnaryOperator::Opcode Opc = static_cast<UnaryOperator::Opcode>(OpcIn); @@ -5428,7 +5421,7 @@ Action::OwningExprResult Sema::ActOnUnaryOp(Scope *S, SourceLocation OpLoc, if (OverOp != OO_None) { LookupOverloadedOperatorName(OverOp, S, Input->getType(), QualType(), Functions); - DeclarationName OpName + DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(OverOp); ArgumentDependentLookup(OpName, &Input, 1, Functions); } @@ -5533,7 +5526,7 @@ Sema::OwningExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, if (!Dependent) { bool DidWarnAboutNonPOD = false; - + // FIXME: Dependent case loses a lot of information here. And probably // leaks like a sieve. for (unsigned i = 0; i != NumComponents; ++i) { @@ -5583,7 +5576,7 @@ Sema::OwningExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, DidWarnAboutNonPOD = true; } } - + FieldDecl *MemberDecl = dyn_cast_or_null<FieldDecl>(LookupQualifiedName(RD, OC.U.IdentInfo, LookupMemberName) @@ -5708,12 +5701,12 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) { CurBlock->isVariadic = false; // Check for a valid sentinel attribute on this block. if (CurBlock->TheDecl->getAttr<SentinelAttr>()) { - Diag(ParamInfo.getAttributes()->getLoc(), + Diag(ParamInfo.getAttributes()->getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1; // FIXME: remove the attribute. } QualType RetTy = T.getTypePtr()->getAsFunctionType()->getResultType(); - + // Do not allow returning a objc interface by-value. if (RetTy->isObjCInterfaceType()) { Diag(ParamInfo.getSourceRange().getBegin(), @@ -5755,17 +5748,17 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) { PushOnScopeChains(*AI, CurBlock->TheScope); // Check for a valid sentinel attribute on this block. - if (!CurBlock->isVariadic && + if (!CurBlock->isVariadic && CurBlock->TheDecl->getAttr<SentinelAttr>()) { - Diag(ParamInfo.getAttributes()->getLoc(), + Diag(ParamInfo.getAttributes()->getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1; // FIXME: remove the attribute. } - + // Analyze the return type. QualType T = GetTypeForDeclarator(ParamInfo, CurScope); QualType RetTy = T->getAsFunctionType()->getResultType(); - + // Do not allow returning a objc interface by-value. if (RetTy->isObjCInterfaceType()) { Diag(ParamInfo.getSourceRange().getBegin(), @@ -5795,7 +5788,7 @@ Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, // If blocks are disabled, emit an error. if (!LangOpts.Blocks) Diag(CaretLoc, diag::err_blocks_disable); - + // Ensure that CurBlock is deleted. llvm::OwningPtr<BlockSemaInfo> BSI(CurBlock); @@ -5830,7 +5823,7 @@ Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, if (CurFunctionNeedsScopeChecking) DiagnoseInvalidJumps(static_cast<CompoundStmt*>(body.get())); CurFunctionNeedsScopeChecking = BSI->SavedFunctionNeedsScopeChecking; - + BSI->TheDecl->setBody(body.takeAs<CompoundStmt>()); CheckFallThroughForBlock(BlockTy, BSI->TheDecl->getBody()); return Owned(new (Context) BlockExpr(BSI->TheDecl, BlockTy, @@ -5843,7 +5836,7 @@ Sema::OwningExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc, QualType T = GetTypeFromParser(type); Expr *E = static_cast<Expr*>(expr.get()); Expr *OrigExpr = E; - + InitBuiltinVaListType(); // Get the va_list type @@ -5858,7 +5851,7 @@ Sema::OwningExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc, } else { // Otherwise, the va_list argument must be an l-value because // it is modified by va_arg. - if (!E->isTypeDependent() && + if (!E->isTypeDependent() && CheckForModifiableLvalue(E, BuiltinLoc, *this)) return ExprError(); } @@ -5992,17 +5985,17 @@ bool Sema::VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result){ return false; } -Sema::ExpressionEvaluationContext -Sema::PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext) { +Sema::ExpressionEvaluationContext +Sema::PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext) { // Introduce a new set of potentially referenced declarations to the stack. if (NewContext == PotentiallyPotentiallyEvaluated) PotentiallyReferencedDeclStack.push_back(PotentiallyReferencedDecls()); - + std::swap(ExprEvalContext, NewContext); return NewContext; } -void +void Sema::PopExpressionEvaluationContext(ExpressionEvaluationContext OldContext, ExpressionEvaluationContext NewContext) { ExprEvalContext = NewContext; @@ -6014,7 +6007,7 @@ Sema::PopExpressionEvaluationContext(ExpressionEvaluationContext OldContext, PotentiallyReferencedDecls RemainingDecls; RemainingDecls.swap(PotentiallyReferencedDeclStack.back()); PotentiallyReferencedDeclStack.pop_back(); - + for (PotentiallyReferencedDecls::iterator I = RemainingDecls.begin(), IEnd = RemainingDecls.end(); I != IEnd; ++I) @@ -6034,30 +6027,30 @@ Sema::PopExpressionEvaluationContext(ExpressionEvaluationContext OldContext, /// \param D the declaration that has been referenced by the source code. void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { assert(D && "No declaration?"); - + if (D->isUsed()) return; - + // Mark a parameter declaration "used", regardless of whether we're in a // template or not. if (isa<ParmVarDecl>(D)) D->setUsed(true); - + // Do not mark anything as "used" within a dependent context; wait for // an instantiation. if (CurContext->isDependentContext()) return; - + switch (ExprEvalContext) { case Unevaluated: // We are in an expression that is not potentially evaluated; do nothing. return; - + case PotentiallyEvaluated: // We are in a potentially-evaluated expression, so this declaration is // "used"; handle this below. break; - + case PotentiallyPotentiallyEvaluated: // We are in an expression that may be potentially evaluated; queue this // declaration reference until we know whether the expression is @@ -6065,14 +6058,14 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { PotentiallyReferencedDeclStack.back().push_back(std::make_pair(Loc, D)); return; } - + // Note that this declaration has been used. if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { unsigned TypeQuals; if (Constructor->isImplicit() && Constructor->isDefaultConstructor()) { if (!Constructor->isUsed()) DefineImplicitDefaultConstructor(Loc, Constructor); - } else if (Constructor->isImplicit() && + } else if (Constructor->isImplicit() && Constructor->isCopyConstructor(Context, TypeQuals)) { if (!Constructor->isUsed()) DefineImplicitCopyConstructor(Loc, Constructor, TypeQuals); @@ -6080,7 +6073,7 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { } else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) { if (Destructor->isImplicit() && !Destructor->isUsed()) DefineImplicitDestructor(Loc, Destructor); - + } else if (CXXMethodDecl *MethodDecl = dyn_cast<CXXMethodDecl>(D)) { if (MethodDecl->isImplicit() && MethodDecl->isOverloadedOperator() && MethodDecl->getOverloadedOperator() == OO_Equal) { @@ -6089,7 +6082,7 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { } } if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { - // Implicit instantiation of function templates and member functions of + // Implicit instantiation of function templates and member functions of // class templates. if (!Function->getBody()) { // FIXME: distinguish between implicit instantiations of function @@ -6099,21 +6092,21 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { Function->getPrimaryTemplate()) PendingImplicitInstantiations.push_back(std::make_pair(Function, Loc)); } - - + + // FIXME: keep track of references to static functions Function->setUsed(true); return; } - + if (VarDecl *Var = dyn_cast<VarDecl>(D)) { // Implicit instantiation of static data members of class templates. // FIXME: distinguish between implicit instantiations (which we need to // actually instantiate) and explicit specializations. - if (Var->isStaticDataMember() && + if (Var->isStaticDataMember() && Var->getInstantiatedFromStaticDataMember()) PendingImplicitInstantiations.push_back(std::make_pair(Var, Loc)); - + // FIXME: keep track of references to static data? D->setUsed(true); diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 12f60b99c6..3943ce103e 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -35,7 +35,7 @@ Sema::ActOnCXXConversionFunctionExpr(Scope *S, SourceLocation OperatorLoc, //FIXME: Preserve type source info. QualType ConvType = GetTypeFromParser(Ty); CanQualType ConvTypeCanon = Context.getCanonicalType(ConvType); - DeclarationName ConvName + DeclarationName ConvName = Context.DeclarationNames.getCXXConversionFunctionName(ConvTypeCanon); return ActOnDeclarationNameExpr(S, OperatorLoc, ConvName, HasTrailingLParen, &SS, isAddressOfOperand); @@ -79,10 +79,10 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, if (!isType) { // C++0x [expr.typeid]p3: - // When typeid is applied to an expression other than an lvalue of a - // polymorphic class type [...] [the] expression is an unevaluated + // When typeid is applied to an expression other than an lvalue of a + // polymorphic class type [...] [the] expression is an unevaluated // operand. - + // FIXME: if the type of the expression is a class type, the class // shall be completely defined. bool isUnevaluatedOperand = true; @@ -95,13 +95,13 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, isUnevaluatedOperand = false; } } - + // If this is an unevaluated operand, clear out the set of declaration // references we have been computing. if (isUnevaluatedOperand) PotentiallyReferencedDeclStack.back().clear(); } - + return Owned(new (Context) CXXTypeidExpr(isType, TyOrExpr, TypeInfoType.withConst(), SourceRange(OpLoc, RParenLoc))); @@ -195,9 +195,9 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep, if (Ty->isDependentType() || CallExpr::hasAnyTypeDependentArguments(Exprs, NumExprs)) { exprs.release(); - - return Owned(CXXUnresolvedConstructExpr::Create(Context, - TypeRange.getBegin(), Ty, + + return Owned(CXXUnresolvedConstructExpr::Create(Context, + TypeRange.getBegin(), Ty, LParenLoc, Exprs, NumExprs, RParenLoc)); @@ -211,12 +211,12 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep, PDiag(diag::err_invalid_incomplete_type_use) << FullRange)) return ExprError(); - + if (RequireNonAbstractType(TyBeginLoc, Ty, diag::err_allocation_of_abstract_type)) return ExprError(); - - + + // C++ [expr.type.conv]p1: // If the expression list is a single expression, the type conversion // expression is equivalent (in definedness, and if defined in meaning) to the @@ -232,9 +232,9 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep, if (!ConversionDecl || !isa<CXXConstructorDecl>(ConversionDecl)) { exprs.release(); return Owned(new (Context) CXXFunctionalCastExpr(Ty.getNonReferenceType(), - Ty, TyBeginLoc, + Ty, TyBeginLoc, CastExpr::CK_UserDefinedConversion, - Exprs[0], ConversionDecl, + Exprs[0], ConversionDecl, RParenLoc)); } } @@ -242,7 +242,7 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep, if (const RecordType *RT = Ty->getAs<RecordType>()) { CXXRecordDecl *Record = cast<CXXRecordDecl>(RT->getDecl()); - if (NumExprs > 1 || !Record->hasTrivialConstructor() || + if (NumExprs > 1 || !Record->hasTrivialConstructor() || !Record->hasTrivialDestructor()) { CXXConstructorDecl *Constructor = PerformInitializationByConstructor(Ty, Exprs, NumExprs, @@ -255,12 +255,12 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep, if (!Constructor) return ExprError(); - OwningExprResult Result = - BuildCXXTemporaryObjectExpr(Constructor, Ty, TyBeginLoc, + OwningExprResult Result = + BuildCXXTemporaryObjectExpr(Constructor, Ty, TyBeginLoc, move(exprs), RParenLoc); if (Result.isInvalid()) return ExprError(); - + return MaybeBindToTemporary(Result.takeAs<Expr>()); } @@ -300,8 +300,7 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementRParen, bool ParenTypeId, Declarator &D, SourceLocation ConstructorLParen, MultiExprArg ConstructorArgs, - SourceLocation ConstructorRParen) -{ + SourceLocation ConstructorRParen) { Expr *ArraySize = 0; unsigned Skip = 0; // If the specified type is an array, unwrap it and save the expression. @@ -337,12 +336,12 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, ++i; } - return BuildCXXNew(StartLoc, UseGlobal, + return BuildCXXNew(StartLoc, UseGlobal, PlacementLParen, - move(PlacementArgs), + move(PlacementArgs), PlacementRParen, ParenTypeId, - AllocType, + AllocType, D.getSourceRange().getBegin(), D.getSourceRange(), Owned(ArraySize), @@ -351,12 +350,12 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, ConstructorRParen); } -Sema::OwningExprResult +Sema::OwningExprResult Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, - bool ParenTypeId, + bool ParenTypeId, QualType AllocType, SourceLocation TypeLoc, SourceRange TypeRange, @@ -472,15 +471,14 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, return Owned(new (Context) CXXNewExpr(UseGlobal, OperatorNew, PlaceArgs, NumPlaceArgs, ParenTypeId, ArraySize, Constructor, Init, ConsArgs, NumConsArgs, OperatorDelete, ResultType, - StartLoc, Init ? ConstructorRParen : SourceLocation())); + StartLoc, Init ? ConstructorRParen : SourceLocation())); } /// CheckAllocatedType - Checks that a type is suitable as the allocated type /// in a new-expression. /// dimension off and stores the size expression in ArraySize. bool Sema::CheckAllocatedType(QualType AllocType, SourceLocation Loc, - SourceRange R) -{ + SourceRange R) { // C++ 5.3.4p1: "[The] type shall be a complete object type, but not an // abstract class type or array thereof. if (AllocType->isFunctionType()) @@ -508,8 +506,7 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, bool IsArray, Expr **PlaceArgs, unsigned NumPlaceArgs, FunctionDecl *&OperatorNew, - FunctionDecl *&OperatorDelete) -{ + FunctionDecl *&OperatorDelete) { // --- Choosing an allocation function --- // C++ 5.3.4p8 - 14 & 18 // 1) If UseGlobal is true, only look in the global scope. Else, also look @@ -534,7 +531,7 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, DeclarationName NewName = Context.DeclarationNames.getCXXOperatorName( IsArray ? OO_Array_New : OO_New); if (AllocType->isRecordType() && !UseGlobal) { - CXXRecordDecl *Record + CXXRecordDecl *Record = cast<CXXRecordDecl>(AllocType->getAs<RecordType>()->getDecl()); // FIXME: We fail to find inherited overloads. if (FindAllocationOverload(StartLoc, Range, NewName, &AllocArgs[0], @@ -556,7 +553,7 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, // copy them back. if (NumPlaceArgs > 0) std::copy(&AllocArgs[1], AllocArgs.end(), PlaceArgs); - + return false; } @@ -565,8 +562,7 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, bool Sema::FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, DeclarationName Name, Expr** Args, unsigned NumArgs, DeclContext *Ctx, - bool AllowMissing, FunctionDecl *&Operator) -{ + bool AllowMissing, FunctionDecl *&Operator) { DeclContext::lookup_iterator Alloc, AllocEnd; llvm::tie(Alloc, AllocEnd) = Ctx->lookup(Name); if (Alloc == AllocEnd) { @@ -639,8 +635,7 @@ bool Sema::FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, /// @endcode /// Note that the placement and nothrow forms of new are *not* implicitly /// declared. Their use requires including \<new\>. -void Sema::DeclareGlobalNewDelete() -{ +void Sema::DeclareGlobalNewDelete() { if (GlobalNewDeleteDeclared) return; GlobalNewDeleteDeclared = true; @@ -666,8 +661,7 @@ void Sema::DeclareGlobalNewDelete() /// DeclareGlobalAllocationFunction - Declares a single implicit global /// allocation function if it doesn't already exist. void Sema::DeclareGlobalAllocationFunction(DeclarationName Name, - QualType Return, QualType Argument) -{ + QualType Return, QualType Argument) { DeclContext *GlobalCtx = Context.getTranslationUnitDecl(); // Check if this function is already declared. @@ -705,15 +699,14 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name, /// @code delete [] ptr; @endcode Action::OwningExprResult Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, - bool ArrayForm, ExprArg Operand) -{ + bool ArrayForm, ExprArg Operand) { // C++ 5.3.5p1: "The operand shall have a pointer type, or a class type // having a single conversion function to a pointer type. The result has // type void." // DR599 amends "pointer type" to "pointer to object type" in both cases. FunctionDecl *OperatorDelete = 0; - + Expr *Ex = (Expr *)Operand.get(); if (!Ex->isTypeDependent()) { QualType Type = Ex->getType(); @@ -731,12 +724,12 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, return ExprError(Diag(StartLoc, diag::err_delete_operand) << Type << Ex->getSourceRange()); else if (!Pointee->isDependentType() && - RequireCompleteType(StartLoc, Pointee, + RequireCompleteType(StartLoc, Pointee, PDiag(diag::warn_delete_incomplete) << Ex->getSourceRange())) return ExprError(); - // FIXME: This should be shared with the code for finding the delete + // FIXME: This should be shared with the code for finding the delete // operator in ActOnCXXNew. IntegerLiteral Size(llvm::APInt::getNullValue( Context.Target.getPointerWidth(0)), @@ -745,12 +738,12 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, ImplicitCastExpr Cast(Context.getPointerType(Context.VoidTy), CastExpr::CK_Unknown, &Size, false); Expr *DeleteArg = &Cast; - + DeclarationName DeleteName = Context.DeclarationNames.getCXXOperatorName( ArrayForm ? OO_Array_Delete : OO_Delete); if (Pointee->isRecordType() && !UseGlobal) { - CXXRecordDecl *Record + CXXRecordDecl *Record = cast<CXXRecordDecl>(Pointee->getAs<RecordType>()->getDecl()); // FIXME: We fail to find inherited overloads. if (FindAllocationOverload(StartLoc, SourceRange(), DeleteName, @@ -759,20 +752,20 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, return ExprError(); if (!Record->hasTrivialDestructor()) if (const CXXDestructorDecl *Dtor = Record->getDestructor(Context)) - MarkDeclarationReferenced(StartLoc, + MarkDeclarationReferenced(StartLoc, const_cast<CXXDestructorDecl*>(Dtor)); } - + if (!OperatorDelete) { // Didn't find a member overload. Look for a global one. DeclareGlobalNewDelete(); DeclContext *TUDecl = Context.getTranslationUnitDecl(); - if (FindAllocationOverload(StartLoc, SourceRange(), DeleteName, + if (FindAllocationOverload(StartLoc, SourceRange(), DeleteName, &DeleteArg, 1, TUDecl, /*AllowMissing=*/false, OperatorDelete)) return ExprError(); } - + // FIXME: Check access and ambiguity of operator delete and destructor. } @@ -804,7 +797,7 @@ Sema::ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc, DeclaratorInfo *DInfo = 0; TagDecl *OwnedTag = 0; QualType Ty = GetTypeForDeclarator(D, S, &DInfo, /*Skip=*/0, &OwnedTag); - + if (Ty->isFunctionType()) { // The declarator shall not specify a function... // We exit without creating a CXXConditionDeclExpr because a FunctionDecl // would be created and CXXConditionDeclExpr wants a VarDecl. @@ -848,7 +841,7 @@ bool Sema::CheckCXXBooleanCondition(Expr *&CondExpr) { /// conversion from a string literal to a pointer to non-const char or /// non-const wchar_t (for narrow and wide string literals, /// respectively). -bool +bool Sema::IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType) { // Look inside the implicit cast, if it exists. if (ImplicitCastExpr *Cast = dyn_cast<ImplicitCastExpr>(From)) @@ -860,7 +853,7 @@ Sema::IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType) { // to wchar_t" (C++ 4.2p2). if (StringLiteral *StrLit = dyn_cast<StringLiteral>(From)) if (const PointerType *ToPtrType = ToType->getAs<PointerType>()) - if (const BuiltinType *ToPointeeType + if (const BuiltinType *ToPointeeType = ToPtrType->getPointeeType()->getAsBuiltinType()) { // This conversion is considered only when there is an // explicit appropriate pointer target type (C++ 4.2p2). @@ -886,19 +879,18 @@ Sema::IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType) { bool Sema::PerformImplicitConversion(Expr *&From, QualType ToType, const char *Flavor, bool AllowExplicit, - bool Elidable) -{ + bool Elidable) { ImplicitConversionSequence ICS; ICS.ConversionKind = ImplicitConversionSequence::BadConversion; if (Elidable && getLangOptions().CPlusPlus0x) { - ICS = TryImplicitConversion(From, ToType, + ICS = TryImplicitConversion(From, ToType, /*SuppressUserConversions=*/false, - AllowExplicit, + AllowExplicit, /*ForceRValue=*/true, /*InOverloadResolution=*/false); } if (ICS.ConversionKind == ImplicitConversionSequence::BadConversion) { - ICS = TryImplicitConversion(From, ToType, + ICS = TryImplicitConversion(From, ToType, /*SuppressUserConversions=*/false, AllowExplicit, /*ForceRValue=*/false, @@ -929,9 +921,9 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, CastExpr::CastKind CastKind = CastExpr::CK_Unknown; if (CXXConversionDecl *CV = dyn_cast<CXXConversionDecl>(FD)) { // FIXME. Get actual Source Location. - From = + From = new (Context) CXXFunctionalCastExpr(ToType.getNonReferenceType(), - ToType, SourceLocation(), + ToType, SourceLocation(), CastExpr::CK_UserDefinedConversion, From, CV, SourceLocation()); @@ -940,9 +932,9 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, else if (CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) { // FIXME. Do we need to check for isLValueReferenceType? DefaultFunctionArrayConversion(From); - OwningExprResult InitResult = + OwningExprResult InitResult = BuildCXXConstructExpr(/*FIXME:ConstructLoc*/SourceLocation(), - ToType.getNonReferenceType(), CD, + ToType.getNonReferenceType(), CD, MultiExprArg(*this, (void**)&From, 1)); // Take ownership of this expression. From = InitResult.takeAs<Expr>(); @@ -972,7 +964,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, /// otherwise. The expression From is replaced with the converted /// expression. Flavor is the context in which we're performing this /// conversion, for use in error messages. -bool +bool Sema::PerformImplicitConversion(Expr *&From, QualType ToType, const StandardConversionSequence& SCS, const char *Flavor) { @@ -985,15 +977,15 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, if (SCS.CopyConstructor) { // FIXME: When can ToType be a reference type? assert(!ToType->isReferenceType()); - - OwningExprResult FromResult = - BuildCXXConstructExpr(/*FIXME:ConstructLoc*/SourceLocation(), - ToType, SCS.CopyConstructor, + + OwningExprResult FromResult = + BuildCXXConstructExpr(/*FIXME:ConstructLoc*/SourceLocation(), + ToType, SCS.CopyConstructor, MultiExprArg(*this, (void**)&From, 1)); - + if (FromResult.isInvalid()) return true; - + From = FromResult.takeAs<Expr>(); return false; } @@ -1054,7 +1046,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, case ICK_Pointer_Conversion: if (SCS.IncompatibleObjC) { // Diagnose incompatible Objective-C conversions - Diag(From->getSourceRange().getBegin(), + Diag(From->getSourceRange().getBegin(), diag::ext_typecheck_convert_incompatible_pointer) << From->getType() << ToType << Flavor << From->getSourceRange(); @@ -1090,7 +1082,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, case ICK_Qualification: // FIXME: Not sure about lvalue vs rvalue here in the presence of rvalue // references. - ImpCastExprToType(From, ToType.getNonReferenceType(), + ImpCastExprToType(From, ToType.getNonReferenceType(), CastExpr::CK_Unknown, ToType->isLValueReferenceType()); break; @@ -1109,12 +1101,12 @@ Sema::OwningExprResult Sema::ActOnUnaryTypeTrait(UnaryTypeTrait OTT, TypeTy *Ty, SourceLocation RParen) { QualType T = GetTypeFromParser(Ty); - + // According to http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html // all traits except __is_class, __is_enum and __is_union require a the type // to be complete. if (OTT != UTT_IsClass && OTT != UTT_IsEnum && OTT != UTT_IsUnion) { - if (RequireCompleteType(KWLoc, T, + if (RequireCompleteType(KWLoc, T, diag::err_incomplete_type_used_in_type_trait_expr)) return ExprError(); } @@ -1127,8 +1119,7 @@ Sema::OwningExprResult Sema::ActOnUnaryTypeTrait(UnaryTypeTrait OTT, } QualType Sema::CheckPointerToMemberOperands( - Expr *&lex, Expr *&rex, SourceLocation Loc, bool isIndirect) -{ + Expr *&lex, Expr *&rex, SourceLocation Loc, bool isIndirect) { const char *OpSpelling = isIndirect ? "->*" : ".*"; // C++ 5.5p2 // The binary operator .* [p3: ->*] binds its second operand, which shall @@ -1140,7 +1131,7 @@ QualType Sema::CheckPointerToMemberOperands( Diag(Loc, diag::err_bad_memptr_rhs) << OpSpelling << RType << rex->getSourceRange(); return QualType(); - } + } QualType Class(MemPtr->getClass(), 0); @@ -1214,8 +1205,7 @@ static QualType TargetType(const ImplicitConversionSequence &ICS) { /// conversion. static bool TryClassUnification(Sema &Self, Expr *From, Expr *To, SourceLocation QuestionLoc, - ImplicitConversionSequence &ICS) -{ + ImplicitConversionSequence &ICS) { // C++0x 5.16p3 // The process for determining whether an operand expression E1 of type T1 // can be converted to match an operand expression E2 of type T2 is defined @@ -1262,7 +1252,7 @@ static bool TryClassUnification(Sema &Self, Expr *From, Expr *To, // Could still fail if there's no copy constructor. // FIXME: Is this a hard error then, or just a conversion failure? The // standard doesn't say. - ICS = Self.TryCopyInitialization(From, TTy, + ICS = Self.TryCopyInitialization(From, TTy, /*SuppressUserConversions=*/false, /*ForceRValue=*/false, /*InOverloadResolution=*/false); @@ -1274,7 +1264,7 @@ static bool TryClassUnification(Sema &Self, Expr *From, Expr *To, // First find the decayed type. if (TTy->isFunctionType()) TTy = Self.Context.getPointerType(TTy); - else if(TTy->isArrayType()) + else if (TTy->isArrayType()) TTy = Self.Context.getArrayDecayedType(TTy); // Now try the implicit conversion. @@ -1339,8 +1329,7 @@ static bool FindConditionalOverload(Sema &Self, Expr *&LHS, Expr *&RHS, /// second part of a standard conversion is ICK_DerivedToBase. This function /// handles the reference binding specially. static bool ConvertForConditional(Sema &Self, Expr *&E, - const ImplicitConversionSequence &ICS) -{ + const ImplicitConversionSequence &ICS) { if (ICS.ConversionKind == ImplicitConversionSequence::StandardConversion && ICS.Standard.ReferenceBinding) { assert(ICS.Standard.DirectBinding && @@ -1583,13 +1572,13 @@ QualType Sema::CXXCheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, QualType Sema::FindCompositePointerType(Expr *&E1, Expr *&E2) { assert(getLangOptions().CPlusPlus && "This function assumes C++"); QualType T1 = E1->getType(), T2 = E2->getType(); - + if (!T1->isPointerType() && !T1->isMemberPointerType() && !T2->isPointerType() && !T2->isMemberPointerType()) return QualType(); // FIXME: Do we need to work on the canonical types? - + // C++0x 5.9p2 // Pointer conversions and qualification conversions are performed on // pointer operands to bring them to their composite pointer type. If @@ -1603,7 +1592,7 @@ QualType Sema::FindCompositePointerType(Expr *&E1, Expr *&E2) { ImpCastExprToType(E2, T1); return T1; } - + // Now both have to be pointers or member pointers. if (!T1->isPointerType() && !T1->isMemberPointerType() && !T2->isPointerType() && !T2->isMemberPointerType()) @@ -1633,7 +1622,7 @@ QualType Sema::FindCompositePointerType(Expr *&E1, Expr *&E2) { MemberOfClass.push_back(std::make_pair((const Type *)0, (const Type *)0)); continue; } - + const MemberPointerType *MemPtr1, *MemPtr2; if ((MemPtr1 = Composite1->getAs<MemberPointerType>()) && (MemPtr2 = Composite2->getAs<MemberPointerType>())) { @@ -1645,19 +1634,19 @@ QualType Sema::FindCompositePointerType(Expr *&E1, Expr *&E2) { MemPtr2->getClass())); continue; } - + // FIXME: block pointer types? - + // Cannot unwrap any more types. break; } while (true); - + // Rewrap the composites as pointers or member pointers with the union CVRs. llvm::SmallVector<std::pair<const Type *, const Type *>, 4>::iterator MOC = MemberOfClass.begin(); - for (llvm::SmallVector<unsigned, 4>::iterator + for (llvm::SmallVector<unsigned, 4>::iterator I = QualifierUnion.begin(), - E = QualifierUnion.end(); + E = QualifierUnion.end(); I != E; (void)++I, ++MOC) { if (MOC->first && MOC->second) { // Rebuild member pointer type @@ -1672,19 +1661,19 @@ QualType Sema::FindCompositePointerType(Expr *&E1, Expr *&E2) { } } - ImplicitConversionSequence E1ToC1 = + ImplicitConversionSequence E1ToC1 = TryImplicitConversion(E1, Composite1, /*SuppressUserConversions=*/false, /*AllowExplicit=*/false, /*ForceRValue=*/false, /*InOverloadResolution=*/false); - ImplicitConversionSequence E2ToC1 = + ImplicitConversionSequence E2ToC1 = TryImplicitConversion(E2, Composite1, /*SuppressUserConversions=*/false, /*AllowExplicit=*/false, /*ForceRValue=*/false, /*InOverloadResolution=*/false); - + ImplicitConversionSequence E1ToC2, E2ToC2; E1ToC2.ConversionKind = ImplicitConversionSequence::BadConversion; E2ToC2.ConversionKind = ImplicitConversionSequence::BadConversion; @@ -1726,16 +1715,16 @@ QualType Sema::FindCompositePointerType(Expr *&E1, Expr *&E2) { Sema::OwningExprResult Sema::MaybeBindToTemporary(Expr *E) { if (!Context.getLangOptions().CPlusPlus) return Owned(E); - + const RecordType *RT = E->getType()->getAs<RecordType>(); if (!RT) return Owned(E); - + CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); if (RD->hasTrivialDestructor()) return Owned(E); - - CXXTemporary *Temp = CXXTemporary::Create(Context, + + CXXTemporary *Temp = CXXTemporary::Create(Context, RD->getDestructor(Context)); ExprTemporaries.push_back(Temp); if (CXXDestructorDecl *Destructor = @@ -1745,40 +1734,40 @@ Sema::OwningExprResult Sema::MaybeBindToTemporary(Expr *E) { return Owned(CXXBindTemporaryExpr::Create(Context, Temp, E)); } -Expr *Sema::MaybeCreateCXXExprWithTemporaries(Expr *SubExpr, +Expr *Sema::MaybeCreateCXXExprWithTemporaries(Expr *SubExpr, bool ShouldDestroyTemps) { assert(SubExpr && "sub expression can't be null!"); - + if (ExprTemporaries.empty()) return SubExpr; - + Expr *E = CXXExprWithTemporaries::Create(Context, SubExpr, - &ExprTemporaries[0], + &ExprTemporaries[0], ExprTemporaries.size(), ShouldDestroyTemps); ExprTemporaries.clear(); - + return E; } -Sema::OwningExprResult +Sema::OwningExprResult Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc, tok::TokenKind OpKind, TypeTy *&ObjectType) { // Since this might be a postfix expression, get rid of ParenListExprs. Base = MaybeConvertParenListExprToParenExpr(S, move(Base)); - + Expr *BaseExpr = (Expr*)Base.get(); assert(BaseExpr && "no record expansion"); - + QualType BaseType = BaseExpr->getType(); if (BaseType->isDependentType()) { // FIXME: member of the current instantiation ObjectType = BaseType.getAsOpaquePtr(); return move(Base); } - + // C++ [over.match.oper]p8: - // [...] When operator->returns, the operator-> is applied to the value + // [...] When operator->returns, the operator-> is applied to the value // returned, with the original second operand. if (OpKind == tok::arrow) { while (BaseType->isRecordType()) { @@ -1789,11 +1778,11 @@ Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc, BaseType = BaseExpr->getType(); } } - + if (BaseType->isPointerType()) BaseType = BaseType->getPointeeType(); - - // We could end up with various non-record types here, such as extended + + // We could end up with various non-record types here, such as extended // vector types or Objective-C interfaces. Just return early and let // ActOnMemberReferenceExpr do the work. if (!BaseType->isRecordType()) { @@ -1804,14 +1793,14 @@ Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc, ObjectType = 0; return move(Base); } - + // C++ [basic.lookup.classref]p2: - // If the id-expression in a class member access (5.2.5) is an + // If the id-expression in a class member access (5.2.5) is an // unqualified-id, and the type of the object expres- sion is of a class // type C (or of pointer to a class type C), the unqualified-id is looked // up in the scope of class C. [...] ObjectType = BaseType.getAsOpaquePtr(); - return move(Base); + return move(Base); } Sema::OwningExprResult @@ -1832,16 +1821,16 @@ Sema::ActOnDestructorReferenceExpr(Scope *S, ExprArg Base, else { TypeTy *BaseTy = getTypeName(*ClassName, ClassNameLoc, S, &SS); if (!BaseTy) { - Diag(ClassNameLoc, diag::err_ident_in_pseudo_dtor_not_a_type) + Diag(ClassNameLoc, diag::err_ident_in_pseudo_dtor_not_a_type) << ClassName; return ExprError(); } - + BaseType = GetTypeFromParser(BaseTy); } - + CanQualType CanBaseType = Context.getCanonicalType(BaseType); - DeclarationName DtorName = + DeclarationName DtorName = Context.DeclarationNames.getCXXDestructorName(CanBaseType); OwningExprResult Result @@ -1849,8 +1838,8 @@ Sema::ActOnDestructorReferenceExpr(Scope *S, ExprArg Base, DtorName, DeclPtrTy(), &SS); if (Result.isInvalid() || HasTrailingLParen) return move(Result); - - // The only way a reference to a destructor can be used is to + + // The only way a reference to a destructor can be used is to // immediately call them. Since the next token is not a '(', produce a // diagnostic and build the call now. Expr *E = (Expr *)Result.get(); @@ -1858,8 +1847,8 @@ Sema::ActOnDestructorReferenceExpr(Scope *S, ExprArg Base, Diag(E->getLocStart(), diag::err_dtor_expr_without_call) << isa<CXXPseudoDestructorExpr>(E) << CodeModificationHint::CreateInsertion(ExpectedLParenLoc, "()"); - - return ActOnCallExpr(0, move(Result), ExpectedLParenLoc, + + return ActOnCallExpr(0, move(Result), ExpectedLParenLoc, MultiExprArg(*this, 0, 0), 0, ExpectedLParenLoc); } @@ -1903,7 +1892,7 @@ Sema::ActOnConversionOperatorReferenceExpr(Scope *S, ExprArg Base, Sema::OwningExprResult Sema::ActOnFinishFullExpr(ExprArg Arg) { Expr *FullExpr = Arg.takeAs<Expr>(); if (FullExpr) - FullExpr = MaybeCreateCXXExprWithTemporaries(FullExpr, + FullExpr = MaybeCreateCXXExprWithTemporaries(FullExpr, /*ShouldDestroyTemps=*/true); diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 0fcf747847..2616c5c0bd 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -20,7 +20,7 @@ using namespace clang; -Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, +Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, ExprTy **strings, unsigned NumStrings) { StringLiteral **Strings = reinterpret_cast<StringLiteral**>(strings); @@ -30,40 +30,40 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, // each one, e.g. @"foo" "bar" @"baz" "qux" which need to be turned into one // StringLiteral for ObjCStringLiteral to hold onto. StringLiteral *S = Strings[0]; - + // If we have a multi-part string, merge it all together. if (NumStrings != 1) { // Concatenate objc strings. llvm::SmallString<128> StrBuf; llvm::SmallVector<SourceLocation, 8> StrLocs; - + for (unsigned i = 0; i != NumStrings; ++i) { S = Strings[i]; - + // ObjC strings can't be wide. if (S->isWide()) { Diag(S->getLocStart(), diag::err_cfstring_literal_not_string_constant) << S->getSourceRange(); return true; } - + // Get the string data. StrBuf.append(S->getStrData(), S->getStrData()+S->getByteLength()); - + // Get the locations of the string tokens. StrLocs.append(S->tokloc_begin(), S->tokloc_end()); - + // Free the temporary string. S->Destroy(Context); } - + // Create the aggregate string with the appropriate content and location // information. S = StringLiteral::Create(Context, &StrBuf[0], StrBuf.size(), false, Context.getPointerType(Context.CharTy), &StrLocs[0], StrLocs.size()); } - + // Verify that this composite string is acceptable for ObjC strings. if (CheckObjCString(S)) return true; @@ -88,15 +88,15 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, Ty = Context.getObjCIdType(); } } - + return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]); } -Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, +Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, QualType EncodedType, SourceLocation RParenLoc) { QualType StrTy; - if (EncodedType->isDependentType()) + if (EncodedType->isDependentType()) StrTy = Context.DependentTy; else { std::string Str; @@ -111,7 +111,7 @@ Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, StrTy = Context.getConstantArrayType(StrTy, llvm::APInt(32, Str.size()+1), ArrayType::Normal, 0); } - + return new (Context) ObjCEncodeExpr(StrTy, EncodedType, AtLoc, RParenLoc); } @@ -131,7 +131,7 @@ Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel, SourceLocation SelLoc, SourceLocation LParenLoc, SourceLocation RParenLoc) { - ObjCMethodDecl *Method = LookupInstanceMethodInGlobalPool(Sel, + ObjCMethodDecl *Method = LookupInstanceMethodInGlobalPool(Sel, SourceRange(LParenLoc, RParenLoc), false); if (!Method) Method = LookupFactoryMethodInGlobalPool(Sel, @@ -153,7 +153,7 @@ Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId, Diag(ProtoLoc, diag::err_undeclared_protocol) << ProtocolId; return true; } - + QualType Ty = Context.getObjCProtoType(); if (Ty.isNull()) return true; @@ -161,11 +161,11 @@ Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId, return new (Context) ObjCProtocolExpr(Ty, PDecl, AtLoc, RParenLoc); } -bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, - Selector Sel, ObjCMethodDecl *Method, +bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, + Selector Sel, ObjCMethodDecl *Method, bool isClassMessage, SourceLocation lbrac, SourceLocation rbrac, - QualType &ReturnType) { + QualType &ReturnType) { if (!Method) { // Apply default argument promotion as for (C99 6.5.2.2p6). for (unsigned i = 0; i != NumArgs; i++) @@ -178,9 +178,9 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, ReturnType = Context.getObjCIdType(); return false; } - + ReturnType = Method->getResultType(); - + unsigned NumNamedArgs = Sel.getNumArgs(); assert(NumArgs >= NumNamedArgs && "Too few arguments for selector!"); @@ -188,22 +188,22 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, for (unsigned i = 0; i < NumNamedArgs; i++) { Expr *argExpr = Args[i]; assert(argExpr && "CheckMessageArgumentTypes(): missing expression"); - + QualType lhsType = Method->param_begin()[i]->getType(); QualType rhsType = argExpr->getType(); - // If necessary, apply function/array conversion. C99 6.7.5.3p[7,8]. + // If necessary, apply function/array conversion. C99 6.7.5.3p[7,8]. if (lhsType->isArrayType()) lhsType = Context.getArrayDecayedType(lhsType); else if (lhsType->isFunctionType()) lhsType = Context.getPointerType(lhsType); - AssignConvertType Result = + AssignConvertType Result = CheckSingleAssignmentConstraints(lhsType, argExpr); if (Args[i] != argExpr) // The expression was converted. Args[i] = argExpr; // Make sure we store the converted expression. - - IsError |= + + IsError |= DiagnoseAssignmentResult(Result, argExpr->getLocStart(), lhsType, rhsType, argExpr, "sending"); } @@ -215,7 +215,7 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, } else { // Check for extra arguments to non-variadic methods. if (NumArgs != NumNamedArgs) { - Diag(Args[NumNamedArgs]->getLocStart(), + Diag(Args[NumNamedArgs]->getLocStart(), diag::err_typecheck_call_too_many_args) << 2 /*method*/ << Method->getSourceRange() << SourceRange(Args[NumNamedArgs]->getLocStart(), @@ -244,22 +244,22 @@ ObjCMethodDecl *Sema::LookupPrivateClassMethod(Selector Sel, while (ClassDecl && !Method) { if (ObjCImplementationDecl *ImpDecl = ClassDecl->getImplementation()) Method = ImpDecl->getClassMethod(Sel); - + // Look through local category implementations associated with the class. if (!Method) Method = ClassDecl->getCategoryClassMethod(Sel); - + // Before we give up, check if the selector is an instance method. // But only in the root. This matches gcc's behaviour and what the // runtime expects. if (!Method && !ClassDecl->getSuperClass()) { Method = ClassDecl->lookupInstanceMethod(Sel); - // Look through local category implementations associated + // Look through local category implementations associated // with the root class. - if (!Method) + if (!Method) Method = LookupPrivateInstanceMethod(Sel, ClassDecl); } - + ClassDecl = ClassDecl->getSuperClass(); } return Method; @@ -272,7 +272,7 @@ ObjCMethodDecl *Sema::LookupPrivateInstanceMethod(Selector Sel, // If we have implementations in scope, check "private" methods. if (ObjCImplementationDecl *ImpDecl = ClassDecl->getImplementation()) Method = ImpDecl->getInstanceMethod(Sel); - + // Look through local category implementations associated with the class. if (!Method) Method = ClassDecl->getCategoryInstanceMethod(Sel); @@ -286,11 +286,11 @@ Action::OwningExprResult Sema::ActOnClassPropertyRefExpr( IdentifierInfo &propertyName, SourceLocation &receiverNameLoc, SourceLocation &propertyNameLoc) { - + ObjCInterfaceDecl *IFace = getObjCInterfaceDecl(&receiverName); - + // Search for a declared property first. - + Selector Sel = PP.getSelectorTable().getNullarySelector(&propertyName); ObjCMethodDecl *Getter = IFace->lookupClassMethod(Sel); @@ -307,12 +307,12 @@ Action::OwningExprResult Sema::ActOnClassPropertyRefExpr( if (DiagnoseUseOfDecl(Getter, propertyNameLoc)) return ExprError(); } - + // Look for the matching setter, in case it is needed. - Selector SetterSel = - SelectorTable::constructSetterName(PP.getIdentifierTable(), + Selector SetterSel = + SelectorTable::constructSetterName(PP.getIdentifierTable(), PP.getSelectorTable(), &propertyName); - + ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel); if (!Setter) { // If this reference is in an @implementation, also check for 'private' @@ -340,7 +340,7 @@ Action::OwningExprResult Sema::ActOnClassPropertyRefExpr( PType = (*PI)->getType(); } return Owned(new (Context) ObjCImplicitSetterGetterRefExpr( - Getter, PType, Setter, + Getter, PType, Setter, propertyNameLoc, IFace, receiverNameLoc)); } return ExprError(Diag(propertyNameLoc, diag::err_property_not_found) @@ -355,21 +355,20 @@ Sema::ExprResult Sema::ActOnClassMessage( Scope *S, IdentifierInfo *receiverName, Selector Sel, SourceLocation lbrac, SourceLocation receiverLoc, - SourceLocation selectorLoc, SourceLocation rbrac, - ExprTy **Args, unsigned NumArgs) -{ + SourceLocation selectorLoc, SourceLocation rbrac, + ExprTy **Args, unsigned NumArgs) { assert(receiverName && "missing receiver class name"); Expr **ArgExprs = reinterpret_cast<Expr **>(Args); ObjCInterfaceDecl* ClassDecl = 0; bool isSuper = false; - + if (receiverName->isStr("super")) { if (getCurMethodDecl()) { isSuper = true; ObjCInterfaceDecl *OID = getCurMethodDecl()->getClassInterface(); if (!OID) - return Diag(lbrac, diag::error_no_super_class_message) + return Diag(lbrac, diag::error_no_super_class_message) << getCurMethodDecl()->getDeclName(); ClassDecl = OID->getSuperClass(); if (!ClassDecl) @@ -380,7 +379,7 @@ Sema::ExprResult Sema::ActOnClassMessage( ExprResult ReceiverExpr = new (Context) ObjCSuperExpr(SourceLocation(), superTy); // We are really in an instance method, redirect. - return ActOnInstanceMessage(ReceiverExpr.get(), Sel, lbrac, + return ActOnInstanceMessage(ReceiverExpr.get(), Sel, lbrac, selectorLoc, rbrac, Args, NumArgs); } // We are sending a message to 'super' within a class method. Do nothing, @@ -391,17 +390,17 @@ Sema::ExprResult Sema::ActOnClassMessage( NamedDecl *SuperDecl = LookupName(S, receiverName, LookupOrdinaryName); ValueDecl *VD = dyn_cast_or_null<ValueDecl>(SuperDecl); if (VD) { - ExprResult ReceiverExpr = new (Context) DeclRefExpr(VD, VD->getType(), + ExprResult ReceiverExpr = new (Context) DeclRefExpr(VD, VD->getType(), receiverLoc); // We are really in an instance method, redirect. - return ActOnInstanceMessage(ReceiverExpr.get(), Sel, lbrac, + return ActOnInstanceMessage(ReceiverExpr.get(), Sel, lbrac, selectorLoc, rbrac, Args, NumArgs); } return Diag(receiverLoc, diag::err_undeclared_var_use) << receiverName; - } + } } else ClassDecl = getObjCInterfaceDecl(receiverName); - + // The following code allows for the following GCC-ism: // // typedef XCElementDisplayRect XCElementGraphicsRect; @@ -432,25 +431,25 @@ Sema::ExprResult Sema::ActOnClassMessage( Diag(lbrac, diag::warn_receiver_forward_class) << ClassDecl->getDeclName(); Method = LookupFactoryMethodInGlobalPool(Sel, SourceRange(lbrac,rbrac)); if (Method) - Diag(Method->getLocation(), diag::note_method_sent_forward_class) + Diag(Method->getLocation(), diag::note_method_sent_forward_class) << Method->getDeclName(); } if (!Method) Method = ClassDecl->lookupClassMethod(Sel); - + // If we have an implementation in scope, check "private" methods. if (!Method) Method = LookupPrivateClassMethod(Sel, ClassDecl); if (Method && DiagnoseUseOfDecl(Method, receiverLoc)) return true; - - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, true, + + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, true, lbrac, rbrac, returnType)) return true; returnType = returnType.getNonReferenceType(); - + // If we have the ObjCInterfaceDecl* for the class that is receiving the // message, use that to construct the ObjCMessageExpr. Otherwise pass on the // IdentifierInfo* for the class. @@ -469,19 +468,19 @@ Sema::ExprResult Sema::ActOnClassMessage( // ArgExprs is optional - if it is present, the number of expressions // is obtained from Sel.getNumArgs(). Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, - SourceLocation lbrac, + SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac, ExprTy **Args, unsigned NumArgs) { assert(receiver && "missing receiver expression"); - + Expr **ArgExprs = reinterpret_cast<Expr **>(Args); Expr *RExpr = static_cast<Expr *>(receiver); - + // If necessary, apply function/array conversion to the receiver. // C99 6.7.5.3p[7,8]. DefaultFunctionArrayConversion(RExpr); - + QualType returnType; QualType ReceiverCType = Context.getCanonicalType(RExpr->getType()).getUnqualifiedType(); @@ -494,8 +493,8 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface()) if (ObjCInterfaceDecl *SuperDecl = ClassDecl->getSuperClass()) { Method = SuperDecl->lookupInstanceMethod(Sel); - - if (!Method) + + if (!Method) // If we have implementations in scope, check "private" methods. Method = LookupPrivateInstanceMethod(Sel, SuperDecl); } @@ -507,41 +506,41 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; - + returnType = returnType.getNonReferenceType(); return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, ArgExprs, NumArgs); } - // Handle messages to id. + // Handle messages to id. if (ReceiverCType->isObjCIdType() || ReceiverCType->isBlockPointerType() || Context.isObjCNSObjectType(RExpr->getType())) { ObjCMethodDecl *Method = LookupInstanceMethodInGlobalPool( Sel, SourceRange(lbrac,rbrac)); if (!Method) Method = LookupFactoryMethodInGlobalPool(Sel, SourceRange(lbrac, rbrac)); - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; returnType = returnType.getNonReferenceType(); return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, ArgExprs, NumArgs); } - + // Handle messages to Class. - if (ReceiverCType->isObjCClassType() || + if (ReceiverCType->isObjCClassType() || ReceiverCType->isObjCQualifiedClassType()) { ObjCMethodDecl *Method = 0; - + if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) { if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface()) { // First check the public methods in the class interface. Method = ClassDecl->lookupClassMethod(Sel); - + if (!Method) Method = LookupPrivateClassMethod(Sel, ClassDecl); - - // FIXME: if we still haven't found a method, we need to look in + + // FIXME: if we still haven't found a method, we need to look in // protocols (if we have qualifiers). } if (Method && DiagnoseUseOfDecl(Method, receiverLoc)) @@ -573,13 +572,13 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, ArgExprs, NumArgs); } - + ObjCMethodDecl *Method = 0; ObjCInterfaceDecl* ClassDecl = 0; - - // We allow sending a message to a qualified ID ("id<foo>"), which is ok as + + // We allow sending a message to a qualified ID ("id<foo>"), which is ok as // long as one of the protocols implements the selector (if not, warn). - if (const ObjCObjectPointerType *QIdTy = + if (const ObjCObjectPointerType *QIdTy = ReceiverCType->getAsObjCQualifiedIdType()) { // Search protocols for instance methods. for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(), @@ -591,16 +590,16 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (PDecl && (Method = PDecl->lookupClassMethod(Sel))) break; } - } else if (const ObjCObjectPointerType *OCIType = + } else if (const ObjCObjectPointerType *OCIType = ReceiverCType->getAsObjCInterfacePointerType()) { // We allow sending a message to a pointer to an interface (an object). - + ClassDecl = OCIType->getInterfaceDecl(); // FIXME: consider using LookupInstanceMethodInGlobalPool, since it will be // faster than the following method (which can do *many* linear searches). // The idea is to add class info to InstanceMethodPool. Method = ClassDecl->lookupInstanceMethod(Sel); - + if (!Method) { // Search protocol qualifiers. for (ObjCObjectPointerType::qual_iterator QI = OCIType->qual_begin(), @@ -612,7 +611,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (!Method) { // If we have implementations in scope, check "private" methods. Method = LookupPrivateInstanceMethod(Sel, ClassDecl); - + if (!Method && !isSelfExpr(RExpr)) { // If we still haven't found a method, look in the global pool. This // behavior isn't very desirable, however we need it for GCC @@ -621,7 +620,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, Method = LookupInstanceMethodInGlobalPool( Sel, SourceRange(lbrac,rbrac)); if (Method && !OCIType->getInterfaceDecl()->isForwardDecl()) - Diag(lbrac, diag::warn_maynot_respond) + Diag(lbrac, diag::warn_maynot_respond) << OCIType->getInterfaceDecl()->getIdentifier()->getName() << Sel; } } @@ -630,7 +629,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, return true; } else if (!Context.getObjCIdType().isNull() && (ReceiverCType->isPointerType() || - (ReceiverCType->isIntegerType() && + (ReceiverCType->isIntegerType() && ReceiverCType->isScalarType()))) { // Implicitly convert integers and pointers to 'id' but emit a warning. Diag(lbrac, diag::warn_bad_receiver_type) @@ -642,7 +641,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, << RExpr->getType() << RExpr->getSourceRange(); return true; } - + if (Method) DiagnoseSentinelCalls(Method, receiverLoc, ArgExprs, NumArgs); if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, diff --git a/lib/Sema/SemaInherit.cpp b/lib/Sema/SemaInherit.cpp index c48e3bc79e..e6734d5176 100644 --- a/lib/Sema/SemaInherit.cpp +++ b/lib/Sema/SemaInherit.cpp @@ -28,9 +28,9 @@ using namespace clang; /// \brief Computes the set of declarations referenced by these base /// paths. void BasePaths::ComputeDeclsFound() { - assert(NumDeclsFound == 0 && !DeclsFound && + assert(NumDeclsFound == 0 && !DeclsFound && "Already computed the set of declarations"); - + std::set<NamedDecl *> Decls; for (BasePaths::paths_iterator Path = begin(), PathEnd = end(); Path != PathEnd; ++Path) @@ -127,24 +127,24 @@ bool Sema::IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths) { /// behavior of this lookup, e.g., whether it finds ambiguities, /// records paths, or attempts to detect the use of virtual base /// classes. -bool Sema::LookupInBases(CXXRecordDecl *Class, +bool Sema::LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria, BasePaths &Paths) { bool FoundPath = false; for (CXXRecordDecl::base_class_const_iterator BaseSpec = Class->bases_begin(), - BaseSpecEnd = Class->bases_end(); + BaseSpecEnd = Class->bases_end(); BaseSpec != BaseSpecEnd; ++BaseSpec) { // Find the record of the base class subobjects for this type. QualType BaseType = Context.getCanonicalType(BaseSpec->getType()); BaseType = BaseType.getUnqualifiedType(); - // If a base class of the class template depends on a template-parameter, + // If a base class of the class template depends on a template-parameter, // the base class scope is not examined during unqualified name lookup. // [temp.dep]p3. if (BaseType->isDependentType()) continue; - + // Determine whether we need to visit this base class at all, // updating the count of subobjects appropriately. std::pair<bool, unsigned>& Subobjects = Paths.ClassSubobjects[BaseType]; @@ -174,7 +174,7 @@ bool Sema::LookupInBases(CXXRecordDecl *Class, Paths.ScratchPath.push_back(Element); } - CXXRecordDecl *BaseRecord + CXXRecordDecl *BaseRecord = cast<CXXRecordDecl>(BaseSpec->getType()->getAs<RecordType>()->getDecl()); // Either look at the base class type or look into the base class @@ -183,7 +183,7 @@ bool Sema::LookupInBases(CXXRecordDecl *Class, bool FoundPathToThisBase = false; switch (Criteria.Kind) { case MemberLookupCriteria::LK_Base: - FoundPathToThisBase + FoundPathToThisBase = (Context.getCanonicalType(BaseSpec->getType()) == Criteria.Base); break; case MemberLookupCriteria::LK_NamedMember: @@ -198,19 +198,19 @@ bool Sema::LookupInBases(CXXRecordDecl *Class, } break; case MemberLookupCriteria::LK_OverriddenMember: - Paths.ScratchPath.Decls = + Paths.ScratchPath.Decls = BaseRecord->lookup(Criteria.Method->getDeclName()); while (Paths.ScratchPath.Decls.first != Paths.ScratchPath.Decls.second) { - if (CXXMethodDecl *MD = + if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(*Paths.ScratchPath.Decls.first)) { OverloadedFunctionDecl::function_iterator MatchedDecl; - if (MD->isVirtual() && + if (MD->isVirtual() && !IsOverload(Criteria.Method, MD, MatchedDecl)) { FoundPathToThisBase = true; break; } } - + ++Paths.ScratchPath.Decls.first; } break; @@ -296,27 +296,27 @@ Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base, bool StillOkay = IsDerivedFrom(Derived, Base, Paths); assert(StillOkay && "Can only be used with a derived-to-base conversion"); (void)StillOkay; - + // Build up a textual representation of the ambiguous paths, e.g., // D -> B -> A, that will be used to illustrate the ambiguous // conversions in the diagnostic. We only print one of the paths // to each base class subobject. std::string PathDisplayStr = getAmbiguousPathsDisplayString(Paths); - + Diag(Loc, AmbigiousBaseConvID) << Derived << Base << PathDisplayStr << Range << Name; return true; } -bool +bool Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base, SourceLocation Loc, SourceRange Range) { - return CheckDerivedToBaseConversion(Derived, Base, + return CheckDerivedToBaseConversion(Derived, Base, diag::err_conv_to_inaccessible_base, diag::err_ambiguous_derived_to_base_conv, Loc, Range, DeclarationName()); } - + /// @brief Builds a string representing ambiguous paths from a /// specific derived class to different subobjects of the same base @@ -333,16 +333,16 @@ Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base, std::string Sema::getAmbiguousPathsDisplayString(BasePaths &Paths) { std::string PathDisplayStr; std::set<unsigned> DisplayedPaths; - for (BasePaths::paths_iterator Path = Paths.begin(); + for (BasePaths::paths_iterator Path = Paths.begin(); Path != Paths.end(); ++Path) { if (DisplayedPaths.insert(Path->back().SubobjectNumber).second) { // We haven't displayed a path to this particular base // class subobject yet. PathDisplayStr += "\n "; PathDisplayStr += Paths.getOrigin().getAsString(); - for (BasePath::const_iterator Element = Path->begin(); + for (BasePath::const_iterator Element = Path->begin(); Element != Path->end(); ++Element) - PathDisplayStr += " -> " + Element->Base->getType().getAsString(); + PathDisplayStr += " -> " + Element->Base->getType().getAsString(); } } diff --git a/lib/Sema/SemaInherit.h b/lib/Sema/SemaInherit.h index b1e791a17b..d08d7f8a4b 100644 --- a/lib/Sema/SemaInherit.h +++ b/lib/Sema/SemaInherit.h @@ -41,11 +41,11 @@ namespace clang { /// Class - The record decl of the class that the base is a base of. const CXXRecordDecl *Class; - + /// SubobjectNumber - Identifies which base class subobject (of type - /// @c Base->getType()) this base path element refers to. This + /// @c Base->getType()) this base path element refers to. This /// value is only valid if @c !Base->isVirtual(), because there - /// is no base numbering for the zero or one virtual bases of a + /// is no base numbering for the zero or one virtual bases of a /// given type. int SubobjectNumber; }; @@ -107,7 +107,7 @@ namespace clang { /// while the element contains the number of non-virtual base /// class subobjects for that class type. The key of the map is /// the cv-unqualified canonical type of the base class subobject. - std::map<QualType, std::pair<bool, unsigned>, QualTypeOrdering> + std::map<QualType, std::pair<bool, unsigned>, QualTypeOrdering> ClassSubobjects; /// FindAmbiguities - Whether Sema::IsDerivedFrom should try find @@ -145,7 +145,7 @@ namespace clang { public: typedef std::list<BasePath>::const_iterator paths_iterator; typedef NamedDecl **decl_iterator; - + /// BasePaths - Construct a new BasePaths structure to record the /// paths for a derived-to-base search. explicit BasePaths(bool FindAmbiguities = true, @@ -153,8 +153,7 @@ namespace clang { bool DetectVirtual = true) : FindAmbiguities(FindAmbiguities), RecordPaths(RecordPaths), DetectVirtual(DetectVirtual), DetectedVirtual(0), DeclsFound(0), - NumDeclsFound(0) - {} + NumDeclsFound(0) { } ~BasePaths() { delete [] DeclsFound; } @@ -208,22 +207,22 @@ namespace clang { LK_NamedMember, LK_OverriddenMember }; - + /// MemberLookupCriteria - Constructs member lookup criteria to /// search for a base class of type Base. - explicit MemberLookupCriteria(QualType Base) + explicit MemberLookupCriteria(QualType Base) : Kind(LK_Base), Base(Base) { } /// MemberLookupCriteria - Constructs member lookup criteria to /// search for a class member with the given Name. - explicit MemberLookupCriteria(DeclarationName Name, + explicit MemberLookupCriteria(DeclarationName Name, Sema::LookupNameKind NameKind, - unsigned IDNS) + unsigned IDNS) : Kind(LK_NamedMember), Name(Name), NameKind(NameKind), IDNS(IDNS) { } explicit MemberLookupCriteria(CXXMethodDecl *MD) : Kind(LK_OverriddenMember), Method(MD) { } - + /// Kind - The kind of lookup we're doing. /// LK_Base if we are looking for a base class (whose /// type is Base). LK_NamedMember if we are looking for a named member of @@ -240,7 +239,7 @@ namespace clang { Sema::LookupNameKind NameKind; unsigned IDNS; - + CXXMethodDecl *Method; }; } diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 877efc31b9..c1f7716330 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -36,7 +36,7 @@ static Expr *IsStringInit(Expr *Init, QualType DeclType, ASTContext &Context) { // See if this is a string literal or @encode. Init = Init->IgnoreParens(); - + // Handle @encode, which is a narrow string. if (isa<ObjCEncodeExpr>(Init) && AT->getElementType()->isCharType()) return Init; @@ -58,26 +58,26 @@ static Expr *IsStringInit(Expr *Init, QualType DeclType, ASTContext &Context) { if (Context.typesAreCompatible(Context.getWCharType(), ElemTy.getUnqualifiedType())) return Init; - + return 0; } -static bool CheckSingleInitializer(Expr *&Init, QualType DeclType, +static bool CheckSingleInitializer(Expr *&Init, QualType DeclType, bool DirectInit, Sema &S) { // Get the type before calling CheckSingleAssignmentConstraints(), since // it can promote the expression. - QualType InitType = Init->getType(); - + QualType InitType = Init->getType(); + if (S.getLangOptions().CPlusPlus) { // FIXME: I dislike this error message. A lot. if (S.PerformImplicitConversion(Init, DeclType, "initializing", DirectInit)) return S.Diag(Init->getSourceRange().getBegin(), diag::err_typecheck_convert_incompatible) - << DeclType << Init->getType() << "initializing" + << DeclType << Init->getType() << "initializing" << Init->getSourceRange(); return false; } - + Sema::AssignConvertType ConvTy = S.CheckSingleAssignmentConstraints(DeclType, Init); return S.DiagnoseAssignmentResult(ConvTy, Init->getLocStart(), DeclType, @@ -89,10 +89,10 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, Sema &S) { uint64_t StrLength = cast<ConstantArrayType>(Str->getType())->getSize().getZExtValue(); - + const ArrayType *AT = S.Context.getAsArrayType(DeclT); if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) { - // C99 6.7.8p14. We have an array of character type with unknown size + // C99 6.7.8p14. We have an array of character type with unknown size // being initialized to a string literal. llvm::APSInt ConstVal(32); ConstVal = StrLength; @@ -102,9 +102,9 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, Sema &S) { ArrayType::Normal, 0); return; } - + const ConstantArrayType *CAT = cast<ConstantArrayType>(AT); - + // C99 6.7.8p14. We have an array of character type with known size. However, // the size may be smaller or larger than the string we are initializing. // FIXME: Avoid truncation for 64-bit length strings. @@ -112,7 +112,7 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, Sema &S) { S.Diag(Str->getSourceRange().getBegin(), diag::warn_initializer_string_for_char_array_too_long) << Str->getSourceRange(); - + // Set the type to the actual size that we are initializing. If we have // something like: // char x[1] = "foo"; @@ -123,26 +123,26 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, Sema &S) { bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType, SourceLocation InitLoc, DeclarationName InitEntity, bool DirectInit) { - if (DeclType->isDependentType() || + if (DeclType->isDependentType() || Init->isTypeDependent() || Init->isValueDependent()) return false; - + // C++ [dcl.init.ref]p1: // A variable declared to be a T& or T&&, that is "reference to type T" // (8.3.2), shall be initialized by an object, or function, of // type T or by an object that can be converted into a T. if (DeclType->isReferenceType()) - return CheckReferenceInit(Init, DeclType, + return CheckReferenceInit(Init, DeclType, /*SuppressUserConversions=*/false, /*AllowExplicit=*/DirectInit, /*ForceRValue=*/false); - + // C99 6.7.8p3: The type of the entity to be initialized shall be an array // of unknown size ("[]") or an object type that is not a variable array type. if (const VariableArrayType *VAT = Context.getAsVariableArrayType(DeclType)) return Diag(InitLoc, diag::err_variable_object_no_init) << VAT->getSizeExpr()->getSourceRange(); - + InitListExpr *InitList = dyn_cast<InitListExpr>(Init); if (!InitList) { // FIXME: Handle wide strings @@ -150,47 +150,47 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType, CheckStringInit(Str, DeclType, *this); return false; } - + // C++ [dcl.init]p14: // -- If the destination type is a (possibly cv-qualified) class // type: if (getLangOptions().CPlusPlus && DeclType->isRecordType()) { QualType DeclTypeC = Context.getCanonicalType(DeclType); QualType InitTypeC = Context.getCanonicalType(Init->getType()); - + // -- If the initialization is direct-initialization, or if it is // copy-initialization where the cv-unqualified version of the // source type is the same class as, or a derived class of, the // class of the destination, constructors are considered. if ((DeclTypeC.getUnqualifiedType() == InitTypeC.getUnqualifiedType()) || IsDerivedFrom(InitTypeC, DeclTypeC)) { - const CXXRecordDecl *RD = + const CXXRecordDecl *RD = cast<CXXRecordDecl>(DeclType->getAs<RecordType>()->getDecl()); - + // No need to make a CXXConstructExpr if both the ctor and dtor are // trivial. if (RD->hasTrivialConstructor() && RD->hasTrivialDestructor()) return false; - - CXXConstructorDecl *Constructor + + CXXConstructorDecl *Constructor = PerformInitializationByConstructor(DeclType, &Init, 1, InitLoc, Init->getSourceRange(), - InitEntity, + InitEntity, DirectInit? IK_Direct : IK_Copy); if (!Constructor) return true; - - OwningExprResult InitResult = + + OwningExprResult InitResult = BuildCXXConstructExpr(/*FIXME:ConstructLoc*/SourceLocation(), - DeclType, Constructor, + DeclType, Constructor, MultiExprArg(*this, (void**)&Init, 1)); if (InitResult.isInvalid()) return true; - + Init = InitResult.takeAs<Expr>(); return false; } - + // -- Otherwise (i.e., for the remaining copy-initialization // cases), user-defined conversion sequences that can // convert from the source type to the destination type or @@ -207,7 +207,7 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType, // have ASTs for such things. if (!PerformImplicitConversion(Init, DeclType, "initializing")) return false; - + if (InitEntity) return Diag(InitLoc, diag::err_cannot_initialize_decl) << InitEntity << (int)(Init->isLvalue(Context) == Expr::LV_Valid) @@ -216,15 +216,15 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType, << DeclType << (int)(Init->isLvalue(Context) == Expr::LV_Valid) << Init->getType() << Init->getSourceRange(); } - + // C99 6.7.8p16. if (DeclType->isArrayType()) return Diag(Init->getLocStart(), diag::err_array_init_list_required) << Init->getSourceRange(); - + return CheckSingleInitializer(Init, DeclType, DirectInit, *this); - } - + } + bool hadError = CheckInitList(InitList, DeclType); Init = InitList; return hadError; @@ -267,8 +267,8 @@ class InitListChecker { bool hadError; std::map<InitListExpr *, InitListExpr *> SyntacticToSemantic; InitListExpr *FullyStructuredList; - - void CheckImplicitInitList(InitListExpr *ParentIList, QualType T, + + void CheckImplicitInitList(InitListExpr *ParentIList, QualType T, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex, bool TopLevelObject = false); @@ -276,41 +276,41 @@ class InitListChecker { unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex, bool TopLevelObject = false); - void CheckListElementTypes(InitListExpr *IList, QualType &DeclType, - bool SubobjectIsDesignatorContext, + void CheckListElementTypes(InitListExpr *IList, QualType &DeclType, + bool SubobjectIsDesignatorContext, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex, bool TopLevelObject = false); - void CheckSubElementType(InitListExpr *IList, QualType ElemType, + void CheckSubElementType(InitListExpr *IList, QualType ElemType, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex); - void CheckScalarType(InitListExpr *IList, QualType DeclType, + void CheckScalarType(InitListExpr *IList, QualType DeclType, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex); - void CheckReferenceType(InitListExpr *IList, QualType DeclType, + void CheckReferenceType(InitListExpr *IList, QualType DeclType, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex); void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex); - void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType, - RecordDecl::field_iterator Field, + void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType, + RecordDecl::field_iterator Field, bool SubobjectIsDesignatorContext, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex, bool TopLevelObject = false); - void CheckArrayType(InitListExpr *IList, QualType &DeclType, - llvm::APSInt elementIndex, + void CheckArrayType(InitListExpr *IList, QualType &DeclType, + llvm::APSInt elementIndex, bool SubobjectIsDesignatorContext, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex); - bool CheckDesignatedInitializer(InitListExpr *IList, DesignatedInitExpr *DIE, + bool CheckDesignatedInitializer(InitListExpr *IList, DesignatedInitExpr *DIE, unsigned DesigIdx, - QualType &CurrentObjectType, + QualType &CurrentObjectType, RecordDecl::field_iterator *NextField, llvm::APSInt *NextElementIndex, unsigned &Index, @@ -344,15 +344,15 @@ public: /// with expressions that perform value-initialization of the /// appropriate type. void InitListChecker::FillInValueInitializations(InitListExpr *ILE) { - assert((ILE->getType() != SemaRef.Context.VoidTy) && + assert((ILE->getType() != SemaRef.Context.VoidTy) && "Should not have void type"); SourceLocation Loc = ILE->getSourceRange().getBegin(); if (ILE->getSyntacticForm()) Loc = ILE->getSyntacticForm()->getSourceRange().getBegin(); - + if (const RecordType *RType = ILE->getType()->getAs<RecordType>()) { unsigned Init = 0, NumInits = ILE->getNumInits(); - for (RecordDecl::field_iterator + for (RecordDecl::field_iterator Field = RType->getDecl()->field_begin(), FieldEnd = RType->getDecl()->field_end(); Field != FieldEnd; ++Field) { @@ -364,11 +364,11 @@ void InitListChecker::FillInValueInitializations(InitListExpr *ILE) { // C++ [dcl.init.aggr]p9: // If an incomplete or empty initializer-list leaves a // member of reference type uninitialized, the program is - // ill-formed. + // ill-formed. SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized) << Field->getType() << ILE->getSyntacticForm()->getSourceRange(); - SemaRef.Diag(Field->getLocation(), + SemaRef.Diag(Field->getLocation(), diag::note_uninit_reference_member); hadError = true; return; @@ -381,9 +381,9 @@ void InitListChecker::FillInValueInitializations(InitListExpr *ILE) { // we make that call explicit in the representation (even when it means // extending the initializer list)? if (Init < NumInits && !hadError) - ILE->setInit(Init, + ILE->setInit(Init, new (SemaRef.Context) ImplicitValueInitExpr(Field->getType())); - } else if (InitListExpr *InnerILE + } else if (InitListExpr *InnerILE = dyn_cast<InitListExpr>(ILE->getInit(Init))) FillInValueInitializations(InnerILE); ++Init; @@ -394,10 +394,10 @@ void InitListChecker::FillInValueInitializations(InitListExpr *ILE) { } return; - } + } QualType ElementType; - + unsigned NumInits = ILE->getNumInits(); unsigned NumElements = NumInits; if (const ArrayType *AType = SemaRef.Context.getAsArrayType(ILE->getType())) { @@ -407,9 +407,9 @@ void InitListChecker::FillInValueInitializations(InitListExpr *ILE) { } else if (const VectorType *VType = ILE->getType()->getAsVectorType()) { ElementType = VType->getElementType(); NumElements = VType->getNumElements(); - } else + } else ElementType = ILE->getType(); - + for (unsigned Init = 0; Init != NumElements; ++Init) { if (Init >= NumInits || !ILE->getInit(Init)) { if (SemaRef.CheckValueInitialization(ElementType, Loc)) { @@ -421,7 +421,7 @@ void InitListChecker::FillInValueInitializations(InitListExpr *ILE) { // we make that call explicit in the representation (even when it means // extending the initializer list)? if (Init < NumInits && !hadError) - ILE->setInit(Init, + ILE->setInit(Init, new (SemaRef.Context) ImplicitValueInitExpr(ElementType)); } else if (InitListExpr *InnerILE = dyn_cast<InitListExpr>(ILE->getInit(Init))) @@ -436,7 +436,7 @@ InitListChecker::InitListChecker(Sema &S, InitListExpr *IL, QualType &T) unsigned newIndex = 0; unsigned newStructuredIndex = 0; - FullyStructuredList + FullyStructuredList = getStructuredSubobjectInit(IL, newIndex, T, 0, 0, IL->getSourceRange()); CheckExplicitInitList(IL, T, newIndex, FullyStructuredList, newStructuredIndex, /*TopLevelObject=*/true); @@ -458,7 +458,7 @@ int InitListChecker::numArrayElements(QualType DeclType) { int InitListChecker::numStructUnionElements(QualType DeclType) { RecordDecl *structDecl = DeclType->getAs<RecordType>()->getDecl(); int InitializableMembers = 0; - for (RecordDecl::field_iterator + for (RecordDecl::field_iterator Field = structDecl->field_begin(), FieldEnd = structDecl->field_end(); Field != FieldEnd; ++Field) { @@ -470,13 +470,13 @@ int InitListChecker::numStructUnionElements(QualType DeclType) { return InitializableMembers - structDecl->hasFlexibleArrayMember(); } -void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList, +void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList, QualType T, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex, bool TopLevelObject) { int maxElements = 0; - + if (T->isArrayType()) maxElements = numArrayElements(T); else if (T->isStructureType() || T->isUnionType()) @@ -496,8 +496,8 @@ void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList, // Build a structured initializer list corresponding to this subobject. InitListExpr *StructuredSubobjectInitList - = getStructuredSubobjectInit(ParentIList, Index, T, StructuredList, - StructuredIndex, + = getStructuredSubobjectInit(ParentIList, Index, T, StructuredList, + StructuredIndex, SourceRange(ParentIList->getInit(Index)->getSourceRange().getBegin(), ParentIList->getSourceRange().getEnd())); unsigned StructuredSubobjectInitIndex = 0; @@ -505,7 +505,7 @@ void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList, // Check the element types and build the structural subobject. unsigned StartIndex = Index; CheckListElementTypes(ParentIList, T, false, Index, - StructuredSubobjectInitList, + StructuredSubobjectInitList, StructuredSubobjectInitIndex, TopLevelObject); unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1); @@ -514,7 +514,7 @@ void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList, // Update the structured sub-object initializer so that it's ending // range corresponds with the end of the last initializer it used. if (EndIndex < ParentIList->getNumInits()) { - SourceLocation EndLoc + SourceLocation EndLoc = ParentIList->getInit(EndIndex)->getSourceRange().getEnd(); StructuredSubobjectInitList->setRBraceLoc(EndLoc); } @@ -528,7 +528,7 @@ void InitListChecker::CheckExplicitInitList(InitListExpr *IList, QualType &T, assert(IList->isExplicit() && "Illegal Implicit InitListExpr"); SyntacticToSemantic[IList] = StructuredList; StructuredList->setSyntacticForm(IList); - CheckListElementTypes(IList, T, true, Index, StructuredList, + CheckListElementTypes(IList, T, true, Index, StructuredList, StructuredIndex, TopLevelObject); IList->setType(T); StructuredList->setType(T); @@ -551,7 +551,7 @@ void InitListChecker::CheckExplicitInitList(InitListExpr *IList, QualType &T, // Don't complain for incomplete types, since we'll get an error // elsewhere QualType CurrentObjectType = StructuredList->getType(); - int initKind = + int initKind = CurrentObjectType->isArrayType()? 0 : CurrentObjectType->isVectorType()? 1 : CurrentObjectType->isScalarType()? 2 : @@ -581,7 +581,7 @@ void InitListChecker::CheckExplicitInitList(InitListExpr *IList, QualType &T, } void InitListChecker::CheckListElementTypes(InitListExpr *IList, - QualType &DeclType, + QualType &DeclType, bool SubobjectIsDesignatorContext, unsigned &Index, InitListExpr *StructuredList, @@ -594,7 +594,7 @@ void InitListChecker::CheckListElementTypes(InitListExpr *IList, } else if (DeclType->isAggregateType()) { if (DeclType->isRecordType()) { RecordDecl *RD = DeclType->getAs<RecordType>()->getDecl(); - CheckStructUnionTypes(IList, DeclType, RD->field_begin(), + CheckStructUnionTypes(IList, DeclType, RD->field_begin(), SubobjectIsDesignatorContext, Index, StructuredList, StructuredIndex, TopLevelObject); @@ -628,13 +628,13 @@ void InitListChecker::CheckListElementTypes(InitListExpr *IList, CheckReferenceType(IList, DeclType, Index, StructuredList, StructuredIndex); } else { // In C, all types are either scalars or aggregates, but - // additional handling is needed here for C++ (and possibly others?). + // additional handling is needed here for C++ (and possibly others?). assert(0 && "Unsupported initializer type"); } } void InitListChecker::CheckSubElementType(InitListExpr *IList, - QualType ElemType, + QualType ElemType, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex) { @@ -642,11 +642,11 @@ void InitListChecker::CheckSubElementType(InitListExpr *IList, if (InitListExpr *SubInitList = dyn_cast<InitListExpr>(expr)) { unsigned newIndex = 0; unsigned newStructuredIndex = 0; - InitListExpr *newStructuredList + InitListExpr *newStructuredList = getStructuredSubobjectInit(IList, Index, ElemType, StructuredList, StructuredIndex, SubInitList->getSourceRange()); - CheckExplicitInitList(SubInitList, ElemType, newIndex, + CheckExplicitInitList(SubInitList, ElemType, newIndex, newStructuredList, newStructuredIndex); ++StructuredIndex; ++Index; @@ -665,14 +665,14 @@ void InitListChecker::CheckSubElementType(InitListExpr *IList, // initializing the aggregate member with an ini- tializer from // an initializer-list. If the initializer can initialize a // member, the member is initialized. [...] - ImplicitConversionSequence ICS + ImplicitConversionSequence ICS = SemaRef.TryCopyInitialization(expr, ElemType, /*SuppressUserConversions=*/false, /*ForceRValue=*/false, /*InOverloadResolution=*/false); if (ICS.ConversionKind != ImplicitConversionSequence::BadConversion) { - if (SemaRef.PerformImplicitConversion(expr, ElemType, ICS, + if (SemaRef.PerformImplicitConversion(expr, ElemType, ICS, "initializing")) hadError = true; UpdateStructuredListElement(StructuredList, StructuredIndex, expr); @@ -682,7 +682,7 @@ void InitListChecker::CheckSubElementType(InitListExpr *IList, // Fall through for subaggregate initialization } else { - // C99 6.7.8p13: + // C99 6.7.8p13: // // The initializer for a structure or union object that has // automatic storage duration shall be either an initializer @@ -701,13 +701,13 @@ void InitListChecker::CheckSubElementType(InitListExpr *IList, } // C++ [dcl.init.aggr]p12: - // + // // [...] Otherwise, if the member is itself a non-empty // subaggregate, brace elision is assumed and the initializer is // considered for the initialization of the first member of // the subaggregate. if (ElemType->isAggregateType() || ElemType->isVectorType()) { - CheckImplicitInitList(IList, ElemType, Index, StructuredList, + CheckImplicitInitList(IList, ElemType, Index, StructuredList, StructuredIndex); ++StructuredIndex; } else { @@ -736,7 +736,7 @@ void InitListChecker::CheckScalarType(InitListExpr *IList, QualType DeclType, ++StructuredIndex; return; } else if (isa<DesignatedInitExpr>(expr)) { - SemaRef.Diag(expr->getSourceRange().getBegin(), + SemaRef.Diag(expr->getSourceRange().getBegin(), diag::err_designator_for_scalar_init) << DeclType << expr->getSourceRange(); hadError = true; @@ -780,13 +780,13 @@ void InitListChecker::CheckReferenceType(InitListExpr *IList, QualType DeclType, ++Index; ++StructuredIndex; return; - } + } Expr *savExpr = expr; // Might be promoted by CheckSingleInitializer. if (SemaRef.CheckReferenceInit(expr, DeclType, /*SuppressUserConversions=*/false, /*AllowExplicit=*/false, - /*ForceRValue=*/false)) + /*ForceRValue=*/false)) hadError = true; else if (savExpr != expr) { // The type was promoted, update initializer list. @@ -802,7 +802,7 @@ void InitListChecker::CheckReferenceType(InitListExpr *IList, QualType DeclType, // general, it would be useful to pass location information down the stack, // so that we know the location (or decl) of the "current object" being // initialized. - SemaRef.Diag(IList->getLocStart(), + SemaRef.Diag(IList->getLocStart(), diag::err_init_reference_member_uninitialized) << DeclType << IList->getSourceRange(); @@ -813,7 +813,7 @@ void InitListChecker::CheckReferenceType(InitListExpr *IList, QualType DeclType, } } -void InitListChecker::CheckVectorType(InitListExpr *IList, QualType DeclType, +void InitListChecker::CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex) { @@ -822,7 +822,7 @@ void InitListChecker::CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned maxElements = VT->getNumElements(); unsigned numEltsInit = 0; QualType elementType = VT->getElementType(); - + if (!SemaRef.getLangOptions().OpenCL) { for (unsigned i = 0; i < maxElements; ++i, ++numEltsInit) { // Don't attempt to go past the end of the init list @@ -853,7 +853,7 @@ void InitListChecker::CheckVectorType(InitListExpr *IList, QualType DeclType, } } } - + // OpenCL & AltiVec require all elements to be initialized. if (numEltsInit != maxElements) if (SemaRef.getLangOptions().OpenCL || SemaRef.getLangOptions().AltiVec) @@ -863,9 +863,9 @@ void InitListChecker::CheckVectorType(InitListExpr *IList, QualType DeclType, } } -void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType, +void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType, llvm::APSInt elementIndex, - bool SubobjectIsDesignatorContext, + bool SubobjectIsDesignatorContext, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex) { @@ -924,7 +924,7 @@ void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType, // Handle this designated initializer. elementIndex will be // updated to be the next array element we'll initialize. - if (CheckDesignatedInitializer(IList, DIE, 0, + if (CheckDesignatedInitializer(IList, DIE, 0, DeclType, 0, &elementIndex, Index, StructuredList, StructuredIndex, true, false)) { @@ -972,27 +972,27 @@ void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType, diag::ext_typecheck_zero_array_size); } - DeclType = SemaRef.Context.getConstantArrayType(elementType, maxElements, + DeclType = SemaRef.Context.getConstantArrayType(elementType, maxElements, ArrayType::Normal, 0); } } -void InitListChecker::CheckStructUnionTypes(InitListExpr *IList, - QualType DeclType, +void InitListChecker::CheckStructUnionTypes(InitListExpr *IList, + QualType DeclType, RecordDecl::field_iterator Field, - bool SubobjectIsDesignatorContext, + bool SubobjectIsDesignatorContext, unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex, bool TopLevelObject) { RecordDecl* structDecl = DeclType->getAs<RecordType>()->getDecl(); - + // If the record is invalid, some of it's members are invalid. To avoid // confusion, we forgo checking the intializer for the entire record. if (structDecl->isInvalidDecl()) { hadError = true; return; - } + } if (DeclType->isUnionType() && IList->getNumInits() == 0) { // Value-initialize the first named member of the union. @@ -1026,7 +1026,7 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList, // Handle this designated initializer. Field will be updated to // the next field that we'll be initializing. - if (CheckDesignatedInitializer(IList, DIE, 0, + if (CheckDesignatedInitializer(IList, DIE, 0, DeclType, &Field, 0, Index, StructuredList, StructuredIndex, true, TopLevelObject)) @@ -1067,15 +1067,15 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList, ++Field; } - if (Field == FieldEnd || !Field->getType()->isIncompleteArrayType() || + if (Field == FieldEnd || !Field->getType()->isIncompleteArrayType() || Index >= IList->getNumInits()) return; // Handle GNU flexible array initializers. - if (!TopLevelObject && + if (!TopLevelObject && (!isa<InitListExpr>(IList->getInit(Index)) || cast<InitListExpr>(IList->getInit(Index))->getNumInits() > 0)) { - SemaRef.Diag(IList->getInit(Index)->getSourceRange().getBegin(), + SemaRef.Diag(IList->getInit(Index)->getSourceRange().getBegin(), diag::err_flexible_array_init_nonempty) << IList->getInit(Index)->getSourceRange().getBegin(); SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member) @@ -1084,7 +1084,7 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList, ++Index; return; } else { - SemaRef.Diag(IList->getInit(Index)->getSourceRange().getBegin(), + SemaRef.Diag(IList->getInit(Index)->getSourceRange().getBegin(), diag::ext_flexible_array_init) << IList->getInit(Index)->getSourceRange().getBegin(); SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member) @@ -1106,8 +1106,8 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList, /// Field/FieldIndex will be updated to point to the (new) /// currently-designated field. static void ExpandAnonymousFieldDesignator(Sema &SemaRef, - DesignatedInitExpr *DIE, - unsigned DesigIdx, + DesignatedInitExpr *DIE, + unsigned DesigIdx, FieldDecl *Field, RecordDecl::field_iterator &FieldIter, unsigned &FieldIndex) { @@ -1117,14 +1117,14 @@ static void ExpandAnonymousFieldDesignator(Sema &SemaRef, // anonymous struct/union (backwards). llvm::SmallVector<FieldDecl *, 4> Path; SemaRef.BuildAnonymousStructUnionMemberPath(Field, Path); - + // Build the replacement designators. llvm::SmallVector<Designator, 4> Replacements; for (llvm::SmallVector<FieldDecl *, 4>::reverse_iterator FI = Path.rbegin(), FIEnd = Path.rend(); FI != FIEnd; ++FI) { if (FI + 1 == FIEnd) - Replacements.push_back(Designator((IdentifierInfo *)0, + Replacements.push_back(Designator((IdentifierInfo *)0, DIE->getDesignator(DesigIdx)->getDotLoc(), DIE->getDesignator(DesigIdx)->getFieldLoc())); else @@ -1136,9 +1136,9 @@ static void ExpandAnonymousFieldDesignator(Sema &SemaRef, // Expand the current designator into the set of replacement // designators, so we have a full subobject path down to where the // member of the anonymous struct/union is actually stored. - DIE->ExpandDesignator(DesigIdx, &Replacements[0], + DIE->ExpandDesignator(DesigIdx, &Replacements[0], &Replacements[0] + Replacements.size()); - + // Update FieldIter/FieldIndex; RecordDecl *Record = cast<RecordDecl>(Path.back()->getDeclContext()); FieldIter = Record->field_begin(); @@ -1163,7 +1163,7 @@ static void ExpandAnonymousFieldDesignator(Sema &SemaRef, /// resides at the given @p Index within the initializer list @p /// IList, is well-formed for a current object of type @p DeclType /// (C99 6.7.8). The actual subobject that this designator refers to -/// within the current subobject is returned in either +/// within the current subobject is returned in either /// @p NextField or @p NextElementIndex (whichever is appropriate). /// /// @param IList The initializer list in which this designated @@ -1192,9 +1192,9 @@ static void ExpandAnonymousFieldDesignator(Sema &SemaRef, /// actually be initialized. /// /// @returns true if there was an error, false otherwise. -bool +bool InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, - DesignatedInitExpr *DIE, + DesignatedInitExpr *DIE, unsigned DesigIdx, QualType &CurrentObjectType, RecordDecl::field_iterator *NextField, @@ -1227,14 +1227,14 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, } bool IsFirstDesignator = (DesigIdx == 0); - assert((IsFirstDesignator || StructuredList) && + assert((IsFirstDesignator || StructuredList) && "Need a non-designated initializer list to start from"); DesignatedInitExpr::Designator *D = DIE->getDesignator(DesigIdx); // Determine the structural initializer list that corresponds to the // current subobject. StructuredList = IsFirstDesignator? SyntacticToSemantic[IList] - : getStructuredSubobjectInit(IList, Index, CurrentObjectType, + : getStructuredSubobjectInit(IList, Index, CurrentObjectType, StructuredList, StructuredIndex, SourceRange(D->getStartLocation(), DIE->getSourceRange().getEnd())); @@ -1249,7 +1249,7 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, // // then the current object (defined below) shall have // structure or union type and the identifier shall be the - // name of a member of that type. + // name of a member of that type. const RecordType *RT = CurrentObjectType->getAs<RecordType>(); if (!RT) { SourceLocation Loc = D->getDotLoc(); @@ -1267,7 +1267,7 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, FieldDecl *KnownField = D->getField(); IdentifierInfo *FieldName = D->getFieldName(); unsigned FieldIndex = 0; - RecordDecl::field_iterator + RecordDecl::field_iterator Field = RT->getDecl()->field_begin(), FieldEnd = RT->getDecl()->field_end(); for (; Field != FieldEnd; ++Field) { @@ -1285,7 +1285,7 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, // name. Perform another lookup for this name, which may find // something that we can't designate (e.g., a member function), // may find nothing, or may find a member of an anonymous - // struct/union. + // struct/union. DeclContext::lookup_result Lookup = RT->getDecl()->lookup(FieldName); if (Lookup.first == Lookup.second) { // Name lookup didn't find anything. @@ -1298,7 +1298,7 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, ->isAnonymousStructOrUnion()) { // Handle an field designator that refers to a member of an // anonymous struct or union. - ExpandAnonymousFieldDesignator(SemaRef, DIE, DesigIdx, + ExpandAnonymousFieldDesignator(SemaRef, DIE, DesigIdx, cast<FieldDecl>(*Lookup.first), Field, FieldIndex); D = DIE->getDesignator(DesigIdx); @@ -1306,7 +1306,7 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, // Name lookup found something, but it wasn't a field. SemaRef.Diag(D->getFieldLoc(), diag::err_field_designator_nonfield) << FieldName; - SemaRef.Diag((*Lookup.first)->getLocation(), + SemaRef.Diag((*Lookup.first)->getLocation(), diag::note_field_designator_found); ++Index; return true; @@ -1328,7 +1328,7 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, // Update the designator with the field declaration. D->setField(*Field); - + // Make sure that our non-designated initializer list has space // for a subobject corresponding to this field. if (FieldIndex >= StructuredList->getNumInits()) @@ -1340,11 +1340,11 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, if ((DesigIdx + 1) != DIE->size()) { // We can't designate an object within the flexible array // member (because GCC doesn't allow it). - DesignatedInitExpr::Designator *NextD + DesignatedInitExpr::Designator *NextD = DIE->getDesignator(DesigIdx + 1); - SemaRef.Diag(NextD->getStartLocation(), + SemaRef.Diag(NextD->getStartLocation(), diag::err_designator_into_flexible_array_member) - << SourceRange(NextD->getStartLocation(), + << SourceRange(NextD->getStartLocation(), DIE->getSourceRange().getEnd()); SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member) << *Field; @@ -1362,9 +1362,9 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, } // Handle GNU flexible array initializers. - if (!Invalid && !TopLevelObject && + if (!Invalid && !TopLevelObject && cast<InitListExpr>(DIE->getInit())->getNumInits() > 0) { - SemaRef.Diag(DIE->getSourceRange().getBegin(), + SemaRef.Diag(DIE->getSourceRange().getBegin(), diag::err_flexible_array_init_nonempty) << DIE->getSourceRange().getBegin(); SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member) @@ -1382,7 +1382,7 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, unsigned newStructuredIndex = FieldIndex; unsigned OldIndex = Index; IList->setInit(Index, DIE->getInit()); - CheckSubElementType(IList, Field->getType(), Index, + CheckSubElementType(IList, Field->getType(), Index, StructuredList, newStructuredIndex); IList->setInit(OldIndex, DIE); if (hadError && !prevHadError) { @@ -1463,10 +1463,10 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, } else { assert(D->isArrayRangeDesignator() && "Need array-range designator"); - - DesignatedStartIndex = + + DesignatedStartIndex = DIE->getArrayRangeStart(*D)->EvaluateAsInt(SemaRef.Context); - DesignatedEndIndex = + DesignatedEndIndex = DIE->getArrayRangeEnd(*D)->EvaluateAsInt(SemaRef.Context); IndexExpr = DIE->getArrayRangeEnd(*D); @@ -1498,11 +1498,11 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, DesignatedStartIndex.setIsUnsigned(true); DesignatedEndIndex.setIsUnsigned(true); } - + // Make sure that our non-designated initializer list has space // for a subobject corresponding to this array element. if (DesignatedEndIndex.getZExtValue() >= StructuredList->getNumInits()) - StructuredList->resizeInits(SemaRef.Context, + StructuredList->resizeInits(SemaRef.Context, DesignatedEndIndex.getZExtValue() + 1); // Repeatedly perform subobject initializations in the range @@ -1534,7 +1534,7 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, StructuredIndex = ElementIndex; return false; } - + if (!FinishSubobjectInit) return false; @@ -1542,7 +1542,7 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList, bool prevHadError = hadError; CheckArrayType(IList, CurrentObjectType, DesignatedStartIndex, false, Index, StructuredList, ElementIndex); - return hadError && !prevHadError; + return hadError && !prevHadError; } // Get the structured initializer list for a subobject of type @@ -1558,7 +1558,7 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index, ExistingInit = SyntacticToSemantic[IList]; else if (StructuredIndex < StructuredList->getNumInits()) ExistingInit = StructuredList->getInit(StructuredIndex); - + if (InitListExpr *Result = dyn_cast_or_null<InitListExpr>(ExistingInit)) return Result; @@ -1567,24 +1567,24 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index, // subobjects of the current object, but there was already an // initialization that completely initialized the current // subobject, e.g., by a compound literal: - // + // // struct X { int a, b; }; // struct X xs[] = { [0] = (struct X) { 1, 2 }, [0].b = 3 }; - // + // // Here, xs[0].a == 0 and xs[0].b == 3, since the second, // designated initializer re-initializes the whole // subobject [0], overwriting previous initializers. - SemaRef.Diag(InitRange.getBegin(), + SemaRef.Diag(InitRange.getBegin(), diag::warn_subobject_initializer_overrides) << InitRange; - SemaRef.Diag(ExistingInit->getSourceRange().getBegin(), + SemaRef.Diag(ExistingInit->getSourceRange().getBegin(), diag::note_previous_initializer) << /*FIXME:has side effects=*/0 << ExistingInit->getSourceRange(); } - InitListExpr *Result - = new (SemaRef.Context) InitListExpr(InitRange.getBegin(), 0, 0, + InitListExpr *Result + = new (SemaRef.Context) InitListExpr(InitRange.getBegin(), 0, 0, InitRange.getEnd()); Result->setType(CurrentObjectType); @@ -1599,7 +1599,7 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index, NumInits = SubList->getNumInits(); } - if (const ArrayType *AType + if (const ArrayType *AType = SemaRef.Context.getAsArrayType(CurrentObjectType)) { if (const ConstantArrayType *CAType = dyn_cast<ConstantArrayType>(AType)) { NumElements = CAType->getSize().getZExtValue(); @@ -1615,7 +1615,7 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index, if (RDecl->isUnion()) NumElements = 1; else - NumElements = std::distance(RDecl->field_begin(), + NumElements = std::distance(RDecl->field_begin(), RDecl->field_end()); } @@ -1647,15 +1647,15 @@ void InitListChecker::UpdateStructuredListElement(InitListExpr *StructuredList, if (Expr *PrevInit = StructuredList->updateInit(StructuredIndex, expr)) { // This initializer overwrites a previous initializer. Warn. - SemaRef.Diag(expr->getSourceRange().getBegin(), + SemaRef.Diag(expr->getSourceRange().getBegin(), diag::warn_initializer_overrides) << expr->getSourceRange(); - SemaRef.Diag(PrevInit->getSourceRange().getBegin(), + SemaRef.Diag(PrevInit->getSourceRange().getBegin(), diag::note_previous_initializer) << /*FIXME:has side effects=*/0 << PrevInit->getSourceRange(); } - + ++StructuredIndex; } @@ -1666,7 +1666,7 @@ void InitListChecker::UpdateStructuredListElement(InitListExpr *StructuredList, /// failure. Returns true if there was an error, false otherwise. If /// everything went okay, Value will receive the value of the constant /// expression. -static bool +static bool CheckArrayDesignatorExpr(Sema &S, Expr *Index, llvm::APSInt &Value) { SourceLocation Loc = Index->getSourceRange().getBegin(); @@ -1697,7 +1697,7 @@ Sema::OwningExprResult Sema::ActOnDesignatedInitializer(Designation &Desig, const Designator &D = Desig.getDesignator(Idx); switch (D.getKind()) { case Designator::FieldDesignator: - Designators.push_back(ASTDesignator(D.getField(), D.getDotLoc(), + Designators.push_back(ASTDesignator(D.getField(), D.getDotLoc(), D.getFieldLoc())); break; @@ -1710,7 +1710,7 @@ Sema::OwningExprResult Sema::ActOnDesignatedInitializer(Designation &Desig, Invalid = true; else { Designators.push_back(ASTDesignator(InitExpressions.size(), - D.getLBracketLoc(), + D.getLBracketLoc(), D.getRBracketLoc())); InitExpressions.push_back(Index); } @@ -1742,12 +1742,12 @@ Sema::OwningExprResult Sema::ActOnDesignatedInitializer(Designation &Desig, if (!StartDependent && !EndDependent && EndValue < StartValue) { Diag(D.getEllipsisLoc(), diag::err_array_designator_empty_range) - << StartValue.toString(10) << EndValue.toString(10) + << StartValue.toString(10) << EndValue.toString(10) << StartIndex->getSourceRange() << EndIndex->getSourceRange(); Invalid = true; } else { Designators.push_back(ASTDesignator(InitExpressions.size(), - D.getLBracketLoc(), + D.getLBracketLoc(), D.getEllipsisLoc(), D.getRBracketLoc())); InitExpressions.push_back(StartIndex); @@ -1792,7 +1792,7 @@ bool Sema::CheckInitList(InitListExpr *&InitList, QualType &DeclType) { /// accessible, non-deleted default constructor. In C, everything can /// be value-initialized, which corresponds to C's notion of /// initializing objects with static storage duration when no -/// initializer is provided for that object. +/// initializer is provided for that object. /// /// \returns true if there was an error, false otherwise. bool Sema::CheckValueInitialization(QualType Type, SourceLocation Loc) { @@ -1814,7 +1814,7 @@ bool Sema::CheckValueInitialization(QualType Type, SourceLocation Loc) { // FIXME: Eventually, we'll need to put the constructor decl into the // AST. return PerformInitializationByConstructor(Type, 0, 0, Loc, - SourceRange(Loc), + SourceRange(Loc), DeclarationName(), IK_Direct); } diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 38abd1641d..44c76a86e0 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -60,7 +60,7 @@ struct UsingDirAncestorCompare { /// AddNamespaceUsingDirectives - Adds all UsingDirectiveDecl's to heap UDirs /// (ordered by common ancestors), found in namespace NS, /// including all found (recursively) in their nominated namespaces. -void AddNamespaceUsingDirectives(ASTContext &Context, +void AddNamespaceUsingDirectives(ASTContext &Context, DeclContext *NS, UsingDirectivesTy &UDirs, NamespaceSet &Visited) { @@ -77,7 +77,7 @@ void AddNamespaceUsingDirectives(ASTContext &Context, /// AddScopeUsingDirectives - Adds all UsingDirectiveDecl's found in Scope S, /// including all found in the namespaces they nominate. -static void AddScopeUsingDirectives(ASTContext &Context, Scope *S, +static void AddScopeUsingDirectives(ASTContext &Context, Scope *S, UsingDirectivesTy &UDirs) { NamespaceSet VisitedNS; @@ -100,7 +100,7 @@ static void AddScopeUsingDirectives(ASTContext &Context, Scope *S, NamespaceDecl *Nominated = UD->getNominatedNamespace(); if (!VisitedNS.count(Nominated)) { VisitedNS.insert(Nominated); - AddNamespaceUsingDirectives(Context, Nominated, UDirs, + AddNamespaceUsingDirectives(Context, Nominated, UDirs, /*ref*/ VisitedNS); } } @@ -112,7 +112,7 @@ static void AddScopeUsingDirectives(ASTContext &Context, Scope *S, /// *I is a match for the namespace. This routine returns an /// appropriate Decl for name lookup, which may either be *I or an /// OverloadedFunctionDecl that represents the overloaded functions in -/// [I, IEnd). +/// [I, IEnd). /// /// The existance of this routine is temporary; users of LookupResult /// should be able to handle multiple results, to deal with cases of @@ -120,10 +120,10 @@ static void AddScopeUsingDirectives(ASTContext &Context, Scope *S, /// Decl node. template<typename DeclIterator> static NamedDecl * -MaybeConstructOverloadSet(ASTContext &Context, +MaybeConstructOverloadSet(ASTContext &Context, DeclIterator I, DeclIterator IEnd) { assert(I != IEnd && "Iterator range cannot be empty"); - assert(!isa<OverloadedFunctionDecl>(*I) && + assert(!isa<OverloadedFunctionDecl>(*I) && "Cannot have an overloaded function"); if ((*I)->isFunctionOrFunctionTemplate()) { @@ -131,8 +131,8 @@ MaybeConstructOverloadSet(ASTContext &Context, // so, collect them into an overload set. DeclIterator Last = I; OverloadedFunctionDecl *Ovl = 0; - for (++Last; - Last != IEnd && (*Last)->isFunctionOrFunctionTemplate(); + for (++Last; + Last != IEnd && (*Last)->isFunctionOrFunctionTemplate(); ++Last) { if (!Ovl) { // FIXME: We leak this overload set. Eventually, we want to stop @@ -153,13 +153,13 @@ MaybeConstructOverloadSet(ASTContext &Context, else Ovl->addOverload(cast<FunctionTemplateDecl>(ND)); } - + // If we had more than one function, we built an overload // set. Return it. if (Ovl) return Ovl; } - + return *I; } @@ -215,7 +215,7 @@ MergeLookupResults(ASTContext &Context, LookupResultsTy &Results) { case LResult::Found: { NamedDecl *ND = I->getAsDecl()->getUnderlyingDecl(); - + if (TagDecl *TD = dyn_cast<TagDecl>(ND)) { TagFound = TD->getCanonicalDecl(); TagNames += FoundDecls.insert(TagFound)? 1 : 0; @@ -234,7 +234,7 @@ MergeLookupResults(ASTContext &Context, LookupResultsTy &Results) { } OrdinaryNonFunc = FoundDecls.size() - TagNames - Functions; bool Ambiguous = false, NameHidesTags = false; - + if (FoundDecls.size() == 1) { // 1) Exactly one result. } else if (TagNames > 1) { @@ -264,7 +264,7 @@ MergeLookupResults(ASTContext &Context, LookupResultsTy &Results) { } if (Ambiguous) - return LResult::CreateLookupResult(Context, + return LResult::CreateLookupResult(Context, FoundDecls.begin(), FoundDecls.size()); if (NameHidesTags) { // There's only one tag, TagFound. Remove it. @@ -281,8 +281,8 @@ MergeLookupResults(ASTContext &Context, LookupResultsTy &Results) { // Retrieve the set of identifier namespaces that correspond to a // specific kind of name lookup. -inline unsigned -getIdentifierNamespacesFromLookupNameKind(Sema::LookupNameKind NameKind, +inline unsigned +getIdentifierNamespacesFromLookupNameKind(Sema::LookupNameKind NameKind, bool CPlusPlus) { unsigned IDNS = 0; switch (NameKind) { @@ -301,7 +301,7 @@ getIdentifierNamespacesFromLookupNameKind(Sema::LookupNameKind NameKind, case Sema::LookupMemberName: IDNS = Decl::IDNS_Member; if (CPlusPlus) - IDNS |= Decl::IDNS_Tag | Decl::IDNS_Ordinary; + IDNS |= Decl::IDNS_Tag | Decl::IDNS_Ordinary; break; case Sema::LookupNestedNameSpecifierName: @@ -328,7 +328,7 @@ Sema::LookupResult Sema::LookupResult::CreateLookupResult(ASTContext &Context, NamedDecl *D) { if (D) D = D->getUnderlyingDecl(); - + LookupResult Result; Result.StoredKind = (D && isa<OverloadedFunctionDecl>(D))? OverloadedDeclSingleDecl : SingleDecl; @@ -340,8 +340,8 @@ Sema::LookupResult::CreateLookupResult(ASTContext &Context, NamedDecl *D) { /// @brief Moves the name-lookup results from Other to this LookupResult. Sema::LookupResult -Sema::LookupResult::CreateLookupResult(ASTContext &Context, - IdentifierResolver::iterator F, +Sema::LookupResult::CreateLookupResult(ASTContext &Context, + IdentifierResolver::iterator F, IdentifierResolver::iterator L) { LookupResult Result; Result.Context = &Context; @@ -355,7 +355,7 @@ Sema::LookupResult::CreateLookupResult(ASTContext &Context, Result.Last = L.getAsOpaqueValue(); return Result; } - } + } NamedDecl *D = *F; if (D) @@ -368,8 +368,8 @@ Sema::LookupResult::CreateLookupResult(ASTContext &Context, } Sema::LookupResult -Sema::LookupResult::CreateLookupResult(ASTContext &Context, - DeclContext::lookup_iterator F, +Sema::LookupResult::CreateLookupResult(ASTContext &Context, + DeclContext::lookup_iterator F, DeclContext::lookup_iterator L) { LookupResult Result; Result.Context = &Context; @@ -388,7 +388,7 @@ Sema::LookupResult::CreateLookupResult(ASTContext &Context, NamedDecl *D = *F; if (D) D = D->getUnderlyingDecl(); - + Result.StoredKind = SingleDecl; Result.First = reinterpret_cast<uintptr_t>(D); Result.Last = 0; @@ -424,7 +424,7 @@ Sema::LookupResult::LookupKind Sema::LookupResult::getKind() const { /// (if only a single declaration was found), an /// OverloadedFunctionDecl (if an overloaded function was found), or /// NULL (if no declaration was found). This conversion must not be -/// used anywhere where name lookup could result in an ambiguity. +/// used anywhere where name lookup could result in an ambiguity. /// /// The OverloadedFunctionDecl conversion is meant as a stop-gap /// solution, since it causes the OverloadedFunctionDecl to be @@ -441,7 +441,7 @@ NamedDecl *Sema::LookupResult::getAsDecl() const { IdentifierResolver::iterator::getFromOpaqueValue(Last)); case OverloadedDeclFromDeclContext: - return MaybeConstructOverloadSet(*Context, + return MaybeConstructOverloadSet(*Context, reinterpret_cast<DeclContext::lookup_iterator>(First), reinterpret_cast<DeclContext::lookup_iterator>(Last)); @@ -450,7 +450,7 @@ NamedDecl *Sema::LookupResult::getAsDecl() const { case AmbiguousLookupStoresDecls: case AmbiguousLookupStoresBasePaths: - assert(false && + assert(false && "Name lookup returned an ambiguity that could not be handled"); break; } @@ -466,7 +466,7 @@ BasePaths *Sema::LookupResult::getBasePaths() const { return 0; } -Sema::LookupResult::iterator::reference +Sema::LookupResult::iterator::reference Sema::LookupResult::iterator::operator*() const { switch (Result->StoredKind) { case SingleDecl: @@ -507,14 +507,14 @@ Sema::LookupResult::iterator& Sema::LookupResult::iterator::operator++() { } case OverloadedDeclFromIdResolver: { - IdentifierResolver::iterator I + IdentifierResolver::iterator I = IdentifierResolver::iterator::getFromOpaqueValue(Current); ++I; Current = I.getAsOpaqueValue(); break; } - case AmbiguousLookupStoresBasePaths: + case AmbiguousLookupStoresBasePaths: if (Result->Last) { NamedDecl ** I = reinterpret_cast<NamedDecl**>(Current); ++I; @@ -526,7 +526,7 @@ Sema::LookupResult::iterator& Sema::LookupResult::iterator::operator++() { case OverloadedDeclFromDeclContext: case AmbiguousLookupStoresDecls: { - DeclContext::lookup_iterator I + DeclContext::lookup_iterator I = reinterpret_cast<DeclContext::lookup_iterator>(Current); ++I; Current = reinterpret_cast<uintptr_t>(I); @@ -548,13 +548,13 @@ Sema::LookupResult::iterator Sema::LookupResult::begin() { case OverloadedDeclSingleDecl: { OverloadedFunctionDecl * Ovl = reinterpret_cast<OverloadedFunctionDecl*>(First); - return iterator(this, + return iterator(this, reinterpret_cast<uintptr_t>(&(*Ovl->function_begin()))); } case AmbiguousLookupStoresBasePaths: if (Last) - return iterator(this, + return iterator(this, reinterpret_cast<uintptr_t>(getBasePaths()->found_decls_begin())); else return iterator(this, @@ -576,13 +576,13 @@ Sema::LookupResult::iterator Sema::LookupResult::end() { case OverloadedDeclSingleDecl: { OverloadedFunctionDecl * Ovl = reinterpret_cast<OverloadedFunctionDecl*>(First); - return iterator(this, + return iterator(this, reinterpret_cast<uintptr_t>(&(*Ovl->function_end()))); } case AmbiguousLookupStoresBasePaths: if (Last) - return iterator(this, + return iterator(this, reinterpret_cast<uintptr_t>(getBasePaths()->found_decls_end())); else return iterator(this, reinterpret_cast<uintptr_t>( @@ -623,7 +623,7 @@ CppNamespaceLookup(ASTContext &Context, DeclContext *NS, llvm::tie(UI, UEnd) = std::equal_range(UDirs->begin(), UDirs->end(), NS, UsingDirAncestorCompare()); - + for (; UI != UEnd; ++UI) CppNamespaceLookup(Context, (*UI)->getNominatedNamespace(), Name, NameKind, IDNS, Results); @@ -641,7 +641,7 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind, bool RedeclarationOnly) { assert(getLangOptions().CPlusPlus && "Can perform only C++ lookup"); - unsigned IDNS + unsigned IDNS = getIdentifierNamespacesFromLookupNameKind(NameKind, /*CPlusPlus*/ true); // If we're testing for redeclarations, also look in the friend namespaces. @@ -652,7 +652,7 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, Scope *Initial = S; DeclContext *OutOfLineCtx = 0; - IdentifierResolver::iterator + IdentifierResolver::iterator I = IdResolver.begin(Name), IEnd = IdResolver.end(); @@ -662,7 +662,7 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, // they were declared in the nearest enclosing namespace which contains // both the using-directive and the nominated namespace. // [Note: in this context, "contains" means "contains directly or - // indirectly". + // indirectly". // // For example: // namespace A { int i; } @@ -705,7 +705,7 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, if (R) return std::make_pair(true, R); } - if (Ctx->getParent() != Ctx->getLexicalParent() + if (Ctx->getParent() != Ctx->getLexicalParent() || isa<CXXMethodDecl>(Ctx)) { // It is out of line defined C++ method or struct, we continue // doing name lookup in parent context. Once we will find namespace @@ -780,7 +780,7 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, if (!S->isDeclScope(DeclPtrTy::make(*LastI))) break; } - + // We store name lookup result, and continue trying to look into // associated context, and maybe namespaces nominated by // using-directives. @@ -834,13 +834,13 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, /// @param Name The name of the entity that we are searching for. /// /// @param Loc If provided, the source location where we're performing -/// name lookup. At present, this is only used to produce diagnostics when +/// name lookup. At present, this is only used to produce diagnostics when /// C library functions (like "malloc") are implicitly declared. /// /// @returns The result of name lookup, which includes zero or more /// declarations and possibly additional information used to diagnose /// ambiguities. -Sema::LookupResult +Sema::LookupResult Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind, bool RedeclarationOnly, bool AllowBuiltinCreation, SourceLocation Loc) { @@ -872,7 +872,7 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind, case Sema::LookupRedeclarationWithLinkage: // Find the nearest non-transparent declaration scope. while (!(S->getFlags() & Scope::DeclScope) || - (S->getEntity() && + (S->getEntity() && static_cast<DeclContext *>(S->getEntity()) ->isTransparentContext())) S = S->getParent(); @@ -886,7 +886,7 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind, case Sema::LookupObjCImplementationName: IDNS = Decl::IDNS_ObjCImplementation; break; - + case Sema::LookupObjCCategoryImplName: IDNS = Decl::IDNS_ObjCCategoryImpl; break; @@ -899,7 +899,7 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind, bool LeftStartingScope = false; for (IdentifierResolver::iterator I = IdResolver.begin(Name), - IEnd = IdResolver.end(); + IEnd = IdResolver.end(); I != IEnd; ++I) if ((*I)->isInIdentifierNamespace(IDNS)) { if (NameKind == LookupRedeclarationWithLinkage) { @@ -948,7 +948,7 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind, // If we didn't find a use of this identifier, and if the identifier // corresponds to a compiler builtin, create the decl object for the builtin // now, injecting it into translation unit scope, and return it. - if (NameKind == LookupOrdinaryName || + if (NameKind == LookupOrdinaryName || NameKind == LookupRedeclarationWithLinkage) { IdentifierInfo *II = Name.getAsIdentifierInfo(); if (II && AllowBuiltinCreation) { @@ -956,7 +956,7 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind, if (unsigned BuiltinID = II->getBuiltinID()) { // In C++, we don't have any predefined library functions like // 'malloc'. Instead, we'll just error. - if (getLangOptions().CPlusPlus && + if (getLangOptions().CPlusPlus && Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) return LookupResult::CreateLookupResult(Context, 0); @@ -1003,18 +1003,18 @@ Sema::LookupResult Sema::LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, LookupNameKind NameKind, bool RedeclarationOnly) { assert(LookupCtx && "Sema::LookupQualifiedName requires a lookup context"); - - if (!Name) + + if (!Name) return LookupResult::CreateLookupResult(Context, 0); - + // If we're performing qualified name lookup (e.g., lookup into a // struct), find fields as part of ordinary name lookup. unsigned IDNS - = getIdentifierNamespacesFromLookupNameKind(NameKind, + = getIdentifierNamespacesFromLookupNameKind(NameKind, getLangOptions().CPlusPlus); if (NameKind == LookupOrdinaryName) IDNS |= Decl::IDNS_Member; - + // Make sure that the declaration context is complete. assert((!isa<TagDecl>(LookupCtx) || LookupCtx->isDependentContext() || @@ -1022,7 +1022,7 @@ Sema::LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, Context.getTypeDeclType(cast<TagDecl>(LookupCtx))->getAs<TagType>() ->isBeingDefined()) && "Declaration context must already be complete!"); - + // Perform qualified name lookup into the LookupCtx. DeclContext::lookup_iterator I, E; for (llvm::tie(I, E) = LookupCtx->lookup(Name); I != E; ++I) @@ -1031,7 +1031,7 @@ Sema::LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, // If this isn't a C++ class, we aren't allowed to look into base // classes, we're done, or the lookup context is dependent, we're done. - if (RedeclarationOnly || !isa<CXXRecordDecl>(LookupCtx) || + if (RedeclarationOnly || !isa<CXXRecordDecl>(LookupCtx) || LookupCtx->isDependentContext()) return LookupResult::CreateLookupResult(Context, 0); @@ -1040,7 +1040,7 @@ Sema::LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, Paths.setOrigin(Context.getTypeDeclType(cast<RecordDecl>(LookupCtx))); // Look for this member in our base classes - if (!LookupInBases(cast<CXXRecordDecl>(LookupCtx), + if (!LookupInBases(cast<CXXRecordDecl>(LookupCtx), MemberLookupCriteria(Name, NameKind, IDNS), Paths)) return LookupResult::CreateLookupResult(Context, 0); @@ -1062,7 +1062,7 @@ Sema::LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, // This is the first subobject we've looked at. Record it's type. SubobjectType = Context.getCanonicalType(PathElement.Base->getType()); SubobjectNumber = PathElement.SubobjectNumber; - } else if (SubobjectType + } else if (SubobjectType != Context.getCanonicalType(PathElement.Base->getType())) { // We found members of the given name in two subobjects of // different types. This lookup is ambiguous. @@ -1075,7 +1075,7 @@ Sema::LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, // C++ [class.member.lookup]p5: // A static member, a nested type or an enumerator defined in // a base class T can unambiguously be found even if an object - // has more than one base class subobject of type T. + // has more than one base class subobject of type T. Decl *FirstDecl = *Path->Decls.first; if (isa<VarDecl>(FirstDecl) || isa<TypeDecl>(FirstDecl) || @@ -1114,7 +1114,7 @@ Sema::LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, // If we found a function declaration, return an overload set. if ((*Paths.front().Decls.first)->isFunctionOrFunctionTemplate()) - return LookupResult::CreateLookupResult(Context, + return LookupResult::CreateLookupResult(Context, Paths.front().Decls.first, Paths.front().Decls.second); // We found a non-function declaration; return a single declaration. @@ -1132,14 +1132,14 @@ Sema::LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, /// /// @param S The scope from which unqualified name lookup will /// begin. -/// +/// /// @param SS An optional C++ scope-specifier, e.g., "::N::M". /// /// @param Name The name of the entity that name lookup will /// search for. /// /// @param Loc If provided, the source location where we're performing -/// name lookup. At present, this is only used to produce diagnostics when +/// name lookup. At present, this is only used to produce diagnostics when /// C library functions (like "malloc") are implicitly declared. /// /// @param EnteringContext Indicates whether we are going to enter the @@ -1147,7 +1147,7 @@ Sema::LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, /// /// @returns The result of qualified or unqualified name lookup. Sema::LookupResult -Sema::LookupParsedName(Scope *S, const CXXScopeSpec *SS, +Sema::LookupParsedName(Scope *S, const CXXScopeSpec *SS, DeclarationName Name, LookupNameKind NameKind, bool RedeclarationOnly, bool AllowBuiltinCreation, SourceLocation Loc, @@ -1157,25 +1157,25 @@ Sema::LookupParsedName(Scope *S, const CXXScopeSpec *SS, // anything. return LookupResult::CreateLookupResult(Context, 0); } - + if (SS && SS->isSet()) { if (DeclContext *DC = computeDeclContext(*SS, EnteringContext)) { - // We have resolved the scope specifier to a particular declaration + // We have resolved the scope specifier to a particular declaration // contex, and will perform name lookup in that context. if (!DC->isDependentContext() && RequireCompleteDeclContext(*SS)) return LookupResult::CreateLookupResult(Context, 0); - + return LookupQualifiedName(DC, Name, NameKind, RedeclarationOnly); } // We could not resolve the scope specified to a specific declaration - // context, which means that SS refers to an unknown specialization. + // context, which means that SS refers to an unknown specialization. // Name lookup can't find anything in this case. return LookupResult::CreateLookupResult(Context, 0); } - // Perform unqualified name lookup starting in the given scope. - return LookupName(S, Name, NameKind, RedeclarationOnly, AllowBuiltinCreation, + // Perform unqualified name lookup starting in the given scope. + return LookupName(S, Name, NameKind, RedeclarationOnly, AllowBuiltinCreation, Loc); } @@ -1184,7 +1184,7 @@ Sema::LookupParsedName(Scope *S, const CXXScopeSpec *SS, /// from name lookup. /// /// @param Result The ambiguous name lookup result. -/// +/// /// @param Name The name of the entity that name lookup was /// searching for. /// @@ -1197,7 +1197,7 @@ Sema::LookupParsedName(Scope *S, const CXXScopeSpec *SS, /// /// @returns true bool Sema::DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name, - SourceLocation NameLoc, + SourceLocation NameLoc, SourceRange LookupRange) { assert(Result.isAmbiguous() && "Lookup result must be ambiguous"); @@ -1209,7 +1209,7 @@ bool Sema::DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name, << LookupRange; DeclContext::lookup_iterator Found = Paths->front().Decls.first; - while (isa<CXXMethodDecl>(*Found) && + while (isa<CXXMethodDecl>(*Found) && cast<CXXMethodDecl>(*Found)->isStatic()) ++Found; @@ -1217,7 +1217,7 @@ bool Sema::DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name, Result.Destroy(); return true; - } + } assert(Result.getKind() == LookupResult::AmbiguousBaseSubobjectTypes && "Unhandled form of name lookup ambiguity"); @@ -1254,8 +1254,8 @@ bool Sema::DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name, return true; } -static void -addAssociatedClassesAndNamespaces(QualType T, +static void +addAssociatedClassesAndNamespaces(QualType T, ASTContext &Context, Sema::AssociatedNamespaceSet &AssociatedNamespaces, Sema::AssociatedClassSet &AssociatedClasses); @@ -1266,19 +1266,19 @@ static void CollectNamespace(Sema::AssociatedNamespaceSet &Namespaces, Namespaces.insert(Ctx); } -// \brief Add the associated classes and namespaces for argument-dependent +// \brief Add the associated classes and namespaces for argument-dependent // lookup that involves a template argument (C++ [basic.lookup.koenig]p2). -static void -addAssociatedClassesAndNamespaces(const TemplateArgument &Arg, +static void +addAssociatedClassesAndNamespaces(const TemplateArgument &Arg, ASTContext &Context, Sema::AssociatedNamespaceSet &AssociatedNamespaces, Sema::AssociatedClassSet &AssociatedClasses) { // C++ [basic.lookup.koenig]p2, last bullet: - // -- [...] ; + // -- [...] ; switch (Arg.getKind()) { case TemplateArgument::Null: break; - + case TemplateArgument::Type: // [...] the namespaces and classes associated with the types of the // template arguments provided for template type parameters (excluding @@ -1287,12 +1287,12 @@ addAssociatedClassesAndNamespaces(const TemplateArgument &Arg, AssociatedNamespaces, AssociatedClasses); break; - + case TemplateArgument::Declaration: - // [...] the namespaces in which any template template arguments are - // defined; and the classes in which any member templates used as + // [...] the namespaces in which any template template arguments are + // defined; and the classes in which any member templates used as // template template arguments are defined. - if (ClassTemplateDecl *ClassTemplate + if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(Arg.getAsDecl())) { DeclContext *Ctx = ClassTemplate->getDeclContext(); if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx)) @@ -1303,13 +1303,13 @@ addAssociatedClassesAndNamespaces(const TemplateArgument &Arg, CollectNamespace(AssociatedNamespaces, Ctx); } break; - + case TemplateArgument::Integral: case TemplateArgument::Expression: - // [Note: non-type template arguments do not contribute to the set of + // [Note: non-type template arguments do not contribute to the set of // associated namespaces. ] break; - + case TemplateArgument::Pack: for (TemplateArgument::pack_iterator P = Arg.pack_begin(), PEnd = Arg.pack_end(); @@ -1322,10 +1322,10 @@ addAssociatedClassesAndNamespaces(const TemplateArgument &Arg, } // \brief Add the associated classes and namespaces for -// argument-dependent lookup with an argument of class type -// (C++ [basic.lookup.koenig]p2). -static void -addAssociatedClassesAndNamespaces(CXXRecordDecl *Class, +// argument-dependent lookup with an argument of class type +// (C++ [basic.lookup.koenig]p2). +static void +addAssociatedClassesAndNamespaces(CXXRecordDecl *Class, ASTContext &Context, Sema::AssociatedNamespaceSet &AssociatedNamespaces, Sema::AssociatedClassSet &AssociatedClasses) { @@ -1335,7 +1335,7 @@ addAssociatedClassesAndNamespaces(CXXRecordDecl *Class, // classes are: the class itself; the class of which it is a // member, if any; and its direct and indirect base // classes. Its associated namespaces are the namespaces in - // which its associated classes are defined. + // which its associated classes are defined. // Add the class of which it is a member, if any. DeclContext *Ctx = Class->getDeclContext(); @@ -1345,22 +1345,22 @@ addAssociatedClassesAndNamespaces(CXXRecordDecl *Class, while (Ctx->isRecord()) Ctx = Ctx->getParent(); CollectNamespace(AssociatedNamespaces, Ctx); - + // Add the class itself. If we've already seen this class, we don't // need to visit base classes. if (!AssociatedClasses.insert(Class)) return; - // -- If T is a template-id, its associated namespaces and classes are - // the namespace in which the template is defined; for member + // -- If T is a template-id, its associated namespaces and classes are + // the namespace in which the template is defined; for member // templates, the member template’s class; the namespaces and classes - // associated with the types of the template arguments provided for + // associated with the types of the template arguments provided for // template type parameters (excluding template template parameters); the - // namespaces in which any template template arguments are defined; and - // the classes in which any member templates used as template template - // arguments are defined. [Note: non-type template arguments do not + // namespaces in which any template template arguments are defined; and + // the classes in which any member templates used as template template + // arguments are defined. [Note: non-type template arguments do not // contribute to the set of associated namespaces. ] - if (ClassTemplateSpecializationDecl *Spec + if (ClassTemplateSpecializationDecl *Spec = dyn_cast<ClassTemplateSpecializationDecl>(Class)) { DeclContext *Ctx = Spec->getSpecializedTemplate()->getDeclContext(); if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx)) @@ -1369,14 +1369,14 @@ addAssociatedClassesAndNamespaces(CXXRecordDecl *Class, while (Ctx->isRecord()) Ctx = Ctx->getParent(); CollectNamespace(AssociatedNamespaces, Ctx); - + const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) addAssociatedClassesAndNamespaces(TemplateArgs[I], Context, AssociatedNamespaces, AssociatedClasses); } - + // Add direct and indirect base classes along with their associated // namespaces. llvm::SmallVector<CXXRecordDecl *, 32> Bases; @@ -1409,9 +1409,9 @@ addAssociatedClassesAndNamespaces(CXXRecordDecl *Class, // \brief Add the associated classes and namespaces for // argument-dependent lookup with an argument of type T -// (C++ [basic.lookup.koenig]p2). -static void -addAssociatedClassesAndNamespaces(QualType T, +// (C++ [basic.lookup.koenig]p2). +static void +addAssociatedClassesAndNamespaces(QualType T, ASTContext &Context, Sema::AssociatedNamespaceSet &AssociatedNamespaces, Sema::AssociatedClassSet &AssociatedClasses) { @@ -1428,7 +1428,7 @@ addAssociatedClassesAndNamespaces(QualType T, T = Context.getCanonicalType(T).getUnqualifiedType(); // -- If T is a pointer to U or an array of U, its associated - // namespaces and classes are those associated with U. + // namespaces and classes are those associated with U. // // We handle this by unwrapping pointer and array types immediately, // to avoid unnecessary recursion. @@ -1437,7 +1437,7 @@ addAssociatedClassesAndNamespaces(QualType T, T = Ptr->getPointeeType(); else if (const ArrayType *Ptr = Context.getAsArrayType(T)) T = Ptr->getElementType(); - else + else break; } @@ -1450,12 +1450,12 @@ addAssociatedClassesAndNamespaces(QualType T, // classes are: the class itself; the class of which it is a // member, if any; and its direct and indirect base // classes. Its associated namespaces are the namespaces in - // which its associated classes are defined. + // which its associated classes are defined. if (const RecordType *ClassType = T->getAs<RecordType>()) - if (CXXRecordDecl *ClassDecl + if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(ClassType->getDecl())) { - addAssociatedClassesAndNamespaces(ClassDecl, Context, - AssociatedNamespaces, + addAssociatedClassesAndNamespaces(ClassDecl, Context, + AssociatedNamespaces, AssociatedClasses); return; } @@ -1463,7 +1463,7 @@ addAssociatedClassesAndNamespaces(QualType T, // -- If T is an enumeration type, its associated namespace is // the namespace in which it is defined. If it is class // member, its associated class is the member’s class; else - // it has no associated class. + // it has no associated class. if (const EnumType *EnumT = T->getAsEnumType()) { EnumDecl *Enum = EnumT->getDecl(); @@ -1484,7 +1484,7 @@ addAssociatedClassesAndNamespaces(QualType T, // types and those associated with the return type. if (const FunctionType *FunctionType = T->getAsFunctionType()) { // Return type - addAssociatedClassesAndNamespaces(FunctionType->getResultType(), + addAssociatedClassesAndNamespaces(FunctionType->getResultType(), Context, AssociatedNamespaces, AssociatedClasses); @@ -1494,23 +1494,23 @@ addAssociatedClassesAndNamespaces(QualType T, // Argument types for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(), - ArgEnd = Proto->arg_type_end(); + ArgEnd = Proto->arg_type_end(); Arg != ArgEnd; ++Arg) addAssociatedClassesAndNamespaces(*Arg, Context, AssociatedNamespaces, AssociatedClasses); - + return; } // -- If T is a pointer to a member function of a class X, its // associated namespaces and classes are those associated // with the function parameter types and return type, - // together with those associated with X. + // together with those associated with X. // // -- If T is a pointer to a data member of class X, its // associated namespaces and classes are those associated // with the member type together with those associated with - // X. + // X. if (const MemberPointerType *MemberPtr = T->getAs<MemberPointerType>()) { // Handle the type that the pointer to member points to. addAssociatedClassesAndNamespaces(MemberPtr->getPointeeType(), @@ -1537,9 +1537,9 @@ addAssociatedClassesAndNamespaces(QualType T, /// arguments. /// /// This routine computes the sets of associated classes and associated -/// namespaces searched by argument-dependent lookup +/// namespaces searched by argument-dependent lookup /// (C++ [basic.lookup.argdep]) for a given set of arguments. -void +void Sema::FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs, AssociatedNamespaceSet &AssociatedNamespaces, AssociatedClassSet &AssociatedClasses) { @@ -1552,7 +1552,7 @@ Sema::FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs, // associated classes to be considered. The sets of namespaces and // classes is determined entirely by the types of the function // arguments (and the namespace of any template template - // argument). + // argument). for (unsigned ArgIdx = 0; ArgIdx != NumArgs; ++ArgIdx) { Expr *Arg = Args[ArgIdx]; @@ -1582,7 +1582,7 @@ Sema::FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs, DRE = dyn_cast<DeclRefExpr>(Arg); TIRE = dyn_cast<TemplateIdRefExpr>(Arg); } - + OverloadedFunctionDecl *Ovl = 0; if (DRE) Ovl = dyn_cast<OverloadedFunctionDecl>(DRE->getDecl()); @@ -1618,7 +1618,7 @@ Sema::FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs, /// arguments have types T1 (and, if non-empty, T2). This routine /// implements the check in C++ [over.match.oper]p3b2 concerning /// enumeration types. -static bool +static bool IsAcceptableNonMemberOperatorCandidate(FunctionDecl *Fn, QualType T1, QualType T2, ASTContext &Context) { @@ -1686,7 +1686,7 @@ Decl *Sema::LookupQualifiedNameWithType(DeclContext *DC, } void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, - QualType T1, QualType T2, + QualType T1, QualType T2, FunctionSet &Functions) { // C++ [over.match.oper]p3: // -- The set of non-member candidates is the result of the @@ -1702,7 +1702,7 @@ void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, // when T2 is an enumeration type, are candidate functions. DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(Op); LookupResult Operators = LookupName(S, OpName, LookupOperatorName); - + assert(!Operators.isAmbiguous() && "Operator lookup cannot be ambiguous"); if (!Operators) @@ -1713,10 +1713,10 @@ void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*Op)) { if (IsAcceptableNonMemberOperatorCandidate(FD, T1, T2, Context)) Functions.insert(FD); // FIXME: canonical FD - } else if (FunctionTemplateDecl *FunTmpl + } else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(*Op)) { // FIXME: friend operators? - // FIXME: do we need to check IsAcceptableNonMemberOperatorCandidate, + // FIXME: do we need to check IsAcceptableNonMemberOperatorCandidate, // later? if (!FunTmpl->getDeclContext()->isRecord()) Functions.insert(FunTmpl); @@ -1739,7 +1739,7 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, // arguments we have. AssociatedNamespaceSet AssociatedNamespaces; AssociatedClassSet AssociatedClasses; - FindAssociatedClassesAndNamespaces(Args, NumArgs, + FindAssociatedClassesAndNamespaces(Args, NumArgs, AssociatedNamespaces, AssociatedClasses); @@ -1755,8 +1755,8 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, // Here, we compute Y and add its members to the overloaded // candidate set. for (AssociatedNamespaceSet::iterator NS = AssociatedNamespaces.begin(), - NSEnd = AssociatedNamespaces.end(); - NS != NSEnd; ++NS) { + NSEnd = AssociatedNamespaces.end(); + NS != NSEnd; ++NS) { // When considering an associated namespace, the lookup is the // same as the lookup performed when the associated namespace is // used as a qualifier (3.4.3.2) except that: @@ -1778,7 +1778,7 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, if (!AssociatedClasses.count(cast<CXXRecordDecl>(LexDC))) continue; } - + CollectFunctionDecl(Functions, D); } } diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 1427d48bc2..c5bbd34af8 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -30,7 +30,7 @@ namespace clang { /// GetConversionCategory - Retrieve the implicit conversion /// category corresponding to the given implicit conversion kind. -ImplicitConversionCategory +ImplicitConversionCategory GetConversionCategory(ImplicitConversionKind Kind) { static const ImplicitConversionCategory Category[(int)ICK_Num_Conversion_Kinds] = { @@ -138,10 +138,9 @@ ImplicitConversionRank StandardConversionSequence::getRank() const { /// isPointerConversionToBool - Determines whether this conversion is /// a conversion of a pointer or pointer-to-member to bool. This is -/// used as part of the ranking of standard conversion sequences +/// used as part of the ranking of standard conversion sequences /// (C++ 13.3.3.2p4). -bool StandardConversionSequence::isPointerConversionToBool() const -{ +bool StandardConversionSequence::isPointerConversionToBool() const { QualType FromType = QualType::getFromOpaquePtr(FromTypePtr); QualType ToType = QualType::getFromOpaquePtr(ToTypePtr); @@ -161,10 +160,9 @@ bool StandardConversionSequence::isPointerConversionToBool() const /// conversion is a conversion of a pointer to a void pointer. This is /// used as part of the ranking of standard conversion sequences (C++ /// 13.3.3.2p4). -bool +bool StandardConversionSequence:: -isPointerConversionToVoidPointer(ASTContext& Context) const -{ +isPointerConversionToVoidPointer(ASTContext& Context) const { QualType FromType = QualType::getFromOpaquePtr(FromTypePtr); QualType ToType = QualType::getFromOpaquePtr(ToTypePtr); @@ -262,7 +260,7 @@ void ImplicitConversionSequence::DebugPrint() const { // same signature (C++ 1.3.10) or if the Old declaration isn't a // function (or overload set). When it does return false and Old is an // OverloadedFunctionDecl, MatchedDecl will be set to point to the -// FunctionDecl that New cannot be overloaded with. +// FunctionDecl that New cannot be overloaded with. // // Example: Given the following input: // @@ -271,7 +269,7 @@ void ImplicitConversionSequence::DebugPrint() const { // int f(int, int); // #3 // // When we process #1, there is no previous declaration of "f", -// so IsOverload will not be used. +// so IsOverload will not be used. // // When we process #2, Old is a FunctionDecl for #1. By comparing the // parameter types, we see that #1 and #2 are overloaded (since they @@ -285,9 +283,8 @@ void ImplicitConversionSequence::DebugPrint() const { // signature), IsOverload returns false and MatchedDecl will be set to // point to the FunctionDecl for #2. bool -Sema::IsOverload(FunctionDecl *New, Decl* OldD, - OverloadedFunctionDecl::function_iterator& MatchedDecl) -{ +Sema::IsOverload(FunctionDecl *New, Decl* OldD, + OverloadedFunctionDecl::function_iterator& MatchedDecl) { if (OverloadedFunctionDecl* Ovl = dyn_cast<OverloadedFunctionDecl>(OldD)) { // Is this new function an overload of every function in the // overload set? @@ -306,8 +303,8 @@ Sema::IsOverload(FunctionDecl *New, Decl* OldD, return IsOverload(New, Old->getTemplatedDecl(), MatchedDecl); else if (FunctionDecl* Old = dyn_cast<FunctionDecl>(OldD)) { FunctionTemplateDecl *OldTemplate = Old->getDescribedFunctionTemplate(); - FunctionTemplateDecl *NewTemplate = New->getDescribedFunctionTemplate(); - + FunctionTemplateDecl *NewTemplate = New->getDescribedFunctionTemplate(); + // C++ [temp.fct]p2: // A function template can be overloaded with other function templates // and with normal (non-template) functions. @@ -342,21 +339,21 @@ Sema::IsOverload(FunctionDecl *New, Decl* OldD, return true; // C++ [temp.over.link]p4: - // The signature of a function template consists of its function + // The signature of a function template consists of its function // signature, its return type and its template parameter list. The names // of the template parameters are significant only for establishing the - // relationship between the template parameters and the rest of the + // relationship between the template parameters and the rest of the // signature. // // We check the return type and template parameter lists for function // templates first; the remaining checks follow. if (NewTemplate && - (!TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(), - OldTemplate->getTemplateParameters(), + (!TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(), + OldTemplate->getTemplateParameters(), false, false, SourceLocation()) || OldType->getResultType() != NewType->getResultType())) return true; - + // If the function is a class member, its signature includes the // cv-qualifiers (if any) on the function itself. // @@ -367,7 +364,7 @@ Sema::IsOverload(FunctionDecl *New, Decl* OldD, // can be overloaded. CXXMethodDecl* OldMethod = dyn_cast<CXXMethodDecl>(Old); CXXMethodDecl* NewMethod = dyn_cast<CXXMethodDecl>(New); - if (OldMethod && NewMethod && + if (OldMethod && NewMethod && !OldMethod->isStatic() && !NewMethod->isStatic() && OldMethod->getTypeQualifiers() != NewMethod->getTypeQualifiers()) return true; @@ -411,13 +408,12 @@ ImplicitConversionSequence Sema::TryImplicitConversion(Expr* From, QualType ToType, bool SuppressUserConversions, bool AllowExplicit, bool ForceRValue, - bool InOverloadResolution) -{ + bool InOverloadResolution) { ImplicitConversionSequence ICS; if (IsStandardConversion(From, ToType, InOverloadResolution, ICS.Standard)) ICS.ConversionKind = ImplicitConversionSequence::StandardConversion; else if (getLangOptions().CPlusPlus && - IsUserDefinedConversion(From, ToType, ICS.UserDefined, + IsUserDefinedConversion(From, ToType, ICS.UserDefined, !SuppressUserConversions, AllowExplicit, ForceRValue)) { ICS.ConversionKind = ImplicitConversionSequence::UserDefinedConversion; @@ -428,9 +424,9 @@ Sema::TryImplicitConversion(Expr* From, QualType ToType, // given Conversion rank, in spite of the fact that a copy // constructor (i.e., a user-defined conversion function) is // called for those cases. - if (CXXConstructorDecl *Constructor + if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(ICS.UserDefined.ConversionFunction)) { - QualType FromCanon + QualType FromCanon = Context.getCanonicalType(From->getType().getUnqualifiedType()); QualType ToCanon = Context.getCanonicalType(ToType).getUnqualifiedType(); if (FromCanon == ToCanon || IsDerivedFrom(FromCanon, ToCanon)) { @@ -470,11 +466,10 @@ Sema::TryImplicitConversion(Expr* From, QualType ToType, /// contain the standard conversion sequence required to perform this /// conversion and this routine will return true. Otherwise, this /// routine will return false and the value of SCS is unspecified. -bool -Sema::IsStandardConversion(Expr* From, QualType ToType, +bool +Sema::IsStandardConversion(Expr* From, QualType ToType, bool InOverloadResolution, - StandardConversionSequence &SCS) -{ + StandardConversionSequence &SCS) { QualType FromType = From->getType(); // Standard conversions (C++ [conv]) @@ -485,23 +480,23 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, SCS.CopyConstructor = 0; // There are no standard conversions for class types in C++, so - // abort early. When overloading in C, however, we do permit + // abort early. When overloading in C, however, we do permit if (FromType->isRecordType() || ToType->isRecordType()) { if (getLangOptions().CPlusPlus) return false; - // When we're overloading in C, we allow, as standard conversions, + // When we're overloading in C, we allow, as standard conversions, } // The first conversion can be an lvalue-to-rvalue conversion, // array-to-pointer conversion, or function-to-pointer conversion // (C++ 4p1). - // Lvalue-to-rvalue conversion (C++ 4.1): + // Lvalue-to-rvalue conversion (C++ 4.1): // An lvalue (3.10) of a non-function, non-array type T can be // converted to an rvalue. Expr::isLvalueResult argIsLvalue = From->isLvalue(Context); - if (argIsLvalue == Expr::LV_Valid && + if (argIsLvalue == Expr::LV_Valid && !FromType->isFunctionType() && !FromType->isArrayType() && Context.getCanonicalType(FromType) != Context.OverloadTy) { SCS.First = ICK_Lvalue_To_Rvalue; @@ -543,7 +538,7 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, // type "pointer to T." The result is a pointer to the // function. (C++ 4.3p1). FromType = Context.getPointerType(FromType); - } else if (FunctionDecl *Fn + } else if (FunctionDecl *Fn = ResolveAddressOfOverloadedFunction(From, ToType, false)) { // Address of overloaded function (C++ [over.over]). SCS.First = ICK_Function_To_Pointer; @@ -584,7 +579,7 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, // conversion to do. SCS.Second = ICK_Identity; } else if (IsIntegralPromotion(From, FromType, ToType)) { - // Integral promotion (C++ 4.5). + // Integral promotion (C++ 4.5). SCS.Second = ICK_Integral_Promotion; FromType = ToType.getUnqualifiedType(); } else if (IsFloatingPointPromotion(FromType, ToType)) { @@ -612,7 +607,7 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, } else if ((FromType->isFloatingType() && ToType->isIntegralType() && (!ToType->isBooleanType() && !ToType->isEnumeralType())) || - ((FromType->isIntegralType() || FromType->isEnumeralType()) && + ((FromType->isIntegralType() || FromType->isEnumeralType()) && ToType->isFloatingType())) { // Floating-integral conversions (C++ 4.9). // FIXME: isIntegralType shouldn't be true for enums in C++. @@ -641,7 +636,7 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, // Boolean conversions (C++ 4.12). SCS.Second = ICK_Boolean_Conversion; FromType = Context.BoolTy; - } else if (!getLangOptions().CPlusPlus && + } else if (!getLangOptions().CPlusPlus && Context.typesAreCompatible(ToType, FromType)) { // Compatible conversions (Clang extension for C function overloading) SCS.Second = ICK_Compatible_Conversion; @@ -662,12 +657,12 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, // No conversion required SCS.Third = ICK_Identity; - // C++ [over.best.ics]p6: + // C++ [over.best.ics]p6: // [...] Any difference in top-level cv-qualification is // subsumed by the initialization itself and does not constitute // a conversion. [...] CanonFrom = Context.getCanonicalType(FromType); - CanonTo = Context.getCanonicalType(ToType); + CanonTo = Context.getCanonicalType(ToType); if (CanonFrom.getUnqualifiedType() == CanonTo.getUnqualifiedType() && CanonFrom.getCVRQualifiers() != CanonTo.getCVRQualifiers()) { FromType = ToType; @@ -688,8 +683,7 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, /// expression From (whose potentially-adjusted type is FromType) to /// ToType is an integral promotion (C++ 4.5). If so, returns true and /// sets PromotedType to the promoted type. -bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) -{ +bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) { const BuiltinType *To = ToType->getAsBuiltinType(); // All integers are built-in. if (!To) { @@ -706,7 +700,7 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) (FromType->isSignedIntegerType() || // We can promote any unsigned integer type whose size is // less than int to an int. - (!FromType->isSignedIntegerType() && + (!FromType->isSignedIntegerType() && Context.getTypeSize(FromType) < Context.getTypeSize(ToType)))) { return To->getKind() == BuiltinType::Int; } @@ -734,15 +728,15 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) // The types we'll try to promote to, in the appropriate // order. Try each of these types. - QualType PromoteTypes[6] = { - Context.IntTy, Context.UnsignedIntTy, + QualType PromoteTypes[6] = { + Context.IntTy, Context.UnsignedIntTy, Context.LongTy, Context.UnsignedLongTy , Context.LongLongTy, Context.UnsignedLongLongTy }; for (int Idx = 0; Idx < 6; ++Idx) { uint64_t ToSize = Context.getTypeSize(PromoteTypes[Idx]); if (FromSize < ToSize || - (FromSize == ToSize && + (FromSize == ToSize && FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) { // We found the type that we can promote to. If this is the // type we wanted, we have a promotion. Otherwise, no @@ -770,23 +764,23 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) MemberDecl->getBitWidth()->isIntegerConstantExpr(BitWidth, Context)) { APSInt ToSize(BitWidth.getBitWidth(), BitWidth.isUnsigned()); ToSize = Context.getTypeSize(ToType); - + // Are we promoting to an int from a bitfield that fits in an int? if (BitWidth < ToSize || (FromType->isSignedIntegerType() && BitWidth <= ToSize)) { return To->getKind() == BuiltinType::Int; } - + // Are we promoting to an unsigned int from an unsigned bitfield // that fits into an unsigned int? if (FromType->isUnsignedIntegerType() && BitWidth <= ToSize) { return To->getKind() == BuiltinType::UInt; } - + return false; } } - + // An rvalue of type bool can be converted to an rvalue of type int, // with false becoming zero and true becoming one (C++ 4.5p4). if (FromType->isBooleanType() && To->getKind() == BuiltinType::Int) { @@ -799,8 +793,7 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) /// IsFloatingPointPromotion - Determines whether the conversion from /// FromType to ToType is a floating point promotion (C++ 4.6). If so, /// returns true and sets PromotedType to the promoted type. -bool Sema::IsFloatingPointPromotion(QualType FromType, QualType ToType) -{ +bool Sema::IsFloatingPointPromotion(QualType FromType, QualType ToType) { /// An rvalue of type float can be converted to an rvalue of type /// double. (C++ 4.6p1). if (const BuiltinType *FromBuiltin = FromType->getAsBuiltinType()) @@ -847,15 +840,15 @@ bool Sema::IsComplexPromotion(QualType FromType, QualType ToType) { /// same type qualifiers as FromPtr has on its pointee type. ToType, /// if non-empty, will be a pointer to ToType that may or may not have /// the right set of qualifiers on its pointee. -static QualType -BuildSimilarlyQualifiedPointerType(const PointerType *FromPtr, +static QualType +BuildSimilarlyQualifiedPointerType(const PointerType *FromPtr, QualType ToPointee, QualType ToType, ASTContext &Context) { QualType CanonFromPointee = Context.getCanonicalType(FromPtr->getPointeeType()); QualType CanonToPointee = Context.getCanonicalType(ToPointee); unsigned Quals = CanonFromPointee.getCVRQualifiers(); - - // Exact qualifier match -> return the pointer type we're converting to. + + // Exact qualifier match -> return the pointer type we're converting to. if (CanonToPointee.getCVRQualifiers() == Quals) { // ToType is exactly what we need. Return it. if (ToType.getTypePtr()) @@ -870,7 +863,7 @@ BuildSimilarlyQualifiedPointerType(const PointerType *FromPtr, return Context.getPointerType(CanonToPointee.getQualifiedType(Quals)); } -static bool isNullPointerConstantForConversion(Expr *Expr, +static bool isNullPointerConstantForConversion(Expr *Expr, bool InOverloadResolution, ASTContext &Context) { // Handle value-dependent integral null pointer constants correctly. @@ -881,7 +874,7 @@ static bool isNullPointerConstantForConversion(Expr *Expr, return Expr->isNullPointerConstant(Context); } - + /// IsPointerConversion - Determines whether the conversion of the /// expression From, which has the (possibly adjusted) type FromType, /// can be converted to the type ToType via a pointer conversion (C++ @@ -901,14 +894,13 @@ static bool isNullPointerConstantForConversion(Expr *Expr, bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, bool InOverloadResolution, QualType& ConvertedType, - bool &IncompatibleObjC) -{ + bool &IncompatibleObjC) { IncompatibleObjC = false; if (isObjCPointerConversion(FromType, ToType, ConvertedType, IncompatibleObjC)) return true; - // Conversion from a null pointer constant to any Objective-C pointer type. - if (ToType->isObjCObjectPointerType() && + // Conversion from a null pointer constant to any Objective-C pointer type. + if (ToType->isObjCObjectPointerType() && isNullPointerConstantForConversion(From, InOverloadResolution, Context)) { ConvertedType = ToType; return true; @@ -922,7 +914,7 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, } // Blocks: A null pointer constant can be converted to a block // pointer type. - if (ToType->isBlockPointerType() && + if (ToType->isBlockPointerType() && isNullPointerConstantForConversion(From, InOverloadResolution, Context)) { ConvertedType = ToType; return true; @@ -930,7 +922,7 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, // If the left-hand-side is nullptr_t, the right side can be a null // pointer constant. - if (ToType->isNullPtrType() && + if (ToType->isNullPtrType() && isNullPointerConstantForConversion(From, InOverloadResolution, Context)) { ConvertedType = ToType; return true; @@ -958,7 +950,7 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, // can be converted to an rvalue of type "pointer to cv void" (C++ // 4.10p2). if (FromPointeeType->isObjectType() && ToPointeeType->isVoidType()) { - ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, + ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, ToPointeeType, ToType, Context); return true; @@ -966,16 +958,16 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, // When we're overloading in C, we allow a special kind of pointer // conversion for compatible-but-not-identical pointee types. - if (!getLangOptions().CPlusPlus && + if (!getLangOptions().CPlusPlus && Context.typesAreCompatible(FromPointeeType, ToPointeeType)) { - ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, + ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, ToPointeeType, - ToType, Context); + ToType, Context); return true; } // C++ [conv.ptr]p3: - // + // // An rvalue of type "pointer to cv D," where D is a class type, // can be converted to an rvalue of type "pointer to cv B," where // B is a base class (clause 10) of D. If B is an inaccessible @@ -990,7 +982,7 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, if (getLangOptions().CPlusPlus && FromPointeeType->isRecordType() && ToPointeeType->isRecordType() && IsDerivedFrom(FromPointeeType, ToPointeeType)) { - ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, + ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, ToPointeeType, ToType, Context); return true; @@ -1002,7 +994,7 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, /// isObjCPointerConversion - Determines whether this is an /// Objective-C pointer conversion. Subroutine of IsPointerConversion, /// with the same arguments and return values. -bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, +bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, QualType& ConvertedType, bool &IncompatibleObjC) { if (!getLangOptions().ObjC1) @@ -1010,7 +1002,7 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, // First, we handle all conversions on ObjC object pointer types. const ObjCObjectPointerType* ToObjCPtr = ToType->getAsObjCObjectPointerType(); - const ObjCObjectPointerType *FromObjCPtr = + const ObjCObjectPointerType *FromObjCPtr = FromType->getAsObjCObjectPointerType(); if (ToObjCPtr && FromObjCPtr) { @@ -1021,9 +1013,9 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, return true; } // Conversions with Objective-C's id<...>. - if ((FromObjCPtr->isObjCQualifiedIdType() || + if ((FromObjCPtr->isObjCQualifiedIdType() || ToObjCPtr->isObjCQualifiedIdType()) && - Context.ObjCQualifiedIdTypesAreCompatible(ToType, FromType, + Context.ObjCQualifiedIdTypesAreCompatible(ToType, FromType, /*compare=*/false)) { ConvertedType = ToType; return true; @@ -1043,7 +1035,7 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, ConvertedType = FromType; return true; } - } + } // Beyond this point, both types need to be C pointers or block pointers. QualType ToPointeeType; if (const PointerType *ToCPtr = ToType->getAs<PointerType>()) @@ -1075,7 +1067,7 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, // differences in the argument and result types are in Objective-C // pointer conversions. If so, we permit the conversion (but // complain about it). - const FunctionProtoType *FromFunctionType + const FunctionProtoType *FromFunctionType = FromPointeeType->getAsFunctionProtoType(); const FunctionProtoType *ToFunctionType = ToPointeeType->getAsFunctionProtoType(); @@ -1106,7 +1098,7 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, // Function types are too different. Abort. return false; } - + // Check argument types. for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumArgs(); ArgIdx != NumArgs; ++ArgIdx) { @@ -1160,9 +1152,9 @@ bool Sema::CheckPointerConversion(Expr *From, QualType ToType) { From->getSourceRange()); } } - if (const ObjCObjectPointerType *FromPtrType = + if (const ObjCObjectPointerType *FromPtrType = FromType->getAsObjCObjectPointerType()) - if (const ObjCObjectPointerType *ToPtrType = + if (const ObjCObjectPointerType *ToPtrType = ToType->getAsObjCObjectPointerType()) { // Objective-C++ conversions are always okay. // FIXME: We should have a different class of conversions for the @@ -1180,8 +1172,7 @@ bool Sema::CheckPointerConversion(Expr *From, QualType ToType) { /// If so, returns true and places the converted type (that might differ from /// ToType in its cv-qualifiers at some level) into ConvertedType. bool Sema::IsMemberPointerConversion(Expr *From, QualType FromType, - QualType ToType, QualType &ConvertedType) -{ + QualType ToType, QualType &ConvertedType) { const MemberPointerType *ToTypePtr = ToType->getAs<MemberPointerType>(); if (!ToTypePtr) return false; @@ -1218,13 +1209,13 @@ bool Sema::IsMemberPointerConversion(Expr *From, QualType FromType, /// for which IsMemberPointerConversion has already returned true. It returns /// true and produces a diagnostic if there was an error, or returns false /// otherwise. -bool Sema::CheckMemberPointerConversion(Expr *From, QualType ToType, +bool Sema::CheckMemberPointerConversion(Expr *From, QualType ToType, CastExpr::CastKind &Kind) { QualType FromType = From->getType(); const MemberPointerType *FromPtrType = FromType->getAs<MemberPointerType>(); if (!FromPtrType) { // This must be a null pointer to member pointer conversion - assert(From->isNullPointerConstant(Context) && + assert(From->isNullPointerConstant(Context) && "Expr must be null pointer constant!"); Kind = CastExpr::CK_NullToMemberPointer; return false; @@ -1278,9 +1269,8 @@ bool Sema::CheckMemberPointerConversion(Expr *From, QualType ToType, /// IsQualificationConversion - Determines whether the conversion from /// an rvalue of type FromType to ToType is a qualification conversion /// (C++ 4.4). -bool -Sema::IsQualificationConversion(QualType FromType, QualType ToType) -{ +bool +Sema::IsQualificationConversion(QualType FromType, QualType ToType) { FromType = Context.getCanonicalType(FromType); ToType = Context.getCanonicalType(ToType); @@ -1307,16 +1297,16 @@ Sema::IsQualificationConversion(QualType FromType, QualType ToType) // 2,j, and similarly for volatile. if (!ToType.isAtLeastAsQualifiedAs(FromType)) return false; - + // -- if the cv 1,j and cv 2,j are different, then const is in // every cv for 0 < k < j. if (FromType.getCVRQualifiers() != ToType.getCVRQualifiers() && !PreviousToQualsIncludeConst) return false; - + // Keep track of whether all prior cv-qualifiers in the "to" type // include const. - PreviousToQualsIncludeConst + PreviousToQualsIncludeConst = PreviousToQualsIncludeConst && ToType.isConstQualified(); } @@ -1359,14 +1349,13 @@ static void GetFunctionAndTemplate(AnyFunctionDecl Orig, T *&Function, /// /// \param ForceRValue true if the expression should be treated as an rvalue /// for overload resolution. -bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, +bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, UserDefinedConversionSequence& User, bool AllowConversionFunctions, - bool AllowExplicit, bool ForceRValue) -{ + bool AllowExplicit, bool ForceRValue) { OverloadCandidateSet CandidateSet; if (const RecordType *ToRecordType = ToType->getAs<RecordType>()) { - if (CXXRecordDecl *ToRecordDecl + if (CXXRecordDecl *ToRecordDecl = dyn_cast<CXXRecordDecl>(ToRecordType->getDecl())) { // C++ [over.match.ctor]p1: // When objects of class type are direct-initialized (8.5), or @@ -1376,11 +1365,11 @@ bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, // functions are all the converting constructors (12.3.1) of // that class. The argument list is the expression-list within // the parentheses of the initializer. - DeclarationName ConstructorName + DeclarationName ConstructorName = Context.DeclarationNames.getCXXConstructorName( Context.getCanonicalType(ToType).getUnqualifiedType()); DeclContext::lookup_iterator Con, ConEnd; - for (llvm::tie(Con, ConEnd) + for (llvm::tie(Con, ConEnd) = ToRecordDecl->lookup(ConstructorName); Con != ConEnd; ++Con) { // Find the constructor (which may be a template). @@ -1388,17 +1377,17 @@ bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, FunctionTemplateDecl *ConstructorTmpl = dyn_cast<FunctionTemplateDecl>(*Con); if (ConstructorTmpl) - Constructor + Constructor = cast<CXXConstructorDecl>(ConstructorTmpl->getTemplatedDecl()); else Constructor = cast<CXXConstructorDecl>(*Con); - + if (!Constructor->isInvalidDecl() && Constructor->isConvertingConstructor(AllowExplicit)) { if (ConstructorTmpl) - AddTemplateOverloadCandidate(ConstructorTmpl, false, 0, 0, &From, + AddTemplateOverloadCandidate(ConstructorTmpl, false, 0, 0, &From, 1, CandidateSet, - /*SuppressUserConversions=*/true, + /*SuppressUserConversions=*/true, ForceRValue); else AddOverloadCandidate(Constructor, &From, 1, CandidateSet, @@ -1410,19 +1399,19 @@ bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, if (!AllowConversionFunctions) { // Don't allow any conversion functions to enter the overload set. - } else if (RequireCompleteType(From->getLocStart(), From->getType(), - PDiag(0) + } else if (RequireCompleteType(From->getLocStart(), From->getType(), + PDiag(0) << From->getSourceRange())) { // No conversion functions from incomplete types. - } else if (const RecordType *FromRecordType + } else if (const RecordType *FromRecordType = From->getType()->getAs<RecordType>()) { - if (CXXRecordDecl *FromRecordDecl + if (CXXRecordDecl *FromRecordDecl = dyn_cast<CXXRecordDecl>(FromRecordType->getDecl())) { // Add all of the conversion functions as candidates. // FIXME: Look for conversions in base classes! - OverloadedFunctionDecl *Conversions + OverloadedFunctionDecl *Conversions = FromRecordDecl->getConversionFunctions(); - for (OverloadedFunctionDecl::function_iterator Func + for (OverloadedFunctionDecl::function_iterator Func = Conversions->function_begin(); Func != Conversions->function_end(); ++Func) { CXXConversionDecl *Conv; @@ -1430,12 +1419,12 @@ bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, GetFunctionAndTemplate(*Func, Conv, ConvTemplate); if (ConvTemplate) Conv = dyn_cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); - else + else Conv = dyn_cast<CXXConversionDecl>(*Func); if (AllowExplicit || !Conv->isExplicit()) { if (ConvTemplate) - AddTemplateConversionCandidate(ConvTemplate, From, ToType, + AddTemplateConversionCandidate(ConvTemplate, From, ToType, CandidateSet); else AddConversionCandidate(Conv, From, ToType, CandidateSet); @@ -1448,7 +1437,7 @@ bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, switch (BestViableFunction(CandidateSet, From->getLocStart(), Best)) { case OR_Success: // Record the standard conversion we used and the conversion function. - if (CXXConstructorDecl *Constructor + if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(Best->Function)) { // C++ [over.ics.user]p1: // If the user-defined conversion is specified by a @@ -1461,7 +1450,7 @@ bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, User.Before = Best->Conversions[0].Standard; User.ConversionFunction = Constructor; User.After.setAsIdentityConversion(); - User.After.FromTypePtr + User.After.FromTypePtr = ThisType->getAs<PointerType>()->getPointeeType().getAsOpaquePtr(); User.After.ToTypePtr = ToType.getAsOpaquePtr(); return true; @@ -1475,8 +1464,8 @@ bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, // implicit object parameter of the conversion function. User.Before = Best->Conversions[0].Standard; User.ConversionFunction = Conversion; - - // C++ [over.ics.user]p2: + + // C++ [over.ics.user]p2: // The second standard conversion sequence converts the // result of the user-defined conversion to the target type // for the sequence. Since an implicit conversion sequence @@ -1491,7 +1480,7 @@ bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, assert(false && "Not a constructor or conversion function?"); return false; } - + case OR_No_Viable_Function: case OR_Deleted: // No conversion here! We're done. @@ -1509,7 +1498,7 @@ bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, /// CompareImplicitConversionSequences - Compare two implicit /// conversion sequences to determine whether one is better than the /// other or if they are indistinguishable (C++ 13.3.3.2). -ImplicitConversionSequence::CompareKind +ImplicitConversionSequence::CompareKind Sema::CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1, const ImplicitConversionSequence& ICS2) { @@ -1521,7 +1510,7 @@ Sema::CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1, // -- a user-defined conversion sequence (13.3.3.1.2) is a better // conversion sequence than an ellipsis conversion sequence // (13.3.3.1.3). - // + // if (ICS1.ConversionKind < ICS2.ConversionKind) return ImplicitConversionSequence::Better; else if (ICS2.ConversionKind < ICS1.ConversionKind) @@ -1532,7 +1521,7 @@ Sema::CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1, // following rules apply: (C++ 13.3.3.2p3): if (ICS1.ConversionKind == ImplicitConversionSequence::StandardConversion) return CompareStandardConversionSequences(ICS1.Standard, ICS2.Standard); - else if (ICS1.ConversionKind == + else if (ICS1.ConversionKind == ImplicitConversionSequence::UserDefinedConversion) { // User-defined conversion sequence U1 is a better conversion // sequence than another user-defined conversion sequence U2 if @@ -1540,7 +1529,7 @@ Sema::CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1, // constructor and if the second standard conversion sequence of // U1 is better than the second standard conversion sequence of // U2 (C++ 13.3.3.2p3). - if (ICS1.UserDefined.ConversionFunction == + if (ICS1.UserDefined.ConversionFunction == ICS2.UserDefined.ConversionFunction) return CompareStandardConversionSequences(ICS1.UserDefined.After, ICS2.UserDefined.After); @@ -1552,7 +1541,7 @@ Sema::CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1, /// CompareStandardConversionSequences - Compare two standard /// conversion sequences to determine whether one is better than the /// other or if they are indistinguishable (C++ 13.3.3.2p3). -ImplicitConversionSequence::CompareKind +ImplicitConversionSequence::CompareKind Sema::CompareStandardConversionSequences(const StandardConversionSequence& SCS1, const StandardConversionSequence& SCS2) { @@ -1569,13 +1558,13 @@ Sema::CompareStandardConversionSequences(const StandardConversionSequence& SCS1, ; else if ((SCS1.Second == ICK_Identity && SCS1.Third == SCS2.Third) || (SCS1.Third == ICK_Identity && SCS1.Second == SCS2.Second) || - (SCS1.Second == ICK_Identity && + (SCS1.Second == ICK_Identity && SCS1.Third == ICK_Identity)) // SCS1 is a proper subsequence of SCS2. return ImplicitConversionSequence::Better; else if ((SCS2.Second == ICK_Identity && SCS2.Third == SCS1.Third) || (SCS2.Third == ICK_Identity && SCS2.Second == SCS1.Second) || - (SCS2.Second == ICK_Identity && + (SCS2.Second == ICK_Identity && SCS2.Third == ICK_Identity)) // SCS2 is a proper subsequence of SCS1. return ImplicitConversionSequence::Worse; @@ -1592,7 +1581,7 @@ Sema::CompareStandardConversionSequences(const StandardConversionSequence& SCS1, // (C++ 13.3.3.2p4): Two conversion sequences with the same rank // are indistinguishable unless one of the following rules // applies: - + // A conversion that is not a conversion of a pointer, or // pointer to member, to bool is better than another conversion // that is such a conversion. @@ -1607,9 +1596,9 @@ Sema::CompareStandardConversionSequences(const StandardConversionSequence& SCS1, // conversion of B* to A* is better than conversion of B* to // void*, and conversion of A* to void* is better than conversion // of B* to void*. - bool SCS1ConvertsToVoid + bool SCS1ConvertsToVoid = SCS1.isPointerConversionToVoidPointer(Context); - bool SCS2ConvertsToVoid + bool SCS2ConvertsToVoid = SCS2.isPointerConversionToVoidPointer(Context); if (SCS1ConvertsToVoid != SCS2ConvertsToVoid) { // Exactly one of the conversion sequences is a conversion to @@ -1636,7 +1625,7 @@ Sema::CompareStandardConversionSequences(const StandardConversionSequence& SCS1, if (SCS2.First == ICK_Array_To_Pointer) FromType2 = Context.getArrayDecayedType(FromType2); - QualType FromPointee1 + QualType FromPointee1 = FromType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType(); QualType FromPointee2 = FromType2->getAs<PointerType>()->getPointeeType().getUnqualifiedType(); @@ -1660,7 +1649,7 @@ Sema::CompareStandardConversionSequences(const StandardConversionSequence& SCS1, // Compare based on qualification conversions (C++ 13.3.3.2p3, // bullet 3). - if (ImplicitConversionSequence::CompareKind QualCK + if (ImplicitConversionSequence::CompareKind QualCK = CompareQualificationConversions(SCS1, SCS2)) return QualCK; @@ -1700,11 +1689,10 @@ Sema::CompareStandardConversionSequences(const StandardConversionSequence& SCS1, /// CompareQualificationConversions - Compares two standard conversion /// sequences to determine whether they can be ranked based on their -/// qualification conversions (C++ 13.3.3.2p3 bullet 3). -ImplicitConversionSequence::CompareKind +/// qualification conversions (C++ 13.3.3.2p3 bullet 3). +ImplicitConversionSequence::CompareKind Sema::CompareQualificationConversions(const StandardConversionSequence& SCS1, - const StandardConversionSequence& SCS2) -{ + const StandardConversionSequence& SCS2) { // C++ 13.3.3.2p3: // -- S1 and S2 differ only in their qualification conversion and // yield similar types T1 and T2 (C++ 4.4), respectively, and the @@ -1727,7 +1715,7 @@ Sema::CompareQualificationConversions(const StandardConversionSequence& SCS1, if (T1.getUnqualifiedType() == T2.getUnqualifiedType()) return ImplicitConversionSequence::Indistinguishable; - ImplicitConversionSequence::CompareKind Result + ImplicitConversionSequence::CompareKind Result = ImplicitConversionSequence::Indistinguishable; while (UnwrapSimilarPointerTypes(T1, T2)) { // Within each iteration of the loop, we check the qualifiers to @@ -1748,7 +1736,7 @@ Sema::CompareQualificationConversions(const StandardConversionSequence& SCS1, // Neither has qualifiers that are a subset of the other's // qualifiers. return ImplicitConversionSequence::Indistinguishable; - + Result = ImplicitConversionSequence::Better; } else if (T1.isMoreQualifiedThan(T2)) { // T2 has fewer qualifiers, so it could be the better sequence. @@ -1756,7 +1744,7 @@ Sema::CompareQualificationConversions(const StandardConversionSequence& SCS1, // Neither has qualifiers that are a subset of the other's // qualifiers. return ImplicitConversionSequence::Indistinguishable; - + Result = ImplicitConversionSequence::Worse; } else { // Qualifiers are disjoint. @@ -1823,14 +1811,14 @@ Sema::CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1, // interfaces. // Compare based on pointer conversions. - if (SCS1.Second == ICK_Pointer_Conversion && + if (SCS1.Second == ICK_Pointer_Conversion && SCS2.Second == ICK_Pointer_Conversion && /*FIXME: Remove if Objective-C id conversions get their own rank*/ FromType1->isPointerType() && FromType2->isPointerType() && ToType1->isPointerType() && ToType2->isPointerType()) { - QualType FromPointee1 + QualType FromPointee1 = FromType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType(); - QualType ToPointee1 + QualType ToPointee1 = ToType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType(); QualType FromPointee2 = FromType2->getAs<PointerType>()->getPointeeType().getUnqualifiedType(); @@ -1863,7 +1851,7 @@ Sema::CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1, return ImplicitConversionSequence::Better; else if (IsDerivedFrom(FromPointee1, FromPointee2)) return ImplicitConversionSequence::Worse; - + if (FromIface1 && FromIface2) { if (Context.canAssignObjCInterfaces(FromIface1, FromIface2)) return ImplicitConversionSequence::Better; @@ -1937,20 +1925,20 @@ Sema::CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1, /// a parameter of this type). If @p SuppressUserConversions, then we /// do not permit any user-defined conversion sequences. If @p ForceRValue, /// then we treat @p From as an rvalue, even if it is an lvalue. -ImplicitConversionSequence -Sema::TryCopyInitialization(Expr *From, QualType ToType, +ImplicitConversionSequence +Sema::TryCopyInitialization(Expr *From, QualType ToType, bool SuppressUserConversions, bool ForceRValue, bool InOverloadResolution) { if (ToType->isReferenceType()) { ImplicitConversionSequence ICS; - CheckReferenceInit(From, ToType, + CheckReferenceInit(From, ToType, SuppressUserConversions, /*AllowExplicit=*/false, ForceRValue, &ICS); return ICS; } else { - return TryImplicitConversion(From, ToType, + return TryImplicitConversion(From, ToType, SuppressUserConversions, /*AllowExplicit=*/false, ForceRValue, @@ -1963,18 +1951,18 @@ Sema::TryCopyInitialization(Expr *From, QualType ToType, /// an error, returns false if the initialization succeeded. Elidable should /// be true when the copy may be elided (C++ 12.8p15). Overload resolution works /// differently in C++0x for this case. -bool Sema::PerformCopyInitialization(Expr *&From, QualType ToType, +bool Sema::PerformCopyInitialization(Expr *&From, QualType ToType, const char* Flavor, bool Elidable) { if (!getLangOptions().CPlusPlus) { // In C, argument passing is the same as performing an assignment. QualType FromType = From->getType(); - + AssignConvertType ConvTy = CheckSingleAssignmentConstraints(ToType, From); if (ConvTy != Compatible && CheckTransparentUnionArgumentConstraints(ToType, From) == Compatible) ConvTy = Compatible; - + return DiagnoseAssignmentResult(ConvTy, From->getLocStart(), ToType, FromType, From, Flavor); } @@ -2020,7 +2008,7 @@ Sema::TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method) { // where X is the class of which the function is a member // (C++ [over.match.funcs]p4). However, when finding an implicit // conversion sequence for the argument, we are not allowed to - // create temporaries or perform user-defined conversions + // create temporaries or perform user-defined conversions // (C++ [over.match.funcs]p5). We perform a simplified version of // reference binding here, that allows class rvalues to bind to // non-constant references. @@ -2058,9 +2046,9 @@ Sema::TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method) { bool Sema::PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method) { QualType FromRecordType, DestType; - QualType ImplicitParamRecordType = + QualType ImplicitParamRecordType = Method->getThisType(Context)->getAs<PointerType>()->getPointeeType(); - + if (const PointerType *PT = From->getType()->getAs<PointerType>()) { FromRecordType = PT->getPointeeType(); DestType = Method->getThisType(Context); @@ -2069,13 +2057,13 @@ Sema::PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method) { DestType = ImplicitParamRecordType; } - ImplicitConversionSequence ICS + ImplicitConversionSequence ICS = TryObjectArgumentInitialization(From, Method); if (ICS.ConversionKind == ImplicitConversionSequence::BadConversion) return Diag(From->getSourceRange().getBegin(), diag::err_implicit_object_parameter_init) << ImplicitParamRecordType << FromRecordType << From->getSourceRange(); - + if (ICS.Standard.Second == ICK_Derived_To_Base && CheckDerivedToBaseConversion(FromRecordType, ImplicitParamRecordType, @@ -2083,7 +2071,7 @@ Sema::PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method) { From->getSourceRange())) return true; - ImpCastExprToType(From, DestType, CastExpr::CK_DerivedToBase, + ImpCastExprToType(From, DestType, CastExpr::CK_DerivedToBase, /*isLvalue=*/true); return false; } @@ -2091,10 +2079,10 @@ Sema::PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method) { /// TryContextuallyConvertToBool - Attempt to contextually convert the /// expression From to bool (C++0x [conv]p3). ImplicitConversionSequence Sema::TryContextuallyConvertToBool(Expr *From) { - return TryImplicitConversion(From, Context.BoolTy, + return TryImplicitConversion(From, Context.BoolTy, // FIXME: Are these flags correct? /*SuppressUserConversions=*/false, - /*AllowExplicit=*/true, + /*AllowExplicit=*/true, /*ForceRValue=*/false, /*InOverloadResolution=*/false); } @@ -2106,7 +2094,7 @@ bool Sema::PerformContextuallyConvertToBool(Expr *&From) { if (!PerformImplicitConversion(From, Context.BoolTy, ICS, "converting")) return false; - return Diag(From->getSourceRange().getBegin(), + return Diag(From->getSourceRange().getBegin(), diag::err_typecheck_bool_condition) << From->getType() << From->getSourceRange(); } @@ -2118,21 +2106,20 @@ bool Sema::PerformContextuallyConvertToBool(Expr *&From) { /// If @p ForceRValue, treat all arguments as rvalues. This is a slightly /// hacky way to implement the overloading rules for elidable copy /// initialization in C++0x (C++0x 12.8p15). -void -Sema::AddOverloadCandidate(FunctionDecl *Function, +void +Sema::AddOverloadCandidate(FunctionDecl *Function, Expr **Args, unsigned NumArgs, OverloadCandidateSet& CandidateSet, bool SuppressUserConversions, - bool ForceRValue) -{ - const FunctionProtoType* Proto + bool ForceRValue) { + const FunctionProtoType* Proto = dyn_cast<FunctionProtoType>(Function->getType()->getAsFunctionType()); assert(Proto && "Functions without a prototype cannot be overloaded"); - assert(!isa<CXXConversionDecl>(Function) && + assert(!isa<CXXConversionDecl>(Function) && "Use AddConversionCandidate for conversion functions"); - assert(!Function->getDescribedFunctionTemplate() && + assert(!Function->getDescribedFunctionTemplate() && "Use AddTemplateOverloadCandidate for function templates"); - + if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Function)) { if (!isa<CXXConstructorDecl>(Method)) { // If we get here, it's because we're calling a member function @@ -2141,7 +2128,7 @@ Sema::AddOverloadCandidate(FunctionDecl *Function, // implicitly. This can happen with a qualified call to a member // function, e.g., X::f(). We use a NULL object as the implied // object argument (C++ [over.call.func]p3). - AddMethodCandidate(Method, 0, Args, NumArgs, CandidateSet, + AddMethodCandidate(Method, 0, Args, NumArgs, CandidateSet, SuppressUserConversions, ForceRValue); return; } @@ -2190,11 +2177,11 @@ Sema::AddOverloadCandidate(FunctionDecl *Function, // (13.3.3.1) that converts that argument to the corresponding // parameter of F. QualType ParamType = Proto->getArgType(ArgIdx); - Candidate.Conversions[ArgIdx] - = TryCopyInitialization(Args[ArgIdx], ParamType, + Candidate.Conversions[ArgIdx] + = TryCopyInitialization(Args[ArgIdx], ParamType, SuppressUserConversions, ForceRValue, /*InOverloadResolution=*/true); - if (Candidate.Conversions[ArgIdx].ConversionKind + if (Candidate.Conversions[ArgIdx].ConversionKind == ImplicitConversionSequence::BadConversion) { Candidate.Viable = false; break; @@ -2203,7 +2190,7 @@ Sema::AddOverloadCandidate(FunctionDecl *Function, // (C++ 13.3.2p2): For the purposes of overload resolution, any // argument for which there is no corresponding parameter is // considered to ""match the ellipsis" (C+ 13.3.3.1.3). - Candidate.Conversions[ArgIdx].ConversionKind + Candidate.Conversions[ArgIdx].ConversionKind = ImplicitConversionSequence::EllipsisConversion; } } @@ -2215,16 +2202,16 @@ void Sema::AddFunctionCandidates(const FunctionSet &Functions, Expr **Args, unsigned NumArgs, OverloadCandidateSet& CandidateSet, bool SuppressUserConversions) { - for (FunctionSet::const_iterator F = Functions.begin(), + for (FunctionSet::const_iterator F = Functions.begin(), FEnd = Functions.end(); F != FEnd; ++F) { if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*F)) - AddOverloadCandidate(FD, Args, NumArgs, CandidateSet, + AddOverloadCandidate(FD, Args, NumArgs, CandidateSet, SuppressUserConversions); else AddTemplateOverloadCandidate(cast<FunctionTemplateDecl>(*F), /*FIXME: explicit args */false, 0, 0, - Args, NumArgs, CandidateSet, + Args, NumArgs, CandidateSet, SuppressUserConversions); } } @@ -2238,13 +2225,12 @@ void Sema::AddFunctionCandidates(const FunctionSet &Functions, /// operators. If @p ForceRValue, treat all arguments as rvalues. This is /// a slightly hacky way to implement the overloading rules for elidable copy /// initialization in C++0x (C++0x 12.8p15). -void +void Sema::AddMethodCandidate(CXXMethodDecl *Method, Expr *Object, Expr **Args, unsigned NumArgs, OverloadCandidateSet& CandidateSet, - bool SuppressUserConversions, bool ForceRValue) -{ - const FunctionProtoType* Proto + bool SuppressUserConversions, bool ForceRValue) { + const FunctionProtoType* Proto = dyn_cast<FunctionProtoType>(Method->getType()->getAsFunctionType()); assert(Proto && "Methods without a prototype cannot be overloaded"); assert(!isa<CXXConversionDecl>(Method) && @@ -2291,7 +2277,7 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, Expr *Object, // Determine the implicit conversion sequence for the object // parameter. Candidate.Conversions[0] = TryObjectArgumentInitialization(Object, Method); - if (Candidate.Conversions[0].ConversionKind + if (Candidate.Conversions[0].ConversionKind == ImplicitConversionSequence::BadConversion) { Candidate.Viable = false; return; @@ -2307,11 +2293,11 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, Expr *Object, // (13.3.3.1) that converts that argument to the corresponding // parameter of F. QualType ParamType = Proto->getArgType(ArgIdx); - Candidate.Conversions[ArgIdx + 1] - = TryCopyInitialization(Args[ArgIdx], ParamType, + Candidate.Conversions[ArgIdx + 1] + = TryCopyInitialization(Args[ArgIdx], ParamType, SuppressUserConversions, ForceRValue, /*InOverloadResolution=*/true); - if (Candidate.Conversions[ArgIdx + 1].ConversionKind + if (Candidate.Conversions[ArgIdx + 1].ConversionKind == ImplicitConversionSequence::BadConversion) { Candidate.Viable = false; break; @@ -2320,7 +2306,7 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, Expr *Object, // (C++ 13.3.2p2): For the purposes of overload resolution, any // argument for which there is no corresponding parameter is // considered to ""match the ellipsis" (C+ 13.3.3.1.3). - Candidate.Conversions[ArgIdx + 1].ConversionKind + Candidate.Conversions[ArgIdx + 1].ConversionKind = ImplicitConversionSequence::EllipsisConversion; } } @@ -2329,7 +2315,7 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, Expr *Object, /// \brief Add a C++ member function template as a candidate to the candidate /// set, using template argument deduction to produce an appropriate member /// function template specialization. -void +void Sema::AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, bool HasExplicitTemplateArgs, const TemplateArgument *ExplicitTemplateArgs, @@ -2339,9 +2325,9 @@ Sema::AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, bool SuppressUserConversions, bool ForceRValue) { // C++ [over.match.funcs]p7: - // In each case where a candidate is a function template, candidate + // In each case where a candidate is a function template, candidate // function template specializations are generated using template argument - // deduction (14.8.3, 14.8.2). Those candidates are then handled as + // deduction (14.8.3, 14.8.2). Those candidates are then handled as // candidate functions in the usual way.113) A given name can refer to one // or more function templates and also to a set of overloaded non-template // functions. In such a case, the candidate functions generated from each @@ -2358,20 +2344,20 @@ Sema::AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, (void)Result; return; } - + // Add the function template specialization produced by template argument // deduction as a candidate. assert(Specialization && "Missing member function template specialization?"); - assert(isa<CXXMethodDecl>(Specialization) && + assert(isa<CXXMethodDecl>(Specialization) && "Specialization is not a member function?"); - AddMethodCandidate(cast<CXXMethodDecl>(Specialization), Object, Args, NumArgs, + AddMethodCandidate(cast<CXXMethodDecl>(Specialization), Object, Args, NumArgs, CandidateSet, SuppressUserConversions, ForceRValue); } /// \brief Add a C++ function template specialization as a candidate /// in the candidate set, using template argument deduction to produce /// an appropriate function template specialization. -void +void Sema::AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, bool HasExplicitTemplateArgs, const TemplateArgument *ExplicitTemplateArgs, @@ -2381,9 +2367,9 @@ Sema::AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, bool SuppressUserConversions, bool ForceRValue) { // C++ [over.match.funcs]p7: - // In each case where a candidate is a function template, candidate + // In each case where a candidate is a function template, candidate // function template specializations are generated using template argument - // deduction (14.8.3, 14.8.2). Those candidates are then handled as + // deduction (14.8.3, 14.8.2). Those candidates are then handled as // candidate functions in the usual way.113) A given name can refer to one // or more function templates and also to a set of overloaded non-template // functions. In such a case, the candidate functions generated from each @@ -2400,18 +2386,18 @@ Sema::AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, (void)Result; return; } - + // Add the function template specialization produced by template argument // deduction as a candidate. assert(Specialization && "Missing function template specialization?"); AddOverloadCandidate(Specialization, Args, NumArgs, CandidateSet, SuppressUserConversions, ForceRValue); } - + /// AddConversionCandidate - Add a C++ conversion function as a -/// candidate in the candidate set (C++ [over.match.conv], +/// candidate in the candidate set (C++ [over.match.conv], /// C++ [over.match.copy]). From is the expression we're converting from, -/// and ToType is the type that we're eventually trying to convert to +/// and ToType is the type that we're eventually trying to convert to /// (which may or may not be the same type as the type that the /// conversion function produces). void @@ -2428,7 +2414,7 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion, Candidate.IsSurrogate = false; Candidate.IgnoreObjectArgument = false; Candidate.FinalConversion.setAsIdentityConversion(); - Candidate.FinalConversion.FromTypePtr + Candidate.FinalConversion.FromTypePtr = Conversion->getConversionType().getAsOpaquePtr(); Candidate.FinalConversion.ToTypePtr = ToType.getAsOpaquePtr(); @@ -2438,7 +2424,7 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion, Candidate.Conversions.resize(1); Candidate.Conversions[0] = TryObjectArgumentInitialization(From, Conversion); - if (Candidate.Conversions[0].ConversionKind + if (Candidate.Conversions[0].ConversionKind == ImplicitConversionSequence::BadConversion) { Candidate.Viable = false; return; @@ -2452,24 +2438,24 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion, // lvalues/rvalues and the type. Fortunately, we can allocate this // call on the stack and we don't need its arguments to be // well-formed. - DeclRefExpr ConversionRef(Conversion, Conversion->getType(), + DeclRefExpr ConversionRef(Conversion, Conversion->getType(), SourceLocation()); ImplicitCastExpr ConversionFn(Context.getPointerType(Conversion->getType()), CastExpr::CK_Unknown, &ConversionRef, false); - - // Note that it is safe to allocate CallExpr on the stack here because + + // Note that it is safe to allocate CallExpr on the stack here because // there are 0 arguments (i.e., nothing is allocated using ASTContext's // allocator). - CallExpr Call(Context, &ConversionFn, 0, 0, + CallExpr Call(Context, &ConversionFn, 0, 0, Conversion->getConversionType().getNonReferenceType(), SourceLocation()); - ImplicitConversionSequence ICS = - TryCopyInitialization(&Call, ToType, + ImplicitConversionSequence ICS = + TryCopyInitialization(&Call, ToType, /*SuppressUserConversions=*/true, /*ForceRValue=*/false, /*InOverloadResolution=*/false); - + switch (ICS.ConversionKind) { case ImplicitConversionSequence::StandardConversion: Candidate.FinalConversion = ICS.Standard; @@ -2480,7 +2466,7 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion, break; default: - assert(false && + assert(false && "Can only end up with a standard conversion sequence or failure"); } } @@ -2490,7 +2476,7 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion, /// to deduce the template arguments of the conversion function /// template from the type that we are converting to (C++ /// [temp.deduct.conv]). -void +void Sema::AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, Expr *From, QualType ToType, OverloadCandidateSet &CandidateSet) { @@ -2500,14 +2486,14 @@ Sema::AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, TemplateDeductionInfo Info(Context); CXXConversionDecl *Specialization = 0; if (TemplateDeductionResult Result - = DeduceTemplateArguments(FunctionTemplate, ToType, + = DeduceTemplateArguments(FunctionTemplate, ToType, Specialization, Info)) { // FIXME: Record what happened with template argument deduction, so // that we can give the user a beautiful diagnostic. (void)Result; return; } - + // Add the conversion function template specialization produced by // template argument deduction as a candidate. assert(Specialization && "Missing function template specialization?"); @@ -2534,7 +2520,7 @@ void Sema::AddSurrogateCandidate(CXXConversionDecl *Conversion, // Determine the implicit conversion sequence for the implicit // object parameter. - ImplicitConversionSequence ObjectInit + ImplicitConversionSequence ObjectInit = TryObjectArgumentInitialization(Object, Conversion); if (ObjectInit.ConversionKind == ImplicitConversionSequence::BadConversion) { Candidate.Viable = false; @@ -2544,15 +2530,15 @@ void Sema::AddSurrogateCandidate(CXXConversionDecl *Conversion, // The first conversion is actually a user-defined conversion whose // first conversion is ObjectInit's standard conversion (which is // effectively a reference binding). Record it as such. - Candidate.Conversions[0].ConversionKind + Candidate.Conversions[0].ConversionKind = ImplicitConversionSequence::UserDefinedConversion; Candidate.Conversions[0].UserDefined.Before = ObjectInit.Standard; Candidate.Conversions[0].UserDefined.ConversionFunction = Conversion; - Candidate.Conversions[0].UserDefined.After + Candidate.Conversions[0].UserDefined.After = Candidate.Conversions[0].UserDefined.Before; Candidate.Conversions[0].UserDefined.After.setAsIdentityConversion(); - // Find the + // Find the unsigned NumArgsInProto = Proto->getNumArgs(); // (C++ 13.3.2p2): A candidate function having fewer than m @@ -2580,12 +2566,12 @@ void Sema::AddSurrogateCandidate(CXXConversionDecl *Conversion, // (13.3.3.1) that converts that argument to the corresponding // parameter of F. QualType ParamType = Proto->getArgType(ArgIdx); - Candidate.Conversions[ArgIdx + 1] - = TryCopyInitialization(Args[ArgIdx], ParamType, + Candidate.Conversions[ArgIdx + 1] + = TryCopyInitialization(Args[ArgIdx], ParamType, /*SuppressUserConversions=*/false, /*ForceRValue=*/false, /*InOverloadResolution=*/false); - if (Candidate.Conversions[ArgIdx + 1].ConversionKind + if (Candidate.Conversions[ArgIdx + 1].ConversionKind == ImplicitConversionSequence::BadConversion) { Candidate.Viable = false; break; @@ -2594,7 +2580,7 @@ void Sema::AddSurrogateCandidate(CXXConversionDecl *Conversion, // (C++ 13.3.2p2): For the purposes of overload resolution, any // argument for which there is no corresponding parameter is // considered to ""match the ellipsis" (C+ 13.3.3.1.3). - Candidate.Conversions[ArgIdx + 1].ConversionKind + Candidate.Conversions[ArgIdx + 1].ConversionKind = ImplicitConversionSequence::EllipsisConversion; } } @@ -2661,14 +2647,14 @@ void Sema::AddMemberOperatorCandidates(OverloadedOperatorKind Op, // Complete the type if it can be completed. Otherwise, we're done. if (RequireCompleteType(OpLoc, T1, PartialDiagnostic(0))) return; - - LookupResult Operators = LookupQualifiedName(T1Rec->getDecl(), OpName, + + LookupResult Operators = LookupQualifiedName(T1Rec->getDecl(), OpName, LookupOrdinaryName, false); - for (LookupResult::iterator Oper = Operators.begin(), + for (LookupResult::iterator Oper = Operators.begin(), OperEnd = Operators.end(); Oper != OperEnd; ++Oper) - AddMethodCandidate(cast<CXXMethodDecl>(*Oper), Args[0], + AddMethodCandidate(cast<CXXMethodDecl>(*Oper), Args[0], Args+1, NumArgs - 1, CandidateSet, /*SuppressUserConversions=*/false); } @@ -2682,7 +2668,7 @@ void Sema::AddMemberOperatorCandidates(OverloadedOperatorKind Op, /// operator. NumContextualBoolArguments is the number of arguments /// (at the beginning of the argument list) that will be contextually /// converted to bool. -void Sema::AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, +void Sema::AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, Expr **Args, unsigned NumArgs, OverloadCandidateSet& CandidateSet, bool IsAssignmentOperator, @@ -2708,24 +2694,24 @@ void Sema::AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, // -- no temporaries are introduced to hold the left operand, and // -- no user-defined conversions are applied to the left // operand to achieve a type match with the left-most - // parameter of a built-in candidate. + // parameter of a built-in candidate. // // We block these conversions by turning off user-defined // conversions, since that is the only way that initialization of // a reference to a non-class type can occur from something that // is not of the same type. if (ArgIdx < NumContextualBoolArguments) { - assert(ParamTys[ArgIdx] == Context.BoolTy && + assert(ParamTys[ArgIdx] == Context.BoolTy && "Contextual conversion to bool requires bool type"); Candidate.Conversions[ArgIdx] = TryContextuallyConvertToBool(Args[ArgIdx]); } else { - Candidate.Conversions[ArgIdx] - = TryCopyInitialization(Args[ArgIdx], ParamTys[ArgIdx], + Candidate.Conversions[ArgIdx] + = TryCopyInitialization(Args[ArgIdx], ParamTys[ArgIdx], ArgIdx == 0 && IsAssignmentOperator, /*ForceRValue=*/false, /*InOverloadResolution=*/false); } - if (Candidate.Conversions[ArgIdx].ConversionKind + if (Candidate.Conversions[ArgIdx].ConversionKind == ImplicitConversionSequence::BadConversion) { Candidate.Viable = false; break; @@ -2756,7 +2742,7 @@ class BuiltinCandidateTypeSet { /// Sema - The semantic analysis instance where we are building the /// candidate type set. Sema &SemaRef; - + /// Context - The AST context in which we will build the type sets. ASTContext &Context; @@ -2767,7 +2753,7 @@ public: /// iterator - Iterates through the types that are part of the set. typedef TypeSet::iterator iterator; - BuiltinCandidateTypeSet(Sema &SemaRef) + BuiltinCandidateTypeSet(Sema &SemaRef) : SemaRef(SemaRef), Context(SemaRef.Context) { } void AddTypesConvertedFrom(QualType Ty, bool AllowUserConversions, @@ -2866,7 +2852,7 @@ BuiltinCandidateTypeSet::AddMemberPointerWithMoreQualifiedTypeVariants( /// functions of a class type, and AllowExplicitConversions if we /// should also include the explicit conversion functions of a class /// type. -void +void BuiltinCandidateTypeSet::AddTypesConvertedFrom(QualType Ty, bool AllowUserConversions, bool AllowExplicitConversions) { @@ -2891,7 +2877,7 @@ BuiltinCandidateTypeSet::AddTypesConvertedFrom(QualType Ty, // Add 'cv void*' to our set of types. if (!Ty->isVoidType()) { - QualType QualVoid + QualType QualVoid = Context.VoidTy.getQualifiedType(PointeeTy.getCVRQualifiers()); AddPointerWithMoreQualifiedTypeVariants(Context.getPointerType(QualVoid)); } @@ -2923,19 +2909,19 @@ BuiltinCandidateTypeSet::AddTypesConvertedFrom(QualType Ty, // No conversion functions in incomplete types. return; } - + CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(TyRec->getDecl()); // FIXME: Visit conversion functions in the base classes, too. - OverloadedFunctionDecl *Conversions + OverloadedFunctionDecl *Conversions = ClassDecl->getConversionFunctions(); - for (OverloadedFunctionDecl::function_iterator Func + for (OverloadedFunctionDecl::function_iterator Func = Conversions->function_begin(); Func != Conversions->function_end(); ++Func) { CXXConversionDecl *Conv; FunctionTemplateDecl *ConvTemplate; GetFunctionAndTemplate(*Func, Conv, ConvTemplate); - // Skip conversion function templates; they don't tell us anything + // Skip conversion function templates; they don't tell us anything // about which builtin types we can convert to. if (ConvTemplate) continue; @@ -2952,33 +2938,33 @@ BuiltinCandidateTypeSet::AddTypesConvertedFrom(QualType Ty, /// given type to the candidate set. static void AddBuiltinAssignmentOperatorCandidates(Sema &S, QualType T, - Expr **Args, + Expr **Args, unsigned NumArgs, OverloadCandidateSet &CandidateSet) { QualType ParamTypes[2]; - + // T& operator=(T&, T) ParamTypes[0] = S.Context.getLValueReferenceType(T); ParamTypes[1] = T; S.AddBuiltinCandidate(ParamTypes[0], ParamTypes, Args, 2, CandidateSet, /*IsAssignmentOperator=*/true); - + if (!S.Context.getCanonicalType(T).isVolatileQualified()) { // volatile T& operator=(volatile T&, T) ParamTypes[0] = S.Context.getLValueReferenceType(T.withVolatile()); ParamTypes[1] = T; S.AddBuiltinCandidate(ParamTypes[0], ParamTypes, Args, 2, CandidateSet, - /*IsAssignmentOperator=*/true); + /*IsAssignmentOperator=*/true); } } - + /// AddBuiltinOperatorCandidates - Add the appropriate built-in /// operator overloads to the candidate set (C++ [over.built]), based /// on the operator @p Op and the arguments given. For example, if the /// operator is a binary '+', this routine might add "int /// operator+(int, int)" to cover integer addition. void -Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, +Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, Expr **Args, unsigned NumArgs, OverloadCandidateSet& CandidateSet) { // The set of "promoted arithmetic types", which are the arithmetic @@ -2988,14 +2974,14 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // FIXME: What about complex? const unsigned FirstIntegralType = 0; const unsigned LastIntegralType = 13; - const unsigned FirstPromotedIntegralType = 7, + const unsigned FirstPromotedIntegralType = 7, LastPromotedIntegralType = 13; const unsigned FirstPromotedArithmeticType = 7, LastPromotedArithmeticType = 16; const unsigned NumArithmeticTypes = 16; QualType ArithmeticTypes[NumArithmeticTypes] = { - Context.BoolTy, Context.CharTy, Context.WCharTy, -// FIXME: Context.Char16Ty, Context.Char32Ty, + Context.BoolTy, Context.CharTy, Context.WCharTy, +// FIXME: Context.Char16Ty, Context.Char32Ty, Context.SignedCharTy, Context.ShortTy, Context.UnsignedCharTy, Context.UnsignedShortTy, Context.IntTy, Context.LongTy, Context.LongLongTy, @@ -3029,7 +3015,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, break; case OO_Star: // '*' is either unary or binary - if (NumArgs == 1) + if (NumArgs == 1) goto UnaryStar; else goto BinaryStar; @@ -3074,10 +3060,10 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // // VQ T& operator--(VQ T&); // T operator--(VQ T&, int); - for (unsigned Arith = (Op == OO_PlusPlus? 0 : 1); + for (unsigned Arith = (Op == OO_PlusPlus? 0 : 1); Arith < NumArithmeticTypes; ++Arith) { QualType ArithTy = ArithmeticTypes[Arith]; - QualType ParamTypes[2] + QualType ParamTypes[2] = { Context.getLValueReferenceType(ArithTy), Context.IntTy }; // Non-volatile version. @@ -3110,10 +3096,10 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, if (!(*Ptr)->getAs<PointerType>()->getPointeeType()->isObjectType()) continue; - QualType ParamTypes[2] = { - Context.getLValueReferenceType(*Ptr), Context.IntTy + QualType ParamTypes[2] = { + Context.getLValueReferenceType(*Ptr), Context.IntTy }; - + // Without volatile if (NumArgs == 1) AddBuiltinCandidate(ParamTypes[0], ParamTypes, Args, 1, CandidateSet); @@ -3146,7 +3132,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, Ptr != CandidateTypes.pointer_end(); ++Ptr) { QualType ParamTy = *Ptr; QualType PointeeTy = ParamTy->getAs<PointerType>()->getPointeeType(); - AddBuiltinCandidate(Context.getLValueReferenceType(PointeeTy), + AddBuiltinCandidate(Context.getLValueReferenceType(PointeeTy), &ParamTy, Args, 1, CandidateSet); } break; @@ -3162,7 +3148,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, QualType ParamTy = *Ptr; AddBuiltinCandidate(ParamTy, &ParamTy, Args, 1, CandidateSet); } - + // Fall through UnaryMinus: @@ -3172,7 +3158,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // // T operator+(T); // T operator-(T); - for (unsigned Arith = FirstPromotedArithmeticType; + for (unsigned Arith = FirstPromotedArithmeticType; Arith < LastPromotedArithmeticType; ++Arith) { QualType ArithTy = ArithmeticTypes[Arith]; AddBuiltinCandidate(ArithTy, &ArithTy, Args, 1, CandidateSet); @@ -3185,7 +3171,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // operator functions of the form // // T operator~(T); - for (unsigned Int = FirstPromotedIntegralType; + for (unsigned Int = FirstPromotedIntegralType; Int < LastPromotedIntegralType; ++Int) { QualType IntTy = ArithmeticTypes[Int]; AddBuiltinCandidate(IntTy, &IntTy, Args, 1, CandidateSet); @@ -3211,12 +3197,12 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, case OO_EqualEqual: case OO_ExclaimEqual: // C++ [over.match.oper]p16: - // For every pointer to member type T, there exist candidate operator - // functions of the form + // For every pointer to member type T, there exist candidate operator + // functions of the form // // bool operator==(T,T); // bool operator!=(T,T); - for (BuiltinCandidateTypeSet::iterator + for (BuiltinCandidateTypeSet::iterator MemPtr = CandidateTypes.member_pointer_begin(), MemPtrEnd = CandidateTypes.member_pointer_end(); MemPtr != MemPtrEnd; @@ -3224,9 +3210,9 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, QualType ParamTypes[2] = { *MemPtr, *MemPtr }; AddBuiltinCandidate(Context.BoolTy, ParamTypes, Args, 2, CandidateSet); } - + // Fall through - + case OO_Less: case OO_Greater: case OO_LessEqual: @@ -3235,7 +3221,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // // For every pointer or enumeration type T, there exist // candidate operator functions of the form - // + // // bool operator<(T, T); // bool operator>(T, T); // bool operator<=(T, T); @@ -3247,7 +3233,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, QualType ParamTypes[2] = { *Ptr, *Ptr }; AddBuiltinCandidate(Context.BoolTy, ParamTypes, Args, 2, CandidateSet); } - for (BuiltinCandidateTypeSet::iterator Enum + for (BuiltinCandidateTypeSet::iterator Enum = CandidateTypes.enumeration_begin(); Enum != CandidateTypes.enumeration_end(); ++Enum) { QualType ParamTypes[2] = { *Enum, *Enum }; @@ -3266,7 +3252,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // // For every cv-qualified or cv-unqualified object type T // there exist candidate operator functions of the form - // + // // T* operator+(T*, ptrdiff_t); // T& operator[](T*, ptrdiff_t); [BELOW] // T* operator-(T*, ptrdiff_t); @@ -3279,7 +3265,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // exist candidate operator functions of the form // // ptrdiff_t operator-(T, T); - for (BuiltinCandidateTypeSet::iterator Ptr + for (BuiltinCandidateTypeSet::iterator Ptr = CandidateTypes.pointer_begin(); Ptr != CandidateTypes.pointer_end(); ++Ptr) { QualType ParamTypes[2] = { *Ptr, Context.getPointerDiffType() }; @@ -3334,9 +3320,9 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // where LR is the result of the usual arithmetic conversions // between types L and R. // Our candidates ignore the first parameter. - for (unsigned Left = FirstPromotedArithmeticType; + for (unsigned Left = FirstPromotedArithmeticType; Left < LastPromotedArithmeticType; ++Left) { - for (unsigned Right = FirstPromotedArithmeticType; + for (unsigned Right = FirstPromotedArithmeticType; Right < LastPromotedArithmeticType; ++Right) { QualType LandR[2] = { ArithmeticTypes[Left], ArithmeticTypes[Right] }; QualType Result @@ -3368,9 +3354,9 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // // where LR is the result of the usual arithmetic conversions // between types L and R. - for (unsigned Left = FirstPromotedIntegralType; + for (unsigned Left = FirstPromotedIntegralType; Left < LastPromotedIntegralType; ++Left) { - for (unsigned Right = FirstPromotedIntegralType; + for (unsigned Right = FirstPromotedIntegralType; Right < LastPromotedIntegralType; ++Right) { QualType LandR[2] = { ArithmeticTypes[Left], ArithmeticTypes[Right] }; QualType Result = (Op == OO_LessLess || Op == OO_GreaterGreater) @@ -3393,13 +3379,13 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, Enum = CandidateTypes.enumeration_begin(), EnumEnd = CandidateTypes.enumeration_end(); Enum != EnumEnd; ++Enum) - AddBuiltinAssignmentOperatorCandidates(*this, *Enum, Args, 2, + AddBuiltinAssignmentOperatorCandidates(*this, *Enum, Args, 2, CandidateSet); for (BuiltinCandidateTypeSet::iterator MemPtr = CandidateTypes.member_pointer_begin(), MemPtrEnd = CandidateTypes.member_pointer_end(); MemPtr != MemPtrEnd; ++MemPtr) - AddBuiltinAssignmentOperatorCandidates(*this, *MemPtr, Args, 2, + AddBuiltinAssignmentOperatorCandidates(*this, *MemPtr, Args, 2, CandidateSet); // Fall through. @@ -3455,7 +3441,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // VQ L& operator+=(VQ L&, R); // VQ L& operator-=(VQ L&, R); for (unsigned Left = 0; Left < NumArithmeticTypes; ++Left) { - for (unsigned Right = FirstPromotedArithmeticType; + for (unsigned Right = FirstPromotedArithmeticType; Right < LastPromotedArithmeticType; ++Right) { QualType ParamTypes[2]; ParamTypes[1] = ArithmeticTypes[Right]; @@ -3493,7 +3479,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // VQ L& operator^=(VQ L&, R); // VQ L& operator|=(VQ L&, R); for (unsigned Left = FirstIntegralType; Left < LastIntegralType; ++Left) { - for (unsigned Right = FirstPromotedIntegralType; + for (unsigned Right = FirstPromotedIntegralType; Right < LastPromotedIntegralType; ++Right) { QualType ParamTypes[2]; ParamTypes[1] = ArithmeticTypes[Right]; @@ -3516,7 +3502,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // // There also exist candidate operator functions of the form // - // bool operator!(bool); + // bool operator!(bool); // bool operator&&(bool, bool); [BELOW] // bool operator||(bool, bool); [BELOW] QualType ParamTy = Context.BoolTy; @@ -3547,7 +3533,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // // For every cv-qualified or cv-unqualified object type T there // exist candidate operator functions of the form - // + // // T* operator+(T*, ptrdiff_t); [ABOVE] // T& operator[](T*, ptrdiff_t); // T* operator-(T*, ptrdiff_t); [ABOVE] @@ -3606,7 +3592,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, /// given function name (which may also be an operator name) and adds /// all of the overload candidates found by ADL to the overload /// candidate set (C++ [basic.lookup.argdep]). -void +void Sema::AddArgumentDependentLookupCandidates(DeclarationName Name, Expr **Args, unsigned NumArgs, OverloadCandidateSet& CandidateSet) { @@ -3645,7 +3631,7 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name, if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*Func)) AddOverloadCandidate(FD, Args, NumArgs, CandidateSet); else - AddTemplateOverloadCandidate(cast<FunctionTemplateDecl>(*Func), + AddTemplateOverloadCandidate(cast<FunctionTemplateDecl>(*Func), /*FIXME: explicit args */false, 0, 0, Args, NumArgs, CandidateSet); } @@ -3653,10 +3639,9 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name, /// isBetterOverloadCandidate - Determines whether the first overload /// candidate is a better candidate than the second (C++ 13.3.3p1). -bool +bool Sema::isBetterOverloadCandidate(const OverloadCandidate& Cand1, - const OverloadCandidate& Cand2) -{ + const OverloadCandidate& Cand2) { // Define viable functions to be better candidates than non-viable // functions. if (!Cand2.Viable) @@ -3675,8 +3660,8 @@ Sema::isBetterOverloadCandidate(const OverloadCandidate& Cand1, StartArg = 1; // C++ [over.match.best]p1: - // A viable function F1 is defined to be a better function than another - // viable function F2 if for all arguments i, ICSi(F1) is not a worse + // A viable function F1 is defined to be a better function than another + // viable function F2 if for all arguments i, ICSi(F1) is not a worse // conversion sequence than ICSi(F2), and then... unsigned NumArgs = Cand1.Conversions.size(); assert(Cand2.Conversions.size() == NumArgs && "Overload candidate mismatch"); @@ -3699,20 +3684,20 @@ Sema::isBetterOverloadCandidate(const OverloadCandidate& Cand1, } } - // -- for some argument j, ICSj(F1) is a better conversion sequence than + // -- for some argument j, ICSj(F1) is a better conversion sequence than // ICSj(F2), or, if not that, if (HasBetterConversion) return true; - // - F1 is a non-template function and F2 is a function template + // - F1 is a non-template function and F2 is a function template // specialization, or, if not that, if (Cand1.Function && !Cand1.Function->getPrimaryTemplate() && Cand2.Function && Cand2.Function->getPrimaryTemplate()) return true; - - // -- F1 and F2 are function template specializations, and the function - // template for F1 is more specialized than the template for F2 - // according to the partial ordering rules described in 14.5.5.2, or, + + // -- F1 and F2 are function template specializations, and the function + // template for F1 is more specialized than the template for F2 + // according to the partial ordering rules described in 14.5.5.2, or, // if not that, if (Cand1.Function && Cand1.Function->getPrimaryTemplate() && Cand2.Function && Cand2.Function->getPrimaryTemplate()) @@ -3728,8 +3713,8 @@ Sema::isBetterOverloadCandidate(const OverloadCandidate& Cand1, // the type of the entity being initialized) is a better // conversion sequence than the standard conversion sequence // from the return type of F2 to the destination type. - if (Cand1.Function && Cand2.Function && - isa<CXXConversionDecl>(Cand1.Function) && + if (Cand1.Function && Cand2.Function && + isa<CXXConversionDecl>(Cand1.Function) && isa<CXXConversionDecl>(Cand2.Function)) { switch (CompareStandardConversionSequences(Cand1.FinalConversion, Cand2.FinalConversion)) { @@ -3750,7 +3735,7 @@ Sema::isBetterOverloadCandidate(const OverloadCandidate& Cand1, return false; } -/// \brief Computes the best viable function (C++ 13.3.3) +/// \brief Computes the best viable function (C++ 13.3.3) /// within an overload candidate set. /// /// \param CandidateSet the set of candidate functions. @@ -3758,15 +3743,14 @@ Sema::isBetterOverloadCandidate(const OverloadCandidate& Cand1, /// \param Loc the location of the function name (or operator symbol) for /// which overload resolution occurs. /// -/// \param Best f overload resolution was successful or found a deleted +/// \param Best f overload resolution was successful or found a deleted /// function, Best points to the candidate function found. /// /// \returns The result of overload resolution. -Sema::OverloadingResult +Sema::OverloadingResult Sema::BestViableFunction(OverloadCandidateSet& CandidateSet, SourceLocation Loc, - OverloadCandidateSet::iterator& Best) -{ + OverloadCandidateSet::iterator& Best) { // Find the best viable function. Best = CandidateSet.end(); for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(); @@ -3785,24 +3769,24 @@ Sema::BestViableFunction(OverloadCandidateSet& CandidateSet, // function. If not, we have an ambiguity. for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(); Cand != CandidateSet.end(); ++Cand) { - if (Cand->Viable && + if (Cand->Viable && Cand != Best && !isBetterOverloadCandidate(*Best, *Cand)) { Best = CandidateSet.end(); return OR_Ambiguous; } } - + // Best is the best viable function. if (Best->Function && - (Best->Function->isDeleted() || + (Best->Function->isDeleted() || Best->Function->getAttr<UnavailableAttr>())) return OR_Deleted; // C++ [basic.def.odr]p2: // An overloaded function is used if it is selected by overload resolution - // when referred to from a potentially-evaluated expression. [Note: this - // covers calls to named functions (5.2.2), operator overloading + // when referred to from a potentially-evaluated expression. [Note: this + // covers calls to named functions (5.2.2), operator overloading // (clause 13), user-defined conversions (12.3.2), allocation function for // placement new (5.3.4), as well as non-default initialization (8.5). if (Best->Function) @@ -3813,10 +3797,9 @@ Sema::BestViableFunction(OverloadCandidateSet& CandidateSet, /// PrintOverloadCandidates - When overload resolution fails, prints /// diagnostic messages containing the candidates in the candidate /// set. If OnlyViable is true, only viable candidates will be printed. -void +void Sema::PrintOverloadCandidates(OverloadCandidateSet& CandidateSet, - bool OnlyViable) -{ + bool OnlyViable) { OverloadCandidateSet::iterator Cand = CandidateSet.begin(), LastCand = CandidateSet.end(); for (; Cand != LastCand; ++Cand) { @@ -3866,7 +3849,7 @@ Sema::PrintOverloadCandidates(OverloadCandidateSet& CandidateSet, // FIXME: We need to get the identifier in here // FIXME: Do we want the error message to point at the operator? // (built-ins won't have a location) - QualType FnType + QualType FnType = Context.getFunctionType(Cand->BuiltinTypes.ResultTy, Cand->BuiltinTypes.ParamTypes, Cand->Conversions.size(), @@ -3886,7 +3869,7 @@ Sema::PrintOverloadCandidates(OverloadCandidateSet& CandidateSet, /// @code /// int f(double); /// int f(int); -/// +/// /// int (*pfd)(double) = f; // selects f(double) /// @endcode /// @@ -3915,7 +3898,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, // Find the actual overloaded function declaration. OverloadedFunctionDecl *Ovl = 0; - + // C++ [over.over]p1: // [...] [Note: any redundant set of parentheses surrounding the // overloaded function name is ignored (5.1). ] @@ -3936,21 +3919,21 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, FunctionTemplate = dyn_cast<FunctionTemplateDecl>(DR->getDecl()); } - // If there's no overloaded function declaration or function template, + // If there's no overloaded function declaration or function template, // we're done. if (!Ovl && !FunctionTemplate) return 0; - + OverloadIterator Fun; if (Ovl) Fun = Ovl; else Fun = FunctionTemplate; - + // Look through all of the overloaded functions, searching for one // whose type matches exactly. llvm::SmallPtrSet<FunctionDecl *, 4> Matches; - + bool FoundNonTemplateFunction = false; for (OverloadIterator FunEnd; Fun != FunEnd; ++Fun) { // C++ [over.over]p3: @@ -3960,22 +3943,22 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, // type "pointer-to-member-function." // Note that according to DR 247, the containing class does not matter. - if (FunctionTemplateDecl *FunctionTemplate + if (FunctionTemplateDecl *FunctionTemplate = dyn_cast<FunctionTemplateDecl>(*Fun)) { - if (CXXMethodDecl *Method + if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FunctionTemplate->getTemplatedDecl())) { - // Skip non-static function templates when converting to pointer, and + // Skip non-static function templates when converting to pointer, and // static when converting to member pointer. if (Method->isStatic() == IsMember) continue; } else if (IsMember) continue; - + // C++ [over.over]p2: - // If the name is a function template, template argument deduction is - // done (14.8.2.2), and if the argument deduction succeeds, the - // resulting template argument list is used to generate a single - // function template specialization, which is added to the set of + // If the name is a function template, template argument deduction is + // done (14.8.2.2), and if the argument deduction succeeds, the + // resulting template argument list is used to generate a single + // function template specialization, which is added to the set of // overloaded functions considered. FunctionDecl *Specialization = 0; TemplateDeductionInfo Info(Context); @@ -3986,13 +3969,13 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, // FIXME: make a note of the failed deduction for diagnostics. (void)Result; } else { - assert(FunctionType + assert(FunctionType == Context.getCanonicalType(Specialization->getType())); Matches.insert( cast<FunctionDecl>(Specialization->getCanonicalDecl())); } } - + if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(*Fun)) { // Skip non-static functions when converting to pointer, and static // when converting to member pointer. @@ -4006,7 +3989,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, Matches.insert(cast<FunctionDecl>(Fun->getCanonicalDecl())); FoundNonTemplateFunction = true; } - } + } } // If there were 0 or 1 matches, we're done. @@ -4042,7 +4025,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, for (++M; M != MEnd; ++M) if (getMoreSpecializedTemplate((*M)->getPrimaryTemplate(), (*Best)->getPrimaryTemplate(), - false) + false) == (*M)->getPrimaryTemplate()) Best = M; @@ -4074,12 +4057,12 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, // candidates output later. RemainingMatches.append(Matches.begin(), Matches.end()); } - - // [...] After such eliminations, if any, there shall remain exactly one + + // [...] After such eliminations, if any, there shall remain exactly one // selected function. if (RemainingMatches.size() == 1) return RemainingMatches.front(); - + // FIXME: We should probably return the same thing that BestViableFunction // returns (even if we issue the diagnostics here). Diag(From->getLocStart(), diag::err_addr_ovl_ambiguous) @@ -4103,7 +4086,7 @@ FunctionDecl *Sema::ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee, unsigned NumExplicitTemplateArgs, SourceLocation LParenLoc, Expr **Args, unsigned NumArgs, - SourceLocation *CommaLocs, + SourceLocation *CommaLocs, SourceLocation RParenLoc, bool &ArgumentDependentLookup) { OverloadCandidateSet CandidateSet; @@ -4117,16 +4100,16 @@ FunctionDecl *Sema::ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee, // and let Y be the lookup set produced by argument dependent // lookup (defined as follows). If X contains // - // -- a declaration of a class member, or + // -- a declaration of a class member, or // // -- a block-scope function declaration that is not a - // using-declaration, or - // + // using-declaration, or + // // -- a declaration that is neither a function or a function // template // - // then Y is empty. - if (OverloadedFunctionDecl *Ovl + // then Y is empty. + if (OverloadedFunctionDecl *Ovl = dyn_cast_or_null<OverloadedFunctionDecl>(Callee)) { for (OverloadedFunctionDecl::function_iterator Func = Ovl->function_begin(), FuncEnd = Ovl->function_end(); @@ -4135,7 +4118,7 @@ FunctionDecl *Sema::ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee, if (FunctionDecl *FunDecl = dyn_cast<FunctionDecl>(*Func)) { if (HasExplicitTemplateArgs) continue; - + AddOverloadCandidate(FunDecl, Args, NumArgs, CandidateSet); Ctx = FunDecl->getDeclContext(); } else { @@ -4158,11 +4141,11 @@ FunctionDecl *Sema::ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee, if (Func->getDeclContext()->isRecord() || Func->getDeclContext()->isFunctionOrMethod()) ArgumentDependentLookup = false; - } else if (FunctionTemplateDecl *FuncTemplate + } else if (FunctionTemplateDecl *FuncTemplate = dyn_cast_or_null<FunctionTemplateDecl>(Callee)) { AddTemplateOverloadCandidate(FuncTemplate, HasExplicitTemplateArgs, ExplicitTemplateArgs, - NumExplicitTemplateArgs, + NumExplicitTemplateArgs, Args, NumArgs, CandidateSet); if (FuncTemplate->getDeclContext()->isRecord()) @@ -4231,7 +4214,7 @@ FunctionDecl *Sema::ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee, Sema::OwningExprResult Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, unsigned OpcIn, FunctionSet &Functions, - ExprArg input) { + ExprArg input) { UnaryOperator::Opcode Opc = static_cast<UnaryOperator::Opcode>(OpcIn); Expr *Input = (Expr *)input.get(); @@ -4241,28 +4224,28 @@ Sema::OwningExprResult Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, Expr *Args[2] = { Input, 0 }; unsigned NumArgs = 1; - + // For post-increment and post-decrement, add the implicit '0' as // the second argument, so that we know this is a post-increment or // post-decrement. if (Opc == UnaryOperator::PostInc || Opc == UnaryOperator::PostDec) { llvm::APSInt Zero(Context.getTypeSize(Context.IntTy), false); - Args[1] = new (Context) IntegerLiteral(Zero, Context.IntTy, + Args[1] = new (Context) IntegerLiteral(Zero, Context.IntTy, SourceLocation()); NumArgs = 2; } if (Input->isTypeDependent()) { - OverloadedFunctionDecl *Overloads + OverloadedFunctionDecl *Overloads = OverloadedFunctionDecl::Create(Context, CurContext, OpName); - for (FunctionSet::iterator Func = Functions.begin(), + for (FunctionSet::iterator Func = Functions.begin(), FuncEnd = Functions.end(); Func != FuncEnd; ++Func) Overloads->addOverload(*Func); DeclRefExpr *Fn = new (Context) DeclRefExpr(Overloads, Context.OverloadTy, OpLoc, false, false); - + input.release(); return Owned(new (Context) CXXOperatorCallExpr(Context, Op, Fn, &Args[0], NumArgs, @@ -4288,11 +4271,11 @@ Sema::OwningExprResult Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, case OR_Success: { // We found a built-in operator or an overloaded operator. FunctionDecl *FnDecl = Best->Function; - + if (FnDecl) { // We matched an overloaded operator. Build a call to that // operator. - + // Convert the arguments. if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FnDecl)) { if (PerformObjectArgumentInitialization(Input, Method)) @@ -4309,15 +4292,15 @@ Sema::OwningExprResult Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, QualType ResultTy = FnDecl->getType()->getAsFunctionType()->getResultType(); ResultTy = ResultTy.getNonReferenceType(); - + // Build the actual expression node. Expr *FnExpr = new (Context) DeclRefExpr(FnDecl, FnDecl->getType(), SourceLocation()); UsualUnaryConversions(FnExpr); - + input.release(); - - Expr *CE = new (Context) CXXOperatorCallExpr(Context, Op, FnExpr, + + Expr *CE = new (Context) CXXOperatorCallExpr(Context, Op, FnExpr, &Input, 1, ResultTy, OpLoc); return MaybeBindToTemporary(CE); } else { @@ -4377,9 +4360,9 @@ Sema::OwningExprResult Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, /// /// \param LHS Left-hand argument. /// \param RHS Right-hand argument. -Sema::OwningExprResult +Sema::OwningExprResult Sema::CreateOverloadedBinOp(SourceLocation OpLoc, - unsigned OpcIn, + unsigned OpcIn, FunctionSet &Functions, Expr *LHS, Expr *RHS) { Expr *Args[2] = { LHS, RHS }; @@ -4397,18 +4380,18 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc, return Owned(new (Context) BinaryOperator(Args[0], Args[1], Opc, Context.DependentTy, OpLoc)); - OverloadedFunctionDecl *Overloads + OverloadedFunctionDecl *Overloads = OverloadedFunctionDecl::Create(Context, CurContext, OpName); - for (FunctionSet::iterator Func = Functions.begin(), + for (FunctionSet::iterator Func = Functions.begin(), FuncEnd = Functions.end(); Func != FuncEnd; ++Func) Overloads->addOverload(*Func); DeclRefExpr *Fn = new (Context) DeclRefExpr(Overloads, Context.OverloadTy, OpLoc, false, false); - + return Owned(new (Context) CXXOperatorCallExpr(Context, Op, Fn, - Args, 2, + Args, 2, Context.DependentTy, OpLoc)); } @@ -4473,7 +4456,7 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc, OpLoc); UsualUnaryConversions(FnExpr); - Expr *CE = new (Context) CXXOperatorCallExpr(Context, Op, FnExpr, + Expr *CE = new (Context) CXXOperatorCallExpr(Context, Op, FnExpr, Args, 2, ResultTy, OpLoc); return MaybeBindToTemporary(CE); } else { @@ -4534,8 +4517,8 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc, /// expression refers to a member function or an overloaded member /// function. Sema::ExprResult -Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, - SourceLocation LParenLoc, Expr **Args, +Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, + SourceLocation LParenLoc, Expr **Args, unsigned NumArgs, SourceLocation *CommaLocs, SourceLocation RParenLoc) { // Dig out the member expression. This holds both the object @@ -4556,11 +4539,11 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, // Add overload candidates OverloadCandidateSet CandidateSet; DeclarationName DeclName = MemExpr->getMemberDecl()->getDeclName(); - + for (OverloadIterator Func(MemExpr->getMemberDecl()), FuncEnd; Func != FuncEnd; ++Func) { if ((Method = dyn_cast<CXXMethodDecl>(*Func))) - AddMethodCandidate(Method, ObjectArg, Args, NumArgs, CandidateSet, + AddMethodCandidate(Method, ObjectArg, Args, NumArgs, CandidateSet, /*SuppressUserConversions=*/false); else AddMethodTemplateCandidate(cast<FunctionTemplateDecl>(*Func), @@ -4571,7 +4554,7 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, CandidateSet, /*SuppressUsedConversions=*/false); } - + OverloadCandidateSet::iterator Best; switch (BestViableFunction(CandidateSet, MemExpr->getLocStart(), Best)) { case OR_Success: @@ -4579,7 +4562,7 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, break; case OR_No_Viable_Function: - Diag(MemExpr->getSourceRange().getBegin(), + Diag(MemExpr->getSourceRange().getBegin(), diag::err_ovl_no_viable_member_function_in_call) << DeclName << MemExprE->getSourceRange(); PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false); @@ -4587,7 +4570,7 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, return true; case OR_Ambiguous: - Diag(MemExpr->getSourceRange().getBegin(), + Diag(MemExpr->getSourceRange().getBegin(), diag::err_ovl_ambiguous_member_call) << DeclName << MemExprE->getSourceRange(); PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false); @@ -4595,7 +4578,7 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, return true; case OR_Deleted: - Diag(MemExpr->getSourceRange().getBegin(), + Diag(MemExpr->getSourceRange().getBegin(), diag::err_ovl_deleted_member_call) << Best->Function->isDeleted() << DeclName << MemExprE->getSourceRange(); @@ -4610,21 +4593,21 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, } assert(Method && "Member call to something that isn't a method?"); - ExprOwningPtr<CXXMemberCallExpr> + ExprOwningPtr<CXXMemberCallExpr> TheCall(this, new (Context) CXXMemberCallExpr(Context, MemExpr, Args, - NumArgs, + NumArgs, Method->getResultType().getNonReferenceType(), RParenLoc)); // Convert the object argument (for a non-static member function call). - if (!Method->isStatic() && + if (!Method->isStatic() && PerformObjectArgumentInitialization(ObjectArg, Method)) return true; MemExpr->setBase(ObjectArg); // Convert the rest of the arguments const FunctionProtoType *Proto = cast<FunctionProtoType>(Method->getType()); - if (ConvertArgumentsForCall(&*TheCall, MemExpr, Method, Proto, Args, NumArgs, + if (ConvertArgumentsForCall(&*TheCall, MemExpr, Method, Proto, Args, NumArgs, RParenLoc)) return true; @@ -4638,15 +4621,15 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, /// type (C++ [over.call.object]), which can end up invoking an /// overloaded function call operator (@c operator()) or performing a /// user-defined conversion on the object argument. -Sema::ExprResult -Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, +Sema::ExprResult +Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, Expr **Args, unsigned NumArgs, - SourceLocation *CommaLocs, + SourceLocation *CommaLocs, SourceLocation RParenLoc) { assert(Object->getType()->isRecordType() && "Requires object type argument"); const RecordType *Record = Object->getType()->getAs<RecordType>(); - + // C++ [over.call.object]p1: // If the primary-expression E in the function call syntax // evaluates to a class object of type "cv T", then the set of @@ -4659,7 +4642,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, DeclContext::lookup_const_iterator Oper, OperEnd; for (llvm::tie(Oper, OperEnd) = Record->getDecl()->lookup(OpName); Oper != OperEnd; ++Oper) - AddMethodCandidate(cast<CXXMethodDecl>(*Oper), Object, Args, NumArgs, + AddMethodCandidate(cast<CXXMethodDecl>(*Oper), Object, Args, NumArgs, CandidateSet, /*SuppressUserConversions=*/false); // C++ [over.call.object]p2: @@ -4679,12 +4662,12 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, // functions for each conversion function declared in an // accessible base class provided the function is not hidden // within T by another intervening declaration. - + if (!RequireCompleteType(SourceLocation(), Object->getType(), 0)) { // FIXME: Look in base classes for more conversion operators! - OverloadedFunctionDecl *Conversions + OverloadedFunctionDecl *Conversions = cast<CXXRecordDecl>(Record->getDecl())->getConversionFunctions(); - for (OverloadedFunctionDecl::function_iterator + for (OverloadedFunctionDecl::function_iterator Func = Conversions->function_begin(), FuncEnd = Conversions->function_end(); Func != FuncEnd; ++Func) { @@ -4707,7 +4690,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, AddSurrogateCandidate(Conv, Proto, Object, Args, NumArgs, CandidateSet); } } - + // Perform overload resolution. OverloadCandidateSet::iterator Best; switch (BestViableFunction(CandidateSet, Object->getLocStart(), Best)) { @@ -4717,7 +4700,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, break; case OR_No_Viable_Function: - Diag(Object->getSourceRange().getBegin(), + Diag(Object->getSourceRange().getBegin(), diag::err_ovl_no_viable_object_call) << Object->getType() << Object->getSourceRange(); PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false); @@ -4737,7 +4720,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, << Object->getType() << Object->getSourceRange(); PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/true); break; - } + } if (Best == CandidateSet.end()) { // We had an error; delete all of the subexpressions and return @@ -4751,7 +4734,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, if (Best->Function == 0) { // Since there is no function declaration, this is one of the // surrogate candidates. Dig out the conversion function. - CXXConversionDecl *Conv + CXXConversionDecl *Conv = cast<CXXConversionDecl>( Best->Conversions[0].UserDefined.ConversionFunction); @@ -4790,16 +4773,16 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, MethodArgs[0] = Object; for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx) MethodArgs[ArgIdx + 1] = Args[ArgIdx]; - - Expr *NewFn = new (Context) DeclRefExpr(Method, Method->getType(), + + Expr *NewFn = new (Context) DeclRefExpr(Method, Method->getType(), SourceLocation()); UsualUnaryConversions(NewFn); // Once we've built TheCall, all of the expressions are properly // owned. QualType ResultTy = Method->getResultType().getNonReferenceType(); - ExprOwningPtr<CXXOperatorCallExpr> - TheCall(this, new (Context) CXXOperatorCallExpr(Context, OO_Call, NewFn, + ExprOwningPtr<CXXOperatorCallExpr> + TheCall(this, new (Context) CXXOperatorCallExpr(Context, OO_Call, NewFn, MethodArgs, NumArgs + 1, ResultTy, RParenLoc)); delete [] MethodArgs; @@ -4823,7 +4806,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, Expr *Arg; if (i < NumArgs) { Arg = Args[i]; - + // Pass the argument. QualType ProtoArgType = Proto->getArgType(i); IsError |= PerformCopyInitialization(Arg, ProtoArgType, "passing"); @@ -4853,13 +4836,13 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, } /// BuildOverloadedArrowExpr - Build a call to an overloaded @c operator-> -/// (if one exists), where @c Base is an expression of class type and +/// (if one exists), where @c Base is an expression of class type and /// @c Member is the name of the member we're trying to find. Sema::OwningExprResult Sema::BuildOverloadedArrowExpr(Scope *S, ExprArg BaseIn, SourceLocation OpLoc) { Expr *Base = static_cast<Expr *>(BaseIn.get()); assert(Base->getType()->isRecordType() && "left-hand side must have class type"); - + // C++ [over.ref]p1: // // [...] An expression x->m is interpreted as (x.operator->())->m @@ -4872,7 +4855,7 @@ Sema::BuildOverloadedArrowExpr(Scope *S, ExprArg BaseIn, SourceLocation OpLoc) { const RecordType *BaseRecord = Base->getType()->getAs<RecordType>(); DeclContext::lookup_const_iterator Oper, OperEnd; - for (llvm::tie(Oper, OperEnd) + for (llvm::tie(Oper, OperEnd) = BaseRecord->getDecl()->lookup(OpName); Oper != OperEnd; ++Oper) AddMethodCandidate(cast<CXXMethodDecl>(*Oper), Base, 0, 0, CandidateSet, /*SuppressUserConversions=*/false); @@ -4920,7 +4903,7 @@ Sema::BuildOverloadedArrowExpr(Scope *S, ExprArg BaseIn, SourceLocation OpLoc) { Expr *FnExpr = new (Context) DeclRefExpr(Method, Method->getType(), SourceLocation()); UsualUnaryConversions(FnExpr); - Base = new (Context) CXXOperatorCallExpr(Context, OO_Arrow, FnExpr, &Base, 1, + Base = new (Context) CXXOperatorCallExpr(Context, OO_Arrow, FnExpr, &Base, 1, Method->getResultType().getNonReferenceType(), OpLoc); return Owned(Base); @@ -4936,13 +4919,13 @@ void Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn) { FixOverloadedFunctionReference(PE->getSubExpr(), Fn); E->setType(PE->getSubExpr()->getType()); } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E)) { - assert(UnOp->getOpcode() == UnaryOperator::AddrOf && + assert(UnOp->getOpcode() == UnaryOperator::AddrOf && "Can only take the address of an overloaded function"); if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Fn)) { if (Method->isStatic()) { // Do nothing: static member functions aren't any different // from non-member functions. - } else if (QualifiedDeclRefExpr *DRE + } else if (QualifiedDeclRefExpr *DRE = dyn_cast<QualifiedDeclRefExpr>(UnOp->getSubExpr())) { // We have taken the address of a pointer to member // function. Perform the computation here so that we get the @@ -4951,7 +4934,7 @@ void Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn) { DRE->setType(Fn->getType()); QualType ClassType = Context.getTypeDeclType(cast<RecordDecl>(Method->getDeclContext())); - E->setType(Context.getMemberPointerType(Fn->getType(), + E->setType(Context.getMemberPointerType(Fn->getType(), ClassType.getTypePtr())); return; } @@ -4960,7 +4943,7 @@ void Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn) { E->setType(Context.getPointerType(UnOp->getSubExpr()->getType())); } else if (DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E)) { assert((isa<OverloadedFunctionDecl>(DR->getDecl()) || - isa<FunctionTemplateDecl>(DR->getDecl())) && + isa<FunctionTemplateDecl>(DR->getDecl())) && "Expected overloaded function or function template"); DR->setDecl(Fn); E->setType(Fn->getType()); diff --git a/lib/Sema/SemaOverload.h b/lib/Sema/SemaOverload.h index 9de3806576..1f3e4df7cb 100644 --- a/lib/Sema/SemaOverload.h +++ b/lib/Sema/SemaOverload.h @@ -59,7 +59,7 @@ namespace clang { ICC_Conversion ///< Conversion }; - ImplicitConversionCategory + ImplicitConversionCategory GetConversionCategory(ImplicitConversionKind Kind); /// ImplicitConversionRank - The rank of an implicit conversion @@ -98,7 +98,7 @@ namespace clang { ImplicitConversionKind Third : 8; /// Deprecated - Whether this the deprecated conversion of a - /// string literal to a pointer to non-const character data + /// string literal to a pointer to non-const character data /// (C++ 4.2p2). bool Deprecated : 1; @@ -106,11 +106,11 @@ namespace clang { /// that we should warn about (if we actually use it). bool IncompatibleObjC : 1; - /// ReferenceBinding - True when this is a reference binding + /// ReferenceBinding - True when this is a reference binding /// (C++ [over.ics.ref]). bool ReferenceBinding : 1; - /// DirectBinding - True when this is a reference binding that is a + /// DirectBinding - True when this is a reference binding that is a /// direct binding (C++ [dcl.init.ref]). bool DirectBinding : 1; @@ -134,7 +134,7 @@ namespace clang { /// conversions. CXXConstructorDecl *CopyConstructor; - void setAsIdentityConversion(); + void setAsIdentityConversion(); ImplicitConversionRank getRank() const; bool isPointerConversionToBool() const; bool isPointerConversionToVoidPointer(ASTContext& Context) const; @@ -159,7 +159,7 @@ namespace clang { /// After - Represents the standard conversion that occurs after /// the actual user-defined conversion. StandardConversionSequence After; - + /// ConversionFunction - The function that will perform the /// user-defined conversion. FunctionDecl* ConversionFunction; @@ -168,7 +168,7 @@ namespace clang { }; /// ImplicitConversionSequence - Represents an implicit conversion - /// sequence, which may be a standard conversion sequence + /// sequence, which may be a standard conversion sequence /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2), /// or an ellipsis conversion sequence (C++ 13.3.3.1.3). struct ImplicitConversionSequence { @@ -211,8 +211,8 @@ namespace clang { /// OverloadCandidate - A single candidate in an overload set (C++ 13.3). struct OverloadCandidate { /// Function - The actual function that this candidate - /// represents. When NULL, this is a built-in candidate - /// (C++ [over.oper]) or a surrogate for a conversion to a + /// represents. When NULL, this is a built-in candidate + /// (C++ [over.oper]) or a surrogate for a conversion to a /// function pointer or reference (C++ [over.call.object]). FunctionDecl *Function; @@ -222,7 +222,7 @@ namespace clang { QualType ResultTy; QualType ParamTypes[3]; } BuiltinTypes; - + /// Surrogate - The conversion function for which this candidate /// is a surrogate, but only if IsSurrogate is true. CXXConversionDecl *Surrogate; diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 76113107ba..4ffca8c8f5 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -52,10 +52,10 @@ Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclGroupPtrTy dg, SourceLocation StartLoc, SourceLocation EndLoc) { DeclGroupRef DG = dg.getAsVal<DeclGroupRef>(); - + // If we have an invalid decl, just return an error. if (DG.isNull()) return StmtError(); - + return Owned(new (Context) DeclStmt(DG, StartLoc, EndLoc)); } @@ -67,12 +67,12 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) { // Ignore expressions that have void type. if (E->getType()->isVoidType()) return; - + SourceLocation Loc; SourceRange R1, R2; if (!E->isUnusedResultAWarning(Loc, R1, R2)) return; - + // Okay, we have an unused result. Depending on what the base expression is, // we might want to make a more specific diagnostic. Check for one of these // cases now. @@ -80,7 +80,7 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) { E = E->IgnoreParens(); if (isa<ObjCImplicitSetterGetterRefExpr>(E)) DiagID = diag::warn_unused_property_expr; - + Diag(Loc, DiagID) << R1 << R2; } @@ -101,7 +101,7 @@ Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R, // We found the end of the list or a statement. Scan for another declstmt. for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i) /*empty*/; - + if (i != NumElts) { Decl *D = *cast<DeclStmt>(Elts[i])->decl_begin(); Diag(D->getLocation(), diag::ext_mixed_decls_code); @@ -112,7 +112,7 @@ Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R, // Ignore statements that are last in a statement expression. if (isStmtExpr && i == NumElts - 1) continue; - + DiagnoseUnusedExprResult(Elts[i]); } @@ -126,9 +126,9 @@ Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprArg lhsval, assert((lhsval.get() != 0) && "missing expression in case statement"); // C99 6.8.4.2p3: The expression shall be an integer constant. - // However, GCC allows any evaluatable integer expression. + // However, GCC allows any evaluatable integer expression. Expr *LHSVal = static_cast<Expr*>(lhsval.get()); - if (!LHSVal->isTypeDependent() && !LHSVal->isValueDependent() && + if (!LHSVal->isTypeDependent() && !LHSVal->isValueDependent() && VerifyIntegerConstantExpression(LHSVal)) return StmtError(); @@ -163,7 +163,7 @@ void Sema::ActOnCaseStmtBody(StmtTy *caseStmt, StmtArg subStmt) { } Action::OwningStmtResult -Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, +Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, StmtArg subStmt, Scope *CurScope) { Stmt *SubStmt = subStmt.takeAs<Stmt>(); @@ -210,7 +210,7 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, StmtArg ThenVal, SourceLocation ElseLoc, StmtArg ElseVal) { OwningExprResult CondResult(CondVal.release()); - + Expr *condExpr = CondResult.takeAs<Expr>(); assert(condExpr && "ActOnIfStmt(): missing expression"); @@ -220,12 +220,12 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, // Take ownership again until we're past the error checking. CondResult = condExpr; QualType condType = condExpr->getType(); - + if (getLangOptions().CPlusPlus) { if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4 return StmtError(); } else if (!condType->isScalarType()) // C99 6.8.4.1p1 - return StmtError(Diag(IfLoc, + return StmtError(Diag(IfLoc, diag::err_typecheck_statement_requires_scalar) << condType << condExpr->getSourceRange()); } @@ -237,14 +237,14 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, // this helps prevent bugs due to typos, such as // if (condition); // do_stuff(); - if (!ElseVal.get()) { + if (!ElseVal.get()) { if (NullStmt* stmt = dyn_cast<NullStmt>(thenStmt)) Diag(stmt->getSemiLoc(), diag::warn_empty_if_body); } Stmt *elseStmt = ElseVal.takeAs<Stmt>(); DiagnoseUnusedExprResult(elseStmt); - + CondResult.release(); return Owned(new (Context) IfStmt(IfLoc, condExpr, thenStmt, ElseLoc, elseStmt)); @@ -264,9 +264,9 @@ Sema::ActOnStartOfSwitchStmt(ExprArg cond) { // of this section. Integral promotions are performed. if (!Cond->isTypeDependent()) { QualType Ty = Cond->getType(); - + // FIXME: Handle class types. - + // If the type is wrong a diagnostic will be emitted later at // ActOnFinishSwitchStmt. if (Ty->isIntegralType() || Ty->isEnumeralType()) { @@ -290,19 +290,19 @@ Sema::ActOnStartOfSwitchStmt(ExprArg cond) { /// the specified diagnostic. void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val, unsigned NewWidth, bool NewSign, - SourceLocation Loc, + SourceLocation Loc, unsigned DiagID) { // Perform a conversion to the promoted condition type if needed. if (NewWidth > Val.getBitWidth()) { // If this is an extension, just do it. llvm::APSInt OldVal(Val); Val.extend(NewWidth); - + // If the input was signed and negative and the output is unsigned, // warn. if (!NewSign && OldVal.isSigned() && OldVal.isNegative()) Diag(Loc, DiagID) << OldVal.toString(10) << Val.toString(10); - + Val.setIsSigned(NewSign); } else if (NewWidth < Val.getBitWidth()) { // If this is a truncation, check for overflow. @@ -313,7 +313,7 @@ void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val, ConvVal.setIsSigned(Val.isSigned()); if (ConvVal != Val) Diag(Loc, DiagID) << Val.toString(10) << ConvVal.toString(10); - + // Regardless of whether a diagnostic was emitted, really do the // truncation. Val.trunc(NewWidth); @@ -323,7 +323,7 @@ void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val, // overflow as well: unsigned(INTMIN) llvm::APSInt OldVal(Val); Val.setIsSigned(NewSign); - + if (Val.isNegative()) // Sign bit changes meaning. Diag(Loc, DiagID) << OldVal.toString(10) << Val.toString(10); } @@ -369,12 +369,12 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, assert(SS == (SwitchStmt*)Switch.get() && "switch stack missing push/pop!"); SS->setBody(BodyStmt, SwitchLoc); - getSwitchStack().pop_back(); + getSwitchStack().pop_back(); Expr *CondExpr = SS->getCond(); QualType CondType = CondExpr->getType(); - if (!CondExpr->isTypeDependent() && + if (!CondExpr->isTypeDependent() && !CondType->isIntegerType()) { // C99 6.8.4.2p1 Diag(SwitchLoc, diag::err_typecheck_statement_requires_integer) << CondType << CondExpr->getSourceRange(); @@ -383,29 +383,29 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, // Get the bitwidth of the switched-on value before promotions. We must // convert the integer case values to this width before comparison. - bool HasDependentValue + bool HasDependentValue = CondExpr->isTypeDependent() || CondExpr->isValueDependent(); - unsigned CondWidth + unsigned CondWidth = HasDependentValue? 0 : static_cast<unsigned>(Context.getTypeSize(CondType)); bool CondIsSigned = CondType->isSignedIntegerType(); - + // Accumulate all of the case values in a vector so that we can sort them // and detect duplicates. This vector contains the APInt for the case after // it has been converted to the condition type. typedef llvm::SmallVector<std::pair<llvm::APSInt, CaseStmt*>, 64> CaseValsTy; CaseValsTy CaseVals; - + // Keep track of any GNU case ranges we see. The APSInt is the low value. std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRanges; - + DefaultStmt *TheDefaultStmt = 0; - + bool CaseListIsErroneous = false; - + for (SwitchCase *SC = SS->getSwitchCaseList(); SC && !HasDependentValue; SC = SC->getNextSwitchCase()) { - + if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC)) { if (TheDefaultStmt) { Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined); @@ -418,10 +418,10 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, CaseListIsErroneous = true; } TheDefaultStmt = DS; - + } else { CaseStmt *CS = cast<CaseStmt>(SC); - + // We already verified that the expression has a i-c-e value (C99 // 6.8.4.2p3) - get that value now. Expr *Lo = CS->getLHS(); @@ -430,9 +430,9 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, HasDependentValue = true; break; } - + llvm::APSInt LoVal = Lo->EvaluateAsInt(Context); - + // Convert the value to the same width/sign as the condition. ConvertIntegerToTypeWarnOnOverflow(LoVal, CondWidth, CondIsSigned, CS->getLHS()->getLocStart(), @@ -442,16 +442,16 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, // cast. ImpCastExprToType(Lo, CondType); CS->setLHS(Lo); - + // If this is a case range, remember it in CaseRanges, otherwise CaseVals. if (CS->getRHS()) { - if (CS->getRHS()->isTypeDependent() || + if (CS->getRHS()->isTypeDependent() || CS->getRHS()->isValueDependent()) { HasDependentValue = true; break; } CaseRanges.push_back(std::make_pair(LoVal, CS)); - } else + } else CaseVals.push_back(std::make_pair(LoVal, CS)); } } @@ -466,7 +466,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, // If we have a duplicate, report it. Diag(CaseVals[i+1].second->getLHS()->getLocStart(), diag::err_duplicate_case) << CaseVals[i].first.toString(10); - Diag(CaseVals[i].second->getLHS()->getLocStart(), + Diag(CaseVals[i].second->getLHS()->getLocStart(), diag::note_duplicate_case_prev); // FIXME: We really want to remove the bogus case stmt from the // substmt, but we have no way to do this right now. @@ -474,31 +474,31 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, } } } - + // Detect duplicate case ranges, which usually don't exist at all in // the first place. if (!CaseRanges.empty()) { // Sort all the case ranges by their low value so we can easily detect // overlaps between ranges. std::stable_sort(CaseRanges.begin(), CaseRanges.end()); - + // Scan the ranges, computing the high values and removing empty ranges. std::vector<llvm::APSInt> HiVals; for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) { CaseStmt *CR = CaseRanges[i].second; Expr *Hi = CR->getRHS(); llvm::APSInt HiVal = Hi->EvaluateAsInt(Context); - + // Convert the value to the same width/sign as the condition. ConvertIntegerToTypeWarnOnOverflow(HiVal, CondWidth, CondIsSigned, CR->getRHS()->getLocStart(), diag::warn_case_value_overflow); - + // If the LHS is not the same type as the condition, insert an implicit // cast. ImpCastExprToType(Hi, CondType); CR->setRHS(Hi); - + // If the low value is bigger than the high value, the case is empty. if (CaseRanges[i].first > HiVal) { Diag(CR->getLHS()->getLocStart(), diag::warn_case_empty_range) @@ -510,7 +510,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, } HiVals.push_back(HiVal); } - + // Rescan the ranges, looking for overlap with singleton values and other // ranges. Since the range list is sorted, we only need to compare case // ranges with their neighbors. @@ -518,12 +518,12 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, llvm::APSInt &CRLo = CaseRanges[i].first; llvm::APSInt &CRHi = HiVals[i]; CaseStmt *CR = CaseRanges[i].second; - + // Check to see whether the case range overlaps with any // singleton cases. CaseStmt *OverlapStmt = 0; llvm::APSInt OverlapVal(32); - + // Find the smallest value >= the lower bound. If I is in the // case range, then we have overlap. CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(), @@ -533,26 +533,26 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, OverlapVal = I->first; // Found overlap with scalar. OverlapStmt = I->second; } - + // Find the smallest value bigger than the upper bound. I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor()); if (I != CaseVals.begin() && (I-1)->first >= CRLo) { OverlapVal = (I-1)->first; // Found overlap with scalar. OverlapStmt = (I-1)->second; } - + // Check to see if this case stmt overlaps with the subsequent // case range. if (i && CRLo <= HiVals[i-1]) { OverlapVal = HiVals[i-1]; // Found overlap with range. OverlapStmt = CaseRanges[i-1].second; } - + if (OverlapStmt) { // If we have a duplicate, report it. Diag(CR->getLHS()->getLocStart(), diag::err_duplicate_case) << OverlapVal.toString(10); - Diag(OverlapStmt->getLHS()->getLocStart(), + Diag(OverlapStmt->getLHS()->getLocStart(), diag::note_duplicate_case_prev); // FIXME: We really want to remove the bogus case stmt from the // substmt, but we have no way to do this right now. @@ -581,7 +581,7 @@ Sema::ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, StmtArg Body) { DefaultFunctionArrayConversion(condExpr); CondArg = condExpr; QualType condType = condExpr->getType(); - + if (getLangOptions().CPlusPlus) { if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4 return StmtError(); @@ -593,7 +593,7 @@ Sema::ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, StmtArg Body) { Stmt *bodyStmt = Body.takeAs<Stmt>(); DiagnoseUnusedExprResult(bodyStmt); - + CondArg.release(); return Owned(new (Context) WhileStmt(condExpr, bodyStmt, WhileLoc)); } @@ -609,12 +609,12 @@ Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, DefaultFunctionArrayConversion(condExpr); Cond = condExpr; QualType condType = condExpr->getType(); - + if (getLangOptions().CPlusPlus) { if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4 return StmtError(); } else if (!condType->isScalarType()) // C99 6.8.5p2 - return StmtError(Diag(DoLoc, + return StmtError(Diag(DoLoc, diag::err_typecheck_statement_requires_scalar) << condType << condExpr->getSourceRange()); } @@ -664,7 +664,7 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, diag::err_typecheck_statement_requires_scalar) << SecondType << Second->getSourceRange()); } - + DiagnoseUnusedExprResult(First); DiagnoseUnusedExprResult(Third); DiagnoseUnusedExprResult(Body); @@ -707,9 +707,9 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, diag::err_selector_element_not_lvalue) << First->getSourceRange()); - FirstType = static_cast<Expr*>(First)->getType(); + FirstType = static_cast<Expr*>(First)->getType(); } - if (!FirstType->isObjCObjectPointerType() && + if (!FirstType->isObjCObjectPointerType() && !FirstType->isBlockPointerType()) Diag(ForLoc, diag::err_selector_element_type) << FirstType << First->getSourceRange(); @@ -832,8 +832,8 @@ Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { // we have a non-void block with an expression, continue checking QualType RetValType = RetValExp->getType(); - // C99 6.8.6.4p3(136): The return statement is not an assignment. The - // overlap restriction of subclause 6.5.16.1 does not apply to the case of + // C99 6.8.6.4p3(136): The return statement is not an assignment. The + // overlap restriction of subclause 6.5.16.1 does not apply to the case of // function return. // In C++ the return statement is handled via a copy initialization. @@ -890,7 +890,7 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { FnRetType = MD->getResultType(); else // If we don't have a function/method context, bail. return StmtError(); - + if (FnRetType->isVoidType()) { if (RetValExp) {// C99 6.8.6.4p1 (ext_ since GCC warns) unsigned D = diag::ext_return_has_expr; @@ -905,7 +905,7 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { << CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl) << RetValExp->getSourceRange(); } - + RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp, true); } return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp)); @@ -926,8 +926,8 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) { // we have a non-void function with an expression, continue checking - // C99 6.8.6.4p3(136): The return statement is not an assignment. The - // overlap restriction of subclause 6.5.16.1 does not apply to the case of + // C99 6.8.6.4p3(136): The return statement is not an assignment. The + // overlap restriction of subclause 6.5.16.1 does not apply to the case of // function return. // C++0x 12.8p15: When certain criteria are met, an implementation is @@ -1009,7 +1009,7 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers.get()); llvm::SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos; - + // The parser verifies that there is a string literal here. if (AsmString->isWide()) return StmtError(Diag(AsmString->getLocStart(),diag::err_asm_wide_character) @@ -1021,7 +1021,7 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character) << Literal->getSourceRange()); - TargetInfo::ConstraintInfo Info(Literal->getStrData(), + TargetInfo::ConstraintInfo Info(Literal->getStrData(), Literal->getByteLength(), Names[i]); if (!Context.Target.validateOutputConstraint(Info)) @@ -1036,7 +1036,7 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, diag::err_asm_invalid_lvalue_in_output) << OutputExpr->getSourceRange()); } - + OutputConstraintInfos.push_back(Info); } @@ -1048,7 +1048,7 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character) << Literal->getSourceRange()); - TargetInfo::ConstraintInfo Info(Literal->getStrData(), + TargetInfo::ConstraintInfo Info(Literal->getStrData(), Literal->getByteLength(), Names[i]); if (!Context.Target.validateInputConstraint(OutputConstraintInfos.data(), @@ -1073,13 +1073,13 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, if (InputExpr->getType()->isVoidType()) { return StmtError(Diag(InputExpr->getLocStart(), diag::err_asm_invalid_type_in_input) - << InputExpr->getType() << Info.getConstraintStr() + << InputExpr->getType() << Info.getConstraintStr() << InputExpr->getSourceRange()); } } - + DefaultFunctionArrayConversion(Exprs[i]); - + InputConstraintInfos.push_back(Info); } @@ -1117,16 +1117,16 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, DeleteStmt(NS); return StmtError(); } - + // Validate tied input operands for type mismatches. for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) { TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i]; - + // If this is a tied constraint, verify that the output and input have // either exactly the same type, or that they are int/ptr operands with the // same size (int/long, int*/long, are ok etc). if (!Info.hasTiedOperand()) continue; - + unsigned TiedTo = Info.getTiedOperand(); Expr *OutputExpr = Exprs[TiedTo]; Expr *InputExpr = Exprs[i+NumOutputs]; @@ -1134,11 +1134,11 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, QualType OutTy = OutputExpr->getType(); if (Context.hasSameType(InTy, OutTy)) continue; // All types can be tied to themselves. - + // Int/ptr operands have some special cases that we allow. if ((OutTy->isIntegerType() || OutTy->isPointerType()) && (InTy->isIntegerType() || InTy->isPointerType())) { - + // They are ok if they are the same size. Tying void* to int is ok if // they are the same size, for example. This also allows tying void* to // int*. @@ -1146,7 +1146,7 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, uint64_t InSize = Context.getTypeSize(InTy); if (OutSize == InSize) continue; - + // If the smaller input/output operand is not mentioned in the asm string, // then we can promote it and the asm string won't notice. Check this // case now. @@ -1154,7 +1154,7 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, for (unsigned p = 0, e = Pieces.size(); p != e; ++p) { AsmStmt::AsmStringPiece &Piece = Pieces[p]; if (!Piece.isOperand()) continue; - + // If this is a reference to the input and if the input was the smaller // one, then we have to reject this asm. if (Piece.getOperandNo() == i+NumOutputs) { @@ -1173,7 +1173,7 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, } } } - + // If the smaller value wasn't mentioned in the asm string, and if the // output was a register, just extend the shorter one to the size of the // larger one. @@ -1181,7 +1181,7 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, OutputConstraintInfos[TiedTo].allowsRegister()) continue; } - + Diag(InputExpr->getLocStart(), diag::err_asm_tying_incompatible_types) << InTy << OutTy << OutputExpr->getSourceRange() @@ -1189,7 +1189,7 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, DeleteStmt(NS); return StmtError(); } - + return Owned(NS); } @@ -1199,18 +1199,18 @@ Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc, StmtArg Body, StmtArg catchList) { Stmt *CatchList = catchList.takeAs<Stmt>(); ParmVarDecl *PVD = cast_or_null<ParmVarDecl>(Parm.getAs<Decl>()); - + // PVD == 0 implies @catch(...). if (PVD) { // If we already know the decl is invalid, reject it. if (PVD->isInvalidDecl()) return StmtError(); - + if (!PVD->getType()->isObjCObjectPointerType()) - return StmtError(Diag(PVD->getLocation(), + return StmtError(Diag(PVD->getLocation(), diag::err_catch_param_not_objc_type)); if (PVD->getType()->isObjCQualifiedIdType()) - return StmtError(Diag(PVD->getLocation(), + return StmtError(Diag(PVD->getLocation(), diag::err_illegal_qualifiers_on_catch_parm)); } @@ -1271,8 +1271,8 @@ Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr, return StmtError(Diag(AtLoc, diag::error_objc_synchronized_expects_object) << SyncExpr->getType() << SyncExpr->getSourceRange()); } - - return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc, + + return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc, SynchExpr.takeAs<Stmt>(), SynchBody.takeAs<Stmt>())); } @@ -1307,12 +1307,12 @@ public: else return getTypeSpecStartLoc() < y.getTypeSpecStartLoc(); } - + bool operator==(const TypeWithHandler& other) const { return t.getTypePtr() == other.t.getTypePtr() && t.getCVRQualifiers() == other.t.getCVRQualifiers(); } - + QualType getQualType() const { return t; } CXXCatchStmt *getCatchStmt() const { return stmt; } SourceLocation getTypeSpecStartLoc() const { @@ -1331,17 +1331,17 @@ Sema::ActOnCXXTryBlock(SourceLocation TryLoc, StmtArg TryBlock, Stmt **Handlers = reinterpret_cast<Stmt**>(RawHandlers.get()); llvm::SmallVector<TypeWithHandler, 8> TypesWithHandlers; - - for(unsigned i = 0; i < NumHandlers; ++i) { + + for (unsigned i = 0; i < NumHandlers; ++i) { CXXCatchStmt *Handler = llvm::cast<CXXCatchStmt>(Handlers[i]); if (!Handler->getExceptionDecl()) { if (i < NumHandlers - 1) return StmtError(Diag(Handler->getLocStart(), diag::err_early_catch_all)); - + continue; } - + const QualType CaughtType = Handler->getCaughtType(); const QualType CanonicalCaughtType = Context.getCanonicalType(CaughtType); TypesWithHandlers.push_back(TypeWithHandler(CanonicalCaughtType, Handler)); @@ -1350,11 +1350,11 @@ Sema::ActOnCXXTryBlock(SourceLocation TryLoc, StmtArg TryBlock, // Detect handlers for the same type as an earlier one. if (NumHandlers > 1) { llvm::array_pod_sort(TypesWithHandlers.begin(), TypesWithHandlers.end()); - + TypeWithHandler prev = TypesWithHandlers[0]; for (unsigned i = 1; i < TypesWithHandlers.size(); ++i) { TypeWithHandler curr = TypesWithHandlers[i]; - + if (curr == prev) { Diag(curr.getTypeSpecStartLoc(), diag::warn_exception_caught_by_earlier_handler) @@ -1363,11 +1363,11 @@ Sema::ActOnCXXTryBlock(SourceLocation TryLoc, StmtArg TryBlock, diag::note_previous_exception_handler) << prev.getCatchStmt()->getCaughtType().getAsString(); } - + prev = curr; } } - + // FIXME: We should detect handlers that cannot catch anything because an // earlier handler catches a superclass. Need to find a method that is not // quadratic for this. diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index dc455185fe..fceac854ee 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -27,10 +27,10 @@ using namespace clang; static NamedDecl *isAcceptableTemplateName(ASTContext &Context, NamedDecl *D) { if (!D) return 0; - + if (isa<TemplateDecl>(D)) return D; - + if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { // C++ [temp.local]p1: // Like normal (non-template) classes, class templates have an @@ -52,14 +52,14 @@ static NamedDecl *isAcceptableTemplateName(ASTContext &Context, NamedDecl *D) { = dyn_cast<ClassTemplateSpecializationDecl>(Record)) return Spec->getSpecializedTemplate(); } - + return 0; } - + OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D); if (!Ovl) return 0; - + for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin(), FEnd = Ovl->function_end(); F != FEnd; ++F) { @@ -71,11 +71,11 @@ static NamedDecl *isAcceptableTemplateName(ASTContext &Context, NamedDecl *D) { if (isa<FunctionTemplateDecl>(*F)) break; } - + if (F != FEnd) { // Build an overloaded function decl containing only the // function templates in Ovl. - OverloadedFunctionDecl *OvlTemplate + OverloadedFunctionDecl *OvlTemplate = OverloadedFunctionDecl::Create(Context, Ovl->getDeclContext(), Ovl->getDeclName()); @@ -85,19 +85,19 @@ static NamedDecl *isAcceptableTemplateName(ASTContext &Context, NamedDecl *D) { if (isa<FunctionTemplateDecl>(*F)) OvlTemplate->addOverload(*F); } - + return OvlTemplate; } return FuncTmpl; } } - + return 0; } TemplateNameKind Sema::isTemplateName(Scope *S, - const IdentifierInfo &II, + const IdentifierInfo &II, SourceLocation IdLoc, const CXXScopeSpec *SS, TypeTy *ObjectTypePtr, @@ -109,7 +109,7 @@ TemplateNameKind Sema::isTemplateName(Scope *S, if (ObjectTypePtr) { // This nested-name-specifier occurs in a member access expression, e.g., // x->B::f, and we are looking into the type of the object. - assert((!SS || !SS->isSet()) && + assert((!SS || !SS->isSet()) && "ObjectType and scope specifier cannot coexist"); QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); LookupCtx = computeDeclContext(ObjectType); @@ -121,29 +121,29 @@ TemplateNameKind Sema::isTemplateName(Scope *S, LookupCtx = computeDeclContext(*SS, EnteringContext); isDependent = isDependentScopeSpecifier(*SS); } - + LookupResult Found; bool ObjectTypeSearchedInScope = false; if (LookupCtx) { // Perform "qualified" name lookup into the declaration context we // computed, which is either the type of the base of a member access - // expression or the declaration context associated with a prior + // expression or the declaration context associated with a prior // nested-name-specifier. // The declaration context must be complete. if (!LookupCtx->isDependentContext() && RequireCompleteDeclContext(*SS)) return TNK_Non_template; - + Found = LookupQualifiedName(LookupCtx, &II, LookupOrdinaryName); - + if (ObjectTypePtr && Found.getKind() == LookupResult::NotFound) { // C++ [basic.lookup.classref]p1: // In a class member access expression (5.2.5), if the . or -> token is - // immediately followed by an identifier followed by a <, the - // identifier must be looked up to determine whether the < is the + // immediately followed by an identifier followed by a <, the + // identifier must be looked up to determine whether the < is the // beginning of a template argument list (14.2) or a less-than operator. - // The identifier is first looked up in the class of the object - // expression. If the identifier is not found, it is then looked up in + // The identifier is first looked up in the class of the object + // expression. If the identifier is not found, it is then looked up in // the context of the entire postfix-expression and shall name a class // or function template. // @@ -153,15 +153,15 @@ TemplateNameKind Sema::isTemplateName(Scope *S, ObjectTypeSearchedInScope = true; } } else if (isDependent) { - // We cannot look into a dependent object type or + // We cannot look into a dependent object type or return TNK_Non_template; } else { // Perform unqualified name lookup in the current scope. Found = LookupName(S, &II, LookupOrdinaryName); } - + // FIXME: Cope with ambiguous name-lookup results. - assert(!Found.isAmbiguous() && + assert(!Found.isAmbiguous() && "Cannot handle template name-lookup ambiguities"); NamedDecl *Template = isAcceptableTemplateName(Context, Found); @@ -170,24 +170,24 @@ TemplateNameKind Sema::isTemplateName(Scope *S, if (ObjectTypePtr && !ObjectTypeSearchedInScope) { // C++ [basic.lookup.classref]p1: - // [...] If the lookup in the class of the object expression finds a + // [...] If the lookup in the class of the object expression finds a // template, the name is also looked up in the context of the entire // postfix-expression and [...] // LookupResult FoundOuter = LookupName(S, &II, LookupOrdinaryName); // FIXME: Handle ambiguities in this lookup better NamedDecl *OuterTemplate = isAcceptableTemplateName(Context, FoundOuter); - + if (!OuterTemplate) { - // - if the name is not found, the name found in the class of the + // - if the name is not found, the name found in the class of the // object expression is used, otherwise } else if (!isa<ClassTemplateDecl>(OuterTemplate)) { - // - if the name is found in the context of the entire - // postfix-expression and does not name a class template, the name + // - if the name is found in the context of the entire + // postfix-expression and does not name a class template, the name // found in the class of the object expression is used, otherwise } else { // - if the name found is a class template, it must refer to the same - // entity as the one found in the class of the object expression, + // entity as the one found in the class of the object expression, // otherwise the program is ill-formed. if (OuterTemplate->getCanonicalDecl() != Template->getCanonicalDecl()) { Diag(IdLoc, diag::err_nested_name_member_ref_lookup_ambiguous) @@ -195,38 +195,38 @@ TemplateNameKind Sema::isTemplateName(Scope *S, Diag(Template->getLocation(), diag::note_ambig_member_ref_object_type) << QualType::getFromOpaquePtr(ObjectTypePtr); Diag(OuterTemplate->getLocation(), diag::note_ambig_member_ref_scope); - - // Recover by taking the template that we found in the object + + // Recover by taking the template that we found in the object // expression's type. } - } + } } - + if (SS && SS->isSet() && !SS->isInvalid()) { - NestedNameSpecifier *Qualifier + NestedNameSpecifier *Qualifier = static_cast<NestedNameSpecifier *>(SS->getScopeRep()); - if (OverloadedFunctionDecl *Ovl + if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(Template)) - TemplateResult + TemplateResult = TemplateTy::make(Context.getQualifiedTemplateName(Qualifier, false, Ovl)); else - TemplateResult + TemplateResult = TemplateTy::make(Context.getQualifiedTemplateName(Qualifier, false, - cast<TemplateDecl>(Template))); - } else if (OverloadedFunctionDecl *Ovl + cast<TemplateDecl>(Template))); + } else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(Template)) { TemplateResult = TemplateTy::make(TemplateName(Ovl)); } else { TemplateResult = TemplateTy::make( TemplateName(cast<TemplateDecl>(Template))); } - - if (isa<ClassTemplateDecl>(Template) || + + if (isa<ClassTemplateDecl>(Template) || isa<TemplateTemplateParmDecl>(Template)) return TNK_Type_template; - - assert((isa<FunctionTemplateDecl>(Template) || + + assert((isa<FunctionTemplateDecl>(Template) || isa<OverloadedFunctionDecl>(Template)) && "Unhandled template kind in Sema::isTemplateName"); return TNK_Function_template; @@ -246,7 +246,7 @@ bool Sema::DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl) { // C++ [temp.local]p4: // A template-parameter shall not be redeclared within its // scope (including nested scopes). - Diag(Loc, diag::err_template_param_shadow) + Diag(Loc, diag::err_template_param_shadow) << cast<NamedDecl>(PrevDecl)->getDeclName(); Diag(PrevDecl->getLocation(), diag::note_template_param_here); return true; @@ -269,24 +269,24 @@ TemplateDecl *Sema::AdjustDeclIfTemplate(DeclPtrTy &D) { /// (otherwise, "class" was used), and KeyLoc is the location of the /// "class" or "typename" keyword. ParamName is the name of the /// parameter (NULL indicates an unnamed template parameter) and -/// ParamName is the location of the parameter name (if any). +/// ParamName is the location of the parameter name (if any). /// If the type parameter has a default argument, it will be added /// later via ActOnTypeParameterDefault. -Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, +Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, SourceLocation EllipsisLoc, SourceLocation KeyLoc, IdentifierInfo *ParamName, SourceLocation ParamNameLoc, unsigned Depth, unsigned Position) { - assert(S->isTemplateParamScope() && - "Template type parameter not in template parameter scope!"); + assert(S->isTemplateParamScope() && + "Template type parameter not in template parameter scope!"); bool Invalid = false; if (ParamName) { NamedDecl *PrevDecl = LookupName(S, ParamName, LookupTagName); if (PrevDecl && PrevDecl->isTemplateParameter()) Invalid = Invalid || DiagnoseTemplateParameterShadow(ParamNameLoc, - PrevDecl); + PrevDecl); } SourceLocation Loc = ParamNameLoc; @@ -294,8 +294,8 @@ Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, Loc = KeyLoc; TemplateTypeParmDecl *Param - = TemplateTypeParmDecl::Create(Context, CurContext, Loc, - Depth, Position, ParamName, Typename, + = TemplateTypeParmDecl::Create(Context, CurContext, Loc, + Depth, Position, ParamName, Typename, Ellipsis); if (Invalid) Param->setInvalidDecl(); @@ -310,28 +310,28 @@ Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, } /// ActOnTypeParameterDefault - Adds a default argument (the type -/// Default) to the given template type parameter (TypeParam). -void Sema::ActOnTypeParameterDefault(DeclPtrTy TypeParam, +/// Default) to the given template type parameter (TypeParam). +void Sema::ActOnTypeParameterDefault(DeclPtrTy TypeParam, SourceLocation EqualLoc, - SourceLocation DefaultLoc, + SourceLocation DefaultLoc, TypeTy *DefaultT) { - TemplateTypeParmDecl *Parm + TemplateTypeParmDecl *Parm = cast<TemplateTypeParmDecl>(TypeParam.getAs<Decl>()); // FIXME: Preserve type source info. QualType Default = GetTypeFromParser(DefaultT); // C++0x [temp.param]p9: // A default template-argument may be specified for any kind of - // template-parameter that is not a template parameter pack. + // template-parameter that is not a template parameter pack. if (Parm->isParameterPack()) { Diag(DefaultLoc, diag::err_template_param_pack_default_arg); return; } - + // C++ [temp.param]p14: // A template-parameter shall not be used in its own default argument. // FIXME: Implement this check! Needs a recursive walk over the types. - + // Check the template argument itself. if (CheckTemplateArgument(Parm, Default, DefaultLoc)) { Parm->setInvalidDecl(); @@ -346,7 +346,7 @@ void Sema::ActOnTypeParameterDefault(DeclPtrTy TypeParam, /// /// \returns the (possibly-promoted) parameter type if valid; /// otherwise, produces a diagnostic and returns a NULL type. -QualType +QualType Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) { // C++ [temp.param]p4: // @@ -355,11 +355,11 @@ Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) { // // -- integral or enumeration type, if (T->isIntegralType() || T->isEnumeralType() || - // -- pointer to object or pointer to function, - (T->isPointerType() && + // -- pointer to object or pointer to function, + (T->isPointerType() && (T->getAs<PointerType>()->getPointeeType()->isObjectType() || T->getAs<PointerType>()->getPointeeType()->isFunctionType())) || - // -- reference to object or reference to function, + // -- reference to object or reference to function, T->isReferenceType() || // -- pointer to member. T->isMemberPointerType() || @@ -390,7 +390,7 @@ Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) { /// class Array") has been parsed. S is the current scope and D is /// the parsed declarator. Sema::DeclPtrTy Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, - unsigned Depth, + unsigned Depth, unsigned Position) { DeclaratorInfo *DInfo = 0; QualType T = GetTypeForDeclarator(D, S, &DInfo); @@ -432,14 +432,14 @@ Sema::DeclPtrTy Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, void Sema::ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParamD, SourceLocation EqualLoc, ExprArg DefaultE) { - NonTypeTemplateParmDecl *TemplateParm + NonTypeTemplateParmDecl *TemplateParm = cast<NonTypeTemplateParmDecl>(TemplateParamD.getAs<Decl>()); Expr *Default = static_cast<Expr *>(DefaultE.get()); - + // C++ [temp.param]p14: // A template-parameter shall not be used in its own default argument. // FIXME: Implement this check! Needs a recursive walk over the types. - + // Check the well-formedness of the default template argument. TemplateArgument Converted; if (CheckTemplateArgument(TemplateParm, TemplateParm->getType(), Default, @@ -461,8 +461,7 @@ Sema::DeclPtrTy Sema::ActOnTemplateTemplateParameter(Scope* S, IdentifierInfo *Name, SourceLocation NameLoc, unsigned Depth, - unsigned Position) -{ + unsigned Position) { assert(S->isTemplateParamScope() && "Template template parameter not in template parameter scope!"); @@ -496,12 +495,12 @@ Sema::DeclPtrTy Sema::ActOnTemplateTemplateParameter(Scope* S, void Sema::ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParamD, SourceLocation EqualLoc, ExprArg DefaultE) { - TemplateTemplateParmDecl *TemplateParm + TemplateTemplateParmDecl *TemplateParm = cast<TemplateTemplateParmDecl>(TemplateParamD.getAs<Decl>()); // Since a template-template parameter's default argument is an // id-expression, it must be a DeclRefExpr. - DeclRefExpr *Default + DeclRefExpr *Default = cast<DeclRefExpr>(static_cast<Expr *>(DefaultE.get())); // C++ [temp.param]p14: @@ -510,12 +509,12 @@ void Sema::ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParamD, // Check the well-formedness of the template argument. if (!isa<TemplateDecl>(Default->getDecl())) { - Diag(Default->getSourceRange().getBegin(), + Diag(Default->getSourceRange().getBegin(), diag::err_template_arg_must_be_template) << Default->getSourceRange(); TemplateParm->setInvalidDecl(); return; - } + } if (CheckTemplateArgument(TemplateParm, Default)) { TemplateParm->setInvalidDecl(); return; @@ -530,7 +529,7 @@ void Sema::ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParamD, Sema::TemplateParamsTy * Sema::ActOnTemplateParameterList(unsigned Depth, SourceLocation ExportLoc, - SourceLocation TemplateLoc, + SourceLocation TemplateLoc, SourceLocation LAngleLoc, DeclPtrTy *Params, unsigned NumParams, SourceLocation RAngleLoc) { @@ -548,7 +547,7 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, AttributeList *Attr, TemplateParameterList *TemplateParams, AccessSpecifier AS) { - assert(TemplateParams && TemplateParams->size() > 0 && + assert(TemplateParams && TemplateParams->size() > 0 && "No template parameters"); assert(TUK != TUK_Reference && "Can only declare or define class templates"); bool Invalid = false; @@ -580,14 +579,14 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, // FIXME: Produce a reasonable diagnostic here return true; } - - Previous = LookupQualifiedName(SemanticContext, Name, LookupOrdinaryName, + + Previous = LookupQualifiedName(SemanticContext, Name, LookupOrdinaryName, true); } else { SemanticContext = CurContext; Previous = LookupName(S, Name, LookupOrdinaryName, true); } - + assert(!Previous.isAmbiguous() && "Ambiguity in class template redecl?"); NamedDecl *PrevDecl = 0; if (Previous.begin() != Previous.end()) @@ -595,10 +594,10 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, if (PrevDecl && !isDeclInScope(PrevDecl, SemanticContext, S)) PrevDecl = 0; - + // If there is a previous declaration with the same name, check // whether this is a valid redeclaration. - ClassTemplateDecl *PrevClassTemplate + ClassTemplateDecl *PrevClassTemplate = dyn_cast_or_null<ClassTemplateDecl>(PrevDecl); if (PrevClassTemplate) { // Ensure that the template parameter lists are compatible. @@ -614,9 +613,9 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, // template declaration (7.1.5.3). RecordDecl *PrevRecordDecl = PrevClassTemplate->getTemplatedDecl(); if (!isAcceptableTagRedeclaration(PrevRecordDecl, Kind, KWLoc, *Name)) { - Diag(KWLoc, diag::err_use_with_wrong_tag) + Diag(KWLoc, diag::err_use_with_wrong_tag) << Name - << CodeModificationHint::CreateReplacement(KWLoc, + << CodeModificationHint::CreateReplacement(KWLoc, PrevRecordDecl->getKindName()); Diag(PrevRecordDecl->getLocation(), diag::note_previous_use); Kind = PrevRecordDecl->getTagKind(); @@ -654,13 +653,13 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, if (CheckTemplateParameterList(TemplateParams, PrevClassTemplate? PrevClassTemplate->getTemplateParameters() : 0)) Invalid = true; - + // FIXME: If we had a scope specifier, we better have a previous template // declaration! - CXXRecordDecl *NewClass = + CXXRecordDecl *NewClass = CXXRecordDecl::Create(Context, Kind, SemanticContext, NameLoc, Name, KWLoc, - PrevClassTemplate? + PrevClassTemplate? PrevClassTemplate->getTemplatedDecl() : 0, /*DelayTypeCreation=*/true); @@ -671,16 +670,16 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, NewClass->setDescribedClassTemplate(NewTemplate); // Build the type for the class template declaration now. - QualType T = - Context.getTypeDeclType(NewClass, - PrevClassTemplate? - PrevClassTemplate->getTemplatedDecl() : 0); + QualType T = + Context.getTypeDeclType(NewClass, + PrevClassTemplate? + PrevClassTemplate->getTemplatedDecl() : 0); assert(T->isDependentType() && "Class template type is not dependent?"); (void)T; // Set the access specifier. SetMemberAccessSpecifier(NewTemplate, PrevClassTemplate, AS); - + // Set the lexical context of these templates NewClass->setLexicalDeclContext(CurContext); NewTemplate->setLexicalDeclContext(CurContext); @@ -722,7 +721,7 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, TemplateParameterList *OldParams) { bool Invalid = false; - + // C++ [temp.param]p10: // The set of default template-arguments available for use with a // template declaration or definition is obtained by merging the @@ -755,7 +754,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, // If a template parameter of a class template is a template parameter pack, // it must be the last template parameter. if (SawParameterPack) { - Diag(ParameterPackLoc, + Diag(ParameterPackLoc, diag::err_template_param_pack_must_be_last_template_parameter); Invalid = true; } @@ -763,15 +762,15 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, // Merge default arguments for template type parameters. if (TemplateTypeParmDecl *NewTypeParm = dyn_cast<TemplateTypeParmDecl>(*NewParam)) { - TemplateTypeParmDecl *OldTypeParm + TemplateTypeParmDecl *OldTypeParm = OldParams? cast<TemplateTypeParmDecl>(*OldParam) : 0; - + if (NewTypeParm->isParameterPack()) { assert(!NewTypeParm->hasDefaultArgument() && "Parameter packs can't have a default argument!"); SawParameterPack = true; ParameterPackLoc = NewTypeParm->getLocation(); - } else if (OldTypeParm && OldTypeParm->hasDefaultArgument() && + } else if (OldTypeParm && OldTypeParm->hasDefaultArgument() && NewTypeParm->hasDefaultArgument()) { OldDefaultLoc = OldTypeParm->getDefaultArgumentLoc(); NewDefaultLoc = NewTypeParm->getDefaultArgumentLoc(); @@ -796,7 +795,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, // Merge default arguments for non-type template parameters NonTypeTemplateParmDecl *OldNonTypeParm = OldParams? cast<NonTypeTemplateParmDecl>(*OldParam) : 0; - if (OldNonTypeParm && OldNonTypeParm->hasDefaultArgument() && + if (OldNonTypeParm && OldNonTypeParm->hasDefaultArgument() && NewNonTypeParm->hasDefaultArgument()) { OldDefaultLoc = OldNonTypeParm->getDefaultArgumentLoc(); NewDefaultLoc = NewNonTypeParm->getDefaultArgumentLoc(); @@ -817,14 +816,14 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, SawDefaultArgument = true; PreviousDefaultArgLoc = NewNonTypeParm->getDefaultArgumentLoc(); } else if (SawDefaultArgument) - MissingDefaultArg = true; + MissingDefaultArg = true; } else { // Merge default arguments for template template parameters TemplateTemplateParmDecl *NewTemplateParm = cast<TemplateTemplateParmDecl>(*NewParam); TemplateTemplateParmDecl *OldTemplateParm = OldParams? cast<TemplateTemplateParmDecl>(*OldParam) : 0; - if (OldTemplateParm && OldTemplateParm->hasDefaultArgument() && + if (OldTemplateParm && OldTemplateParm->hasDefaultArgument() && NewTemplateParm->hasDefaultArgument()) { OldDefaultLoc = OldTemplateParm->getDefaultArgumentLoc(); NewDefaultLoc = NewTemplateParm->getDefaultArgumentLoc(); @@ -844,7 +843,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, SawDefaultArgument = true; PreviousDefaultArgLoc = NewTemplateParm->getDefaultArgumentLoc(); } else if (SawDefaultArgument) - MissingDefaultArg = true; + MissingDefaultArg = true; } if (RedundantDefaultArg) { @@ -859,7 +858,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, // If a template-parameter has a default template-argument, // all subsequent template-parameters shall have a default // template-argument supplied. - Diag((*NewParam)->getLocation(), + Diag((*NewParam)->getLocation(), diag::err_template_param_default_arg_missing); Diag(PreviousDefaultArgLoc, diag::note_template_param_prev_default_arg); Invalid = true; @@ -874,13 +873,13 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, return Invalid; } -/// \brief Match the given template parameter lists to the given scope +/// \brief Match the given template parameter lists to the given scope /// specifier, returning the template parameter list that applies to the /// name. /// /// \param DeclStartLoc the start of the declaration that has a scope /// specifier or a template parameter list. -/// +/// /// \param SS the scope specifier that will be matched to the given template /// parameter lists. This scope specifier precedes a qualified name that is /// being declared. @@ -890,10 +889,10 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, /// /// \param NumParamLists the number of template parameter lists in ParamLists. /// -/// \returns the template parameter list, if any, that corresponds to the +/// \returns the template parameter list, if any, that corresponds to the /// name that is preceded by the scope specifier @p SS. This template /// parameter list may be have template parameters (if we're declaring a -/// template) or may have no template parameters (if we're declaring a +/// template) or may have no template parameters (if we're declaring a /// template specialization), or may be NULL (if we were's declaring isn't /// itself a template). TemplateParameterList * @@ -907,35 +906,35 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, TemplateIdsInSpecifier; for (NestedNameSpecifier *NNS = (NestedNameSpecifier *)SS.getScopeRep(); NNS; NNS = NNS->getPrefix()) { - if (const TemplateSpecializationType *SpecType + if (const TemplateSpecializationType *SpecType = dyn_cast_or_null<TemplateSpecializationType>(NNS->getAsType())) { TemplateDecl *Template = SpecType->getTemplateName().getAsTemplateDecl(); if (!Template) continue; // FIXME: should this be an error? probably... - + if (const RecordType *Record = SpecType->getAs<RecordType>()) { ClassTemplateSpecializationDecl *SpecDecl = cast<ClassTemplateSpecializationDecl>(Record->getDecl()); // If the nested name specifier refers to an explicit specialization, // we don't need a template<> header. - // FIXME: revisit this approach once we cope with specialization + // FIXME: revisit this approach once we cope with specialization // properly. if (SpecDecl->getSpecializationKind() == TSK_ExplicitSpecialization) continue; } - + TemplateIdsInSpecifier.push_back(SpecType); } } - + // Reverse the list of template-ids in the scope specifier, so that we can // more easily match up the template-ids and the template parameter lists. std::reverse(TemplateIdsInSpecifier.begin(), TemplateIdsInSpecifier.end()); - + SourceLocation FirstTemplateLoc = DeclStartLoc; if (NumParamLists) FirstTemplateLoc = ParamLists[0]->getTemplateLoc(); - + // Match the template-ids found in the specifier to the template parameter // lists. unsigned Idx = 0; @@ -947,8 +946,8 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, // We have a template-id without a corresponding template parameter // list. if (DependentTemplateId) { - // FIXME: the location information here isn't great. - Diag(SS.getRange().getBegin(), + // FIXME: the location information here isn't great. + Diag(SS.getRange().getBegin(), diag::err_template_spec_needs_template_parameters) << TemplateId << SS.getRange(); @@ -960,13 +959,13 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, } return 0; } - + // Check the template parameter list against its corresponding template-id. if (DependentTemplateId) { - TemplateDecl *Template + TemplateDecl *Template = TemplateIdsInSpecifier[Idx]->getTemplateName().getAsTemplateDecl(); - if (ClassTemplateDecl *ClassTemplate + if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(Template)) { TemplateParameterList *ExpectedTemplateParams = 0; // Is this template-id naming the primary template? @@ -979,34 +978,34 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, ExpectedTemplateParams = PartialSpec->getTemplateParameters(); if (ExpectedTemplateParams) - TemplateParameterListsAreEqual(ParamLists[Idx], + TemplateParameterListsAreEqual(ParamLists[Idx], ExpectedTemplateParams, true); - } + } } else if (ParamLists[Idx]->size() > 0) - Diag(ParamLists[Idx]->getTemplateLoc(), + Diag(ParamLists[Idx]->getTemplateLoc(), diag::err_template_param_list_matches_nontemplate) << TemplateId << ParamLists[Idx]->getSourceRange(); } - + // If there were at least as many template-ids as there were template // parameter lists, then there are no template parameter lists remaining for // the declaration itself. if (Idx >= NumParamLists) return 0; - + // If there were too many template parameter lists, complain about that now. if (Idx != NumParamLists - 1) { while (Idx < NumParamLists - 1) { - Diag(ParamLists[Idx]->getTemplateLoc(), + Diag(ParamLists[Idx]->getTemplateLoc(), diag::err_template_spec_extra_headers) << SourceRange(ParamLists[Idx]->getTemplateLoc(), ParamLists[Idx]->getRAngleLoc()); ++Idx; } } - + // Return the last template parameter list, which corresponds to the // entity being declared. return ParamLists[NumParamLists - 1]; @@ -1014,8 +1013,8 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, /// \brief Translates template arguments as provided by the parser /// into template arguments used by semantic analysis. -static void -translateTemplateArguments(ASTTemplateArgsPtr &TemplateArgsIn, +static void +translateTemplateArguments(ASTTemplateArgsPtr &TemplateArgsIn, SourceLocation *TemplateArgLocs, llvm::SmallVector<TemplateArgument, 16> &TemplateArgs) { TemplateArgs.reserve(TemplateArgsIn.size()); @@ -1049,12 +1048,12 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, // template. TemplateArgumentListBuilder Converted(Template->getTemplateParameters(), NumTemplateArgs); - if (CheckTemplateArgumentList(Template, TemplateLoc, LAngleLoc, + if (CheckTemplateArgumentList(Template, TemplateLoc, LAngleLoc, TemplateArgs, NumTemplateArgs, RAngleLoc, false, Converted)) return QualType(); - assert((Converted.structuredSize() == + assert((Converted.structuredSize() == Template->getTemplateParameters()->size()) && "Converted template argument list is too short!"); @@ -1071,21 +1070,21 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, // // template<typename T, typename U = T> struct A; TemplateName CanonName = Context.getCanonicalTemplateName(Name); - CanonType = Context.getTemplateSpecializationType(CanonName, + CanonType = Context.getTemplateSpecializationType(CanonName, Converted.getFlatArguments(), Converted.flatSize()); - + // FIXME: CanonType is not actually the canonical type, and unfortunately // it is a TemplateTypeSpecializationType that we will never use again. // In the future, we need to teach getTemplateSpecializationType to only // build the canonical type and return that to us. CanonType = Context.getCanonicalType(CanonType); - } else if (ClassTemplateDecl *ClassTemplate + } else if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(Template)) { // Find the class template specialization declaration that // corresponds to these arguments. llvm::FoldingSetNodeID ID; - ClassTemplateSpecializationDecl::Profile(ID, + ClassTemplateSpecializationDecl::Profile(ID, Converted.getFlatArguments(), Converted.flatSize(), Context); @@ -1096,7 +1095,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, // This is the first time we have referenced this class template // specialization. Create the canonical declaration and add it to // the set of specializations. - Decl = ClassTemplateSpecializationDecl::Create(Context, + Decl = ClassTemplateSpecializationDecl::Create(Context, ClassTemplate->getDeclContext(), TemplateLoc, ClassTemplate, @@ -1107,7 +1106,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, CanonType = Context.getTypeDeclType(Decl); } - + // Build the fully-sugared type for this class template // specialization, which refers back to the class template // specialization we created or found. @@ -1118,7 +1117,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, Action::TypeResult Sema::ActOnTemplateIdType(TemplateTy TemplateD, SourceLocation TemplateLoc, - SourceLocation LAngleLoc, + SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgsIn, SourceLocation *TemplateArgLocs, SourceLocation RAngleLoc) { @@ -1151,7 +1150,7 @@ Sema::TypeResult Sema::ActOnTagTemplateIdType(TypeResult TypeResult, // Verify the tag specifier. TagDecl::TagKind TagKind = TagDecl::getTagKindForTypeSpec(TagSpec); - + if (const RecordType *RT = Type->getAs<RecordType>()) { RecordDecl *D = RT->getDecl(); @@ -1179,14 +1178,14 @@ Sema::OwningExprResult Sema::BuildTemplateIdExpr(TemplateName Template, SourceLocation RAngleLoc) { // FIXME: Can we do any checking at this point? I guess we could check the // template arguments that we have against the template name, if the template - // name refers to a single template. That's not a terribly common case, + // name refers to a single template. That's not a terribly common case, // though. - return Owned(TemplateIdRefExpr::Create(Context, + return Owned(TemplateIdRefExpr::Create(Context, /*FIXME: New type?*/Context.OverloadTy, /*FIXME: Necessary?*/0, /*FIXME: Necessary?*/SourceRange(), Template, TemplateNameLoc, LAngleLoc, - TemplateArgs, + TemplateArgs, NumTemplateArgs, RAngleLoc)); } @@ -1197,12 +1196,12 @@ Sema::OwningExprResult Sema::ActOnTemplateIdExpr(TemplateTy TemplateD, SourceLocation *TemplateArgLocs, SourceLocation RAngleLoc) { TemplateName Template = TemplateD.getAsVal<TemplateName>(); - + // Translate the parser's template argument list in our AST format. llvm::SmallVector<TemplateArgument, 16> TemplateArgs; translateTemplateArguments(TemplateArgsIn, TemplateArgLocs, TemplateArgs); TemplateArgsIn.release(); - + return BuildTemplateIdExpr(Template, TemplateNameLoc, LAngleLoc, TemplateArgs.data(), TemplateArgs.size(), RAngleLoc); @@ -1220,7 +1219,7 @@ Sema::ActOnMemberTemplateIdReferenceExpr(Scope *S, ExprArg Base, SourceLocation *TemplateArgLocs, SourceLocation RAngleLoc) { TemplateName Template = TemplateD.getAsVal<TemplateName>(); - + // FIXME: We're going to end up looking up the template based on its name, // twice! DeclarationName Name; @@ -1230,17 +1229,17 @@ Sema::ActOnMemberTemplateIdReferenceExpr(Scope *S, ExprArg Base, Name = Ovl->getDeclName(); else Name = Template.getAsDependentTemplateName()->getName(); - + // Translate the parser's template argument list in our AST format. llvm::SmallVector<TemplateArgument, 16> TemplateArgs; translateTemplateArguments(TemplateArgsIn, TemplateArgLocs, TemplateArgs); TemplateArgsIn.release(); - + // Do we have the save the actual template name? We might need it... return BuildMemberReferenceExpr(S, move(Base), OpLoc, OpKind, TemplateNameLoc, Name, true, LAngleLoc, TemplateArgs.data(), TemplateArgs.size(), - RAngleLoc, DeclPtrTy(), &SS); + RAngleLoc, DeclPtrTy(), &SS); } /// \brief Form a dependent template name. @@ -1250,13 +1249,13 @@ Sema::ActOnMemberTemplateIdReferenceExpr(Scope *S, ExprArg Base, /// example, given "MetaFun::template apply", the scope specifier \p /// SS will be "MetaFun::", \p TemplateKWLoc contains the location /// of the "template" keyword, and "apply" is the \p Name. -Sema::TemplateTy +Sema::TemplateTy Sema::ActOnDependentTemplateName(SourceLocation TemplateKWLoc, const IdentifierInfo &Name, SourceLocation NameLoc, const CXXScopeSpec &SS, TypeTy *ObjectType) { - if ((ObjectType && + if ((ObjectType && computeDeclContext(QualType::getFromOpaquePtr(ObjectType))) || (SS.isSet() && computeDeclContext(SS, false))) { // C++0x [temp.names]p5: @@ -1276,7 +1275,7 @@ Sema::ActOnDependentTemplateName(SourceLocation TemplateKWLoc, // "template" keyword is now permitted). We follow the C++0x // rules, even in C++03 mode, retroactively applying the DR. TemplateTy Template; - TemplateNameKind TNK = isTemplateName(0, Name, NameLoc, &SS, ObjectType, + TemplateNameKind TNK = isTemplateName(0, Name, NameLoc, &SS, ObjectType, false, Template); if (TNK == TNK_Non_template) { Diag(NameLoc, diag::err_template_kw_refers_to_non_template) @@ -1287,12 +1286,12 @@ Sema::ActOnDependentTemplateName(SourceLocation TemplateKWLoc, return Template; } - NestedNameSpecifier *Qualifier + NestedNameSpecifier *Qualifier = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); return TemplateTy::make(Context.getDependentTemplateName(Qualifier, &Name)); } -bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, +bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, const TemplateArgument &Arg, TemplateArgumentListBuilder &Converted) { // Check template type parameter. @@ -1305,13 +1304,13 @@ bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, // is not a type. Diag(Arg.getLocation(), diag::err_template_arg_must_be_type); Diag(Param->getLocation(), diag::note_template_param_here); - + return true; - } + } if (CheckTemplateArgument(Param, Arg.getAsType(), Arg.getLocation())) return true; - + // Add the converted template type argument. Converted.Append( TemplateArgument(Arg.getLocation(), @@ -1334,9 +1333,9 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, unsigned NumArgs = NumTemplateArgs; bool Invalid = false; - bool HasParameterPack = + bool HasParameterPack = NumParams > 0 && Params->getParam(NumParams - 1)->isTemplateParameterPack(); - + if ((NumArgs > NumParams && !HasParameterPack) || (NumArgs < Params->getMinRequiredArguments() && !PartialTemplateArgs)) { @@ -1356,8 +1355,8 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, << Params->getSourceRange(); Invalid = true; } - - // C++ [temp.arg]p1: + + // C++ [temp.arg]p1: // [...] The type and form of each template-argument specified in // a template-id shall match the type and form specified for the // corresponding parameter declared by the template in its @@ -1368,7 +1367,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, Param != ParamEnd; ++Param, ++ArgIdx) { if (ArgIdx > NumArgs && PartialTemplateArgs) break; - + // Decode the template argument TemplateArgument Arg; if (ArgIdx >= NumArgs) { @@ -1381,7 +1380,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, Converted.EndPack(); break; } - + if (!TTP->hasDefaultArgument()) break; @@ -1390,14 +1389,14 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, // If the argument type is dependent, instantiate it now based // on the previously-computed template arguments. if (ArgType->isDependentType()) { - InstantiatingTemplate Inst(*this, TemplateLoc, + InstantiatingTemplate Inst(*this, TemplateLoc, Template, Converted.getFlatArguments(), Converted.flatSize(), SourceRange(TemplateLoc, RAngleLoc)); TemplateArgumentList TemplateArgs(Context, Converted, /*TakeArgs=*/false); - ArgType = SubstType(ArgType, + ArgType = SubstType(ArgType, MultiLevelTemplateArgumentList(TemplateArgs), TTP->getDefaultArgumentLoc(), TTP->getDeclName()); @@ -1407,29 +1406,29 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, return true; Arg = TemplateArgument(TTP->getLocation(), ArgType); - } else if (NonTypeTemplateParmDecl *NTTP + } else if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*Param)) { if (!NTTP->hasDefaultArgument()) break; - InstantiatingTemplate Inst(*this, TemplateLoc, + InstantiatingTemplate Inst(*this, TemplateLoc, Template, Converted.getFlatArguments(), Converted.flatSize(), SourceRange(TemplateLoc, RAngleLoc)); - + TemplateArgumentList TemplateArgs(Context, Converted, /*TakeArgs=*/false); - Sema::OwningExprResult E - = SubstExpr(NTTP->getDefaultArgument(), + Sema::OwningExprResult E + = SubstExpr(NTTP->getDefaultArgument(), MultiLevelTemplateArgumentList(TemplateArgs)); if (E.isInvalid()) return true; - + Arg = TemplateArgument(E.takeAs<Expr>()); } else { - TemplateTemplateParmDecl *TempParm - = cast<TemplateTemplateParmDecl>(*Param); + TemplateTemplateParmDecl *TempParm + = cast<TemplateTemplateParmDecl>(*Param); if (!TempParm->hasDefaultArgument()) break; @@ -1451,13 +1450,13 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, if (CheckTemplateTypeArgument(TTP, TemplateArgs[ArgIdx], Converted)) Invalid = true; } - + Converted.EndPack(); } else { if (CheckTemplateTypeArgument(TTP, Arg, Converted)) Invalid = true; } - } else if (NonTypeTemplateParmDecl *NTTP + } else if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*Param)) { // Check non-type template parameters. @@ -1466,21 +1465,21 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, QualType NTTPType = NTTP->getType(); if (NTTPType->isDependentType()) { // Do substitution on the type of the non-type template parameter. - InstantiatingTemplate Inst(*this, TemplateLoc, + InstantiatingTemplate Inst(*this, TemplateLoc, Template, Converted.getFlatArguments(), Converted.flatSize(), SourceRange(TemplateLoc, RAngleLoc)); TemplateArgumentList TemplateArgs(Context, Converted, /*TakeArgs=*/false); - NTTPType = SubstType(NTTPType, + NTTPType = SubstType(NTTPType, MultiLevelTemplateArgumentList(TemplateArgs), NTTP->getLocation(), NTTP->getDeclName()); // If that worked, check the non-type template parameter type // for validity. if (!NTTPType.isNull()) - NTTPType = CheckNonTypeTemplateParameterType(NTTPType, + NTTPType = CheckNonTypeTemplateParameterType(NTTPType, NTTP->getLocation()); if (NTTPType.isNull()) { Invalid = true; @@ -1492,7 +1491,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, case TemplateArgument::Null: assert(false && "Should never see a NULL template argument here"); break; - + case TemplateArgument::Expression: { Expr *E = Arg.getAsExpr(); TemplateArgument Result; @@ -1513,7 +1512,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, case TemplateArgument::Type: // We have a non-type template parameter but the template // argument is a type. - + // C++ [temp.arg]p2: // In a template-argument, an ambiguity between a type-id and // an expression is resolved to a type-id, regardless of the @@ -1529,37 +1528,37 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, Diag((*Param)->getLocation(), diag::note_template_param_here); Invalid = true; break; - + case TemplateArgument::Pack: assert(0 && "FIXME: Implement!"); break; } - } else { + } else { // Check template template parameters. - TemplateTemplateParmDecl *TempParm + TemplateTemplateParmDecl *TempParm = cast<TemplateTemplateParmDecl>(*Param); - + switch (Arg.getKind()) { case TemplateArgument::Null: assert(false && "Should never see a NULL template argument here"); break; - + case TemplateArgument::Expression: { Expr *ArgExpr = Arg.getAsExpr(); if (ArgExpr && isa<DeclRefExpr>(ArgExpr) && isa<TemplateDecl>(cast<DeclRefExpr>(ArgExpr)->getDecl())) { if (CheckTemplateArgument(TempParm, cast<DeclRefExpr>(ArgExpr))) Invalid = true; - + // Add the converted template argument. - Decl *D + Decl *D = cast<DeclRefExpr>(ArgExpr)->getDecl()->getCanonicalDecl(); Converted.Append(TemplateArgument(Arg.getLocation(), D)); continue; } } // fall through - + case TemplateArgument::Type: { // We have a template template parameter but the template // argument does not refer to a template. @@ -1573,11 +1572,11 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, // it to the list of converted arguments. Converted.Append(Arg); break; - + case TemplateArgument::Integral: assert(false && "Integral argument with template template parameter"); break; - + case TemplateArgument::Pack: assert(0 && "FIXME: Implement!"); break; @@ -1593,7 +1592,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, /// /// This routine implements the semantics of C++ [temp.arg.type]. It /// returns true if an error occurred, and false otherwise. -bool Sema::CheckTemplateArgument(TemplateTypeParmDecl *Param, +bool Sema::CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg, SourceLocation ArgLoc) { // C++ [temp.arg.type]p2: // A local type, a type with no linkage, an unnamed type or a type @@ -1609,7 +1608,7 @@ bool Sema::CheckTemplateArgument(TemplateTypeParmDecl *Param, if (Tag && Tag->getDecl()->getDeclContext()->isFunctionOrMethod()) return Diag(ArgLoc, diag::err_template_arg_local_type) << QualType(Tag, 0); - else if (Tag && !Tag->getDecl()->getDeclName() && + else if (Tag && !Tag->getDecl()->getDeclName() && !Tag->getDecl()->getTypedefForAnonDecl()) { Diag(ArgLoc, diag::err_template_arg_unnamed_type); Diag(Tag->getDecl()->getLocation(), diag::note_template_unnamed_type_here); @@ -1634,7 +1633,7 @@ bool Sema::CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, return false; // C++ [temp.arg.nontype]p1: - // + // // A template-argument for a non-type, non-template // template-parameter shall be one of: [...] // @@ -1645,11 +1644,11 @@ bool Sema::CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, // the name refers to a function or array, or if the // corresponding template-parameter is a reference; or DeclRefExpr *DRE = 0; - + // Ignore (and complain about) any excess parentheses. while (ParenExpr *Parens = dyn_cast<ParenExpr>(Arg)) { if (!Invalid) { - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_extra_parens) << Arg->getSourceRange(); Invalid = true; @@ -1665,7 +1664,7 @@ bool Sema::CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, DRE = dyn_cast<DeclRefExpr>(Arg); if (!DRE || !isa<ValueDecl>(DRE->getDecl())) - return Diag(Arg->getSourceRange().getBegin(), + return Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_not_object_or_func_form) << Arg->getSourceRange(); @@ -1677,14 +1676,14 @@ bool Sema::CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, // Cannot refer to non-static member functions if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(DRE->getDecl())) if (!Method->isStatic()) - return Diag(Arg->getSourceRange().getBegin(), + return Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_method) << Method << Arg->getSourceRange(); - + // Functions must have external linkage. if (FunctionDecl *Func = dyn_cast<FunctionDecl>(DRE->getDecl())) { if (Func->getStorageClass() == FunctionDecl::Static) { - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_function_not_extern) << Func << Arg->getSourceRange(); Diag(Func->getLocation(), diag::note_template_arg_internal_object) @@ -1699,7 +1698,7 @@ bool Sema::CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, if (VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl())) { if (!Var->hasGlobalStorage()) { - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_object_not_extern) << Var << Arg->getSourceRange(); Diag(Var->getLocation(), diag::note_template_arg_internal_object) @@ -1711,19 +1710,19 @@ bool Sema::CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, Entity = Var; return Invalid; } - + // We found something else, but we don't know specifically what it is. - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_not_object_or_func) << Arg->getSourceRange(); - Diag(DRE->getDecl()->getLocation(), + Diag(DRE->getDecl()->getLocation(), diag::note_template_arg_refers_here); return true; } /// \brief Checks whether the given template argument is a pointer to /// member constant according to C++ [temp.arg.nontype]p1. -bool +bool Sema::CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member) { bool Invalid = false; @@ -1736,7 +1735,7 @@ Sema::CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member) { return false; // C++ [temp.arg.nontype]p1: - // + // // A template-argument for a non-type, non-template // template-parameter shall be one of: [...] // @@ -1746,7 +1745,7 @@ Sema::CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member) { // Ignore (and complain about) any excess parentheses. while (ParenExpr *Parens = dyn_cast<ParenExpr>(Arg)) { if (!Invalid) { - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_extra_parens) << Arg->getSourceRange(); Invalid = true; @@ -1776,10 +1775,10 @@ Sema::CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member) { } // We found something else, but we don't know specifically what it is. - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_not_pointer_to_member_form) << Arg->getSourceRange(); - Diag(DRE->getDecl()->getLocation(), + Diag(DRE->getDecl()->getLocation(), diag::note_template_arg_refers_here); return true; } @@ -1794,7 +1793,7 @@ Sema::CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member) { /// /// If no error was detected, Converted receives the converted template argument. bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, - QualType InstantiatedParamType, Expr *&Arg, + QualType InstantiatedParamType, Expr *&Arg, TemplateArgument &Converted) { SourceLocation StartLoc = Arg->getSourceRange().getBegin(); @@ -1830,7 +1829,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, SourceLocation NonConstantLoc; llvm::APSInt Value; if (!ArgType->isIntegralType() && !ArgType->isEnumeralType()) { - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_not_integral_or_enumeral) << ArgType << Arg->getSourceRange(); Diag(Param->getLocation(), diag::note_template_param_here); @@ -1859,7 +1858,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, ImpCastExprToType(Arg, ParamType); } else { // We can't perform this conversion. - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_not_convertible) << Arg->getType() << InstantiatedParamType << Arg->getSourceRange(); Diag(Param->getLocation(), diag::note_template_param_here); @@ -1885,7 +1884,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, // Check that we don't overflow the template parameter type. unsigned AllowedBits = Context.getTypeSize(IntegerType); if (Value.getActiveBits() > AllowedBits) { - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_too_large) << Value.toString(10) << Param->getType() << Arg->getSourceRange(); @@ -1909,7 +1908,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, } Converted = TemplateArgument(StartLoc, Value, - ParamType->isEnumeralType() ? ParamType + ParamType->isEnumeralType() ? ParamType : IntegerType); return false; } @@ -1939,7 +1938,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, (ParamType->isMemberPointerType() && ParamType->getAs<MemberPointerType>()->getPointeeType() ->isFunctionType())) { - if (Context.hasSameUnqualifiedType(ArgType, + if (Context.hasSameUnqualifiedType(ArgType, ParamType.getNonReferenceType())) { // We don't have to do anything: the types already match. } else if (ArgType->isNullPtrType() && (ParamType->isPointerType() || @@ -1949,7 +1948,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, } else if (ArgType->isFunctionType() && ParamType->isPointerType()) { ArgType = Context.getPointerType(ArgType); ImpCastExprToType(Arg, ArgType); - } else if (FunctionDecl *Fn + } else if (FunctionDecl *Fn = ResolveAddressOfOverloadedFunction(Arg, ParamType, true)) { if (DiagnoseUseOfDecl(Fn, Arg->getSourceRange().getBegin())) return true; @@ -1962,16 +1961,16 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, } } - if (!Context.hasSameUnqualifiedType(ArgType, + if (!Context.hasSameUnqualifiedType(ArgType, ParamType.getNonReferenceType())) { // We can't perform this conversion. - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_not_convertible) << Arg->getType() << InstantiatedParamType << Arg->getSourceRange(); Diag(Param->getLocation(), diag::note_template_param_here); return true; } - + if (ParamType->isMemberPointerType()) { NamedDecl *Member = 0; if (CheckTemplateArgumentPointerToMember(Arg, Member)) @@ -1982,7 +1981,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, Converted = TemplateArgument(StartLoc, Member); return false; } - + NamedDecl *Entity = 0; if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) return true; @@ -2013,16 +2012,16 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, ArgType = ParamType; ImpCastExprToType(Arg, ParamType); } - + if (!Context.hasSameUnqualifiedType(ArgType, ParamType)) { // We can't perform this conversion. - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_not_convertible) << Arg->getType() << InstantiatedParamType << Arg->getSourceRange(); Diag(Param->getLocation(), diag::note_template_param_here); return true; } - + NamedDecl *Entity = 0; if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) return true; @@ -2032,7 +2031,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, Converted = TemplateArgument(StartLoc, Entity); return false; } - + if (const ReferenceType *ParamRefType = ParamType->getAs<ReferenceType>()) { // -- For a non-type template-parameter of type reference to // object, no conversions apply. The type referred to by the @@ -2044,7 +2043,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, "Only object references allowed here"); if (!Context.hasSameUnqualifiedType(ParamRefType->getPointeeType(), ArgType)) { - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_no_ref_bind) << InstantiatedParamType << Arg->getType() << Arg->getSourceRange(); @@ -2052,10 +2051,10 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, return true; } - unsigned ParamQuals + unsigned ParamQuals = Context.getCanonicalType(ParamType).getCVRQualifiers(); unsigned ArgQuals = Context.getCanonicalType(ArgType).getCVRQualifiers(); - + if ((ParamQuals | ArgQuals) != ParamQuals) { Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_ref_bind_ignores_quals) @@ -2064,7 +2063,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, Diag(Param->getLocation(), diag::note_template_param_here); return true; } - + NamedDecl *Entity = 0; if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) return true; @@ -2087,17 +2086,17 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, ImpCastExprToType(Arg, ParamType); } else { // We can't perform this conversion. - Diag(Arg->getSourceRange().getBegin(), + Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_not_convertible) << Arg->getType() << InstantiatedParamType << Arg->getSourceRange(); Diag(Param->getLocation(), diag::note_template_param_here); - return true; + return true; } NamedDecl *Member = 0; if (CheckTemplateArgumentPointerToMember(Arg, Member)) return true; - + if (Member) Member = cast<NamedDecl>(Member->getCanonicalDecl()); Converted = TemplateArgument(StartLoc, Member); @@ -2125,9 +2124,9 @@ bool Sema::CheckTemplateArgument(TemplateTemplateParmDecl *Param, // Note that we also allow template template parameters here, which // will happen when we are dealing with, e.g., class template // partial specializations. - if (!isa<ClassTemplateDecl>(Template) && + if (!isa<ClassTemplateDecl>(Template) && !isa<TemplateTemplateParmDecl>(Template)) { - assert(isa<FunctionTemplateDecl>(Template) && + assert(isa<FunctionTemplateDecl>(Template) && "Only function templates are possible here"); Diag(Arg->getLocStart(), diag::err_template_arg_not_class_template); Diag(Template->getLocation(), diag::note_template_arg_refers_here_func) @@ -2143,7 +2142,7 @@ bool Sema::CheckTemplateArgument(TemplateTemplateParmDecl *Param, /// \brief Determine whether the given template parameter lists are /// equivalent. /// -/// \param New The new template parameter list, typically written in the +/// \param New The new template parameter list, typically written in the /// source code as part of a new template declaration. /// /// \param Old The old template parameter list, typically found via @@ -2165,7 +2164,7 @@ bool Sema::CheckTemplateArgument(TemplateTemplateParmDecl *Param, /// /// \returns True if the template parameter lists are equal, false /// otherwise. -bool +bool Sema::TemplateParameterListsAreEqual(TemplateParameterList *New, TemplateParameterList *Old, bool Complain, @@ -2177,7 +2176,7 @@ Sema::TemplateParameterListsAreEqual(TemplateParameterList *New, if (TemplateArgLoc.isValid()) { Diag(TemplateArgLoc, diag::err_template_arg_template_params_mismatch); NextDiag = diag::note_template_param_list_different_arity; - } + } Diag(New->getTemplateLoc(), NextDiag) << (New->size() > Old->size()) << IsTemplateTemplateParm @@ -2218,15 +2217,15 @@ Sema::TemplateParameterListsAreEqual(TemplateParameterList *New, // types within the template parameter list of the template template // parameter can be checked, and (2) the template type parameter depths // will match up. - QualType OldParmType + QualType OldParmType = Context.getTypeDeclType(cast<TemplateTypeParmDecl>(*OldParm)); - QualType NewParmType + QualType NewParmType = Context.getTypeDeclType(cast<TemplateTypeParmDecl>(*NewParm)); - assert(Context.getCanonicalType(OldParmType) == - Context.getCanonicalType(NewParmType) && + assert(Context.getCanonicalType(OldParmType) == + Context.getCanonicalType(NewParmType) && "type parameter mismatch?"); #endif - } else if (NonTypeTemplateParmDecl *OldNTTP + } else if (NonTypeTemplateParmDecl *OldNTTP = dyn_cast<NonTypeTemplateParmDecl>(*OldParm)) { // The types of non-type template parameters must agree. NonTypeTemplateParmDecl *NewNTTP @@ -2236,14 +2235,14 @@ Sema::TemplateParameterListsAreEqual(TemplateParameterList *New, if (Complain) { unsigned NextDiag = diag::err_template_nontype_parm_different_type; if (TemplateArgLoc.isValid()) { - Diag(TemplateArgLoc, + Diag(TemplateArgLoc, diag::err_template_arg_template_params_mismatch); NextDiag = diag::note_template_nontype_parm_different_type; } Diag(NewNTTP->getLocation(), NextDiag) << NewNTTP->getType() << IsTemplateTemplateParm; - Diag(OldNTTP->getLocation(), + Diag(OldNTTP->getLocation(), diag::note_template_nontype_parm_prev_declaration) << OldNTTP->getType(); } @@ -2253,9 +2252,9 @@ Sema::TemplateParameterListsAreEqual(TemplateParameterList *New, // The template parameter lists of template template // parameters must agree. // FIXME: Could we perform a faster "type" comparison here? - assert(isa<TemplateTemplateParmDecl>(*OldParm) && + assert(isa<TemplateTemplateParmDecl>(*OldParm) && "Only template template parameters handled here"); - TemplateTemplateParmDecl *OldTTP + TemplateTemplateParmDecl *OldTTP = cast<TemplateTemplateParmDecl>(*OldParm); TemplateTemplateParmDecl *NewTTP = cast<TemplateTemplateParmDecl>(*NewParm); @@ -2275,29 +2274,29 @@ Sema::TemplateParameterListsAreEqual(TemplateParameterList *New, /// /// If the template declaration is valid in this scope, returns /// false. Otherwise, issues a diagnostic and returns true. -bool +bool Sema::CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams) { // Find the nearest enclosing declaration scope. while ((S->getFlags() & Scope::DeclScope) == 0 || (S->getFlags() & Scope::TemplateParamScope) != 0) S = S->getParent(); - + // C++ [temp]p2: // A template-declaration can appear only as a namespace scope or // class scope declaration. DeclContext *Ctx = static_cast<DeclContext *>(S->getEntity()); if (Ctx && isa<LinkageSpecDecl>(Ctx) && cast<LinkageSpecDecl>(Ctx)->getLanguage() != LinkageSpecDecl::lang_cxx) - return Diag(TemplateParams->getTemplateLoc(), diag::err_template_linkage) + return Diag(TemplateParams->getTemplateLoc(), diag::err_template_linkage) << TemplateParams->getSourceRange(); - + while (Ctx && isa<LinkageSpecDecl>(Ctx)) Ctx = Ctx->getParent(); if (Ctx && (Ctx->isFileContext() || Ctx->isRecord())) return false; - return Diag(TemplateParams->getTemplateLoc(), + return Diag(TemplateParams->getTemplateLoc(), diag::err_template_outside_namespace_or_class_scope) << TemplateParams->getSourceRange(); } @@ -2306,11 +2305,11 @@ Sema::CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams) { /// instantiation in the current context is well-formed. /// /// This routine determines whether a class template specialization or -/// explicit instantiation can be declared in the current context -/// (C++ [temp.expl.spec]p2, C++0x [temp.explicit]p2) and emits -/// appropriate diagnostics if there was an error. It returns true if +/// explicit instantiation can be declared in the current context +/// (C++ [temp.expl.spec]p2, C++0x [temp.explicit]p2) and emits +/// appropriate diagnostics if there was an error. It returns true if // there was an error that we cannot recover from, and false otherwise. -bool +bool Sema::CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate, ClassTemplateSpecializationDecl *PrevDecl, SourceLocation TemplateNameLoc, @@ -2338,7 +2337,7 @@ Sema::CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate, } DeclContext *DC = CurContext->getEnclosingNamespaceContext(); - DeclContext *TemplateContext + DeclContext *TemplateContext = ClassTemplate->getDeclContext()->getEnclosingNamespaceContext(); if ((!PrevDecl || PrevDecl->getSpecializationKind() == TSK_Undeclared) && !ExplicitInstantiation) { @@ -2352,7 +2351,7 @@ Sema::CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate, << ClassTemplate << ScopeSpecifierRange; else if (isa<NamespaceDecl>(TemplateContext)) Diag(TemplateNameLoc, diag::err_template_spec_decl_out_of_scope) - << PartialSpecialization << ClassTemplate + << PartialSpecialization << ClassTemplate << cast<NamedDecl>(TemplateContext) << ScopeSpecifierRange; Diag(ClassTemplate->getLocation(), diag::note_template_decl_here); @@ -2379,10 +2378,10 @@ Sema::CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate, Diag(TemplateNameLoc, diag::err_template_spec_redecl_out_of_scope) << Kind << ClassTemplate << cast<NamedDecl>(TemplateContext) << ScopeSpecifierRange; - else + else SuppressedDiag = true; } - + if (!SuppressedDiag) Diag(ClassTemplate->getLocation(), diag::note_template_decl_here); } @@ -2413,16 +2412,16 @@ bool Sema::CheckClassTemplatePartialSpecializationArgs( // FIXME: the interface to this function will have to change to // accommodate variadic templates. MirrorsPrimaryTemplate = true; - + const TemplateArgument *ArgList = TemplateArgs.getFlatArguments(); - + for (unsigned I = 0, N = TemplateParams->size(); I != N; ++I) { // Determine whether the template argument list of the partial // specialization is identical to the implicit argument list of // the primary template. The caller may need to diagnostic this as // an error per C++ [temp.class.spec]p9b3. if (MirrorsPrimaryTemplate) { - if (TemplateTypeParmDecl *TTP + if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(TemplateParams->getParam(I))) { if (Context.getCanonicalType(Context.getTypeDeclType(TTP)) != Context.getCanonicalType(ArgList[I].getAsType())) @@ -2432,11 +2431,11 @@ bool Sema::CheckClassTemplatePartialSpecializationArgs( TemplateParams->getParam(I))) { // FIXME: We should settle on either Declaration storage or // Expression storage for template template parameters. - TemplateTemplateParmDecl *ArgDecl + TemplateTemplateParmDecl *ArgDecl = dyn_cast_or_null<TemplateTemplateParmDecl>( ArgList[I].getAsDecl()); if (!ArgDecl) - if (DeclRefExpr *DRE + if (DeclRefExpr *DRE = dyn_cast_or_null<DeclRefExpr>(ArgList[I].getAsExpr())) ArgDecl = dyn_cast<TemplateTemplateParmDecl>(DRE->getDecl()); @@ -2447,7 +2446,7 @@ bool Sema::CheckClassTemplatePartialSpecializationArgs( } } - NonTypeTemplateParmDecl *Param + NonTypeTemplateParmDecl *Param = dyn_cast<NonTypeTemplateParmDecl>(TemplateParams->getParam(I)); if (!Param) { continue; @@ -2468,9 +2467,9 @@ bool Sema::CheckClassTemplatePartialSpecializationArgs( // specialized non-type arguments, so skip any non-specialized // arguments. if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ArgExpr)) - if (NonTypeTemplateParmDecl *NTTP + if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl())) { - if (MirrorsPrimaryTemplate && + if (MirrorsPrimaryTemplate && (Param->getIndex() != NTTP->getIndex() || Param->getDepth() != NTTP->getDepth())) MirrorsPrimaryTemplate = false; @@ -2486,7 +2485,7 @@ bool Sema::CheckClassTemplatePartialSpecializationArgs( // specialization except when the argument expression is a // simple identifier. if (ArgExpr->isTypeDependent() || ArgExpr->isValueDependent()) { - Diag(ArgExpr->getLocStart(), + Diag(ArgExpr->getLocStart(), diag::err_dependent_non_type_arg_in_partial_spec) << ArgExpr->getSourceRange(); return true; @@ -2496,7 +2495,7 @@ bool Sema::CheckClassTemplatePartialSpecializationArgs( // specialized non-type argument shall not be dependent on a // parameter of the specialization. if (Param->getType()->isDependentType()) { - Diag(ArgExpr->getLocStart(), + Diag(ArgExpr->getLocStart(), diag::err_dependent_typed_non_type_arg_in_partial_spec) << Param->getType() << ArgExpr->getSourceRange(); @@ -2513,7 +2512,7 @@ bool Sema::CheckClassTemplatePartialSpecializationArgs( Sema::DeclResult Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, - SourceLocation KWLoc, + SourceLocation KWLoc, const CXXScopeSpec &SS, TemplateTy TemplateD, SourceLocation TemplateNameLoc, @@ -2527,7 +2526,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // Find the class template we're specializing TemplateName Name = TemplateD.getAsVal<TemplateName>(); - ClassTemplateDecl *ClassTemplate + ClassTemplateDecl *ClassTemplate = cast<ClassTemplateDecl>(Name.getAsTemplateDecl()); bool isPartialSpecialization = false; @@ -2535,8 +2534,8 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // Check the validity of the template headers that introduce this // template. TemplateParameterList *TemplateParams - = MatchTemplateParametersToScopeSpecifier(TemplateNameLoc, SS, - (TemplateParameterList**)TemplateParameterLists.get(), + = MatchTemplateParametersToScopeSpecifier(TemplateNameLoc, SS, + (TemplateParameterList**)TemplateParameterLists.get(), TemplateParameterLists.size()); if (TemplateParams && TemplateParams->size() > 0) { isPartialSpecialization = true; @@ -2548,14 +2547,14 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, Decl *Param = TemplateParams->getParam(I); if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) { if (TTP->hasDefaultArgument()) { - Diag(TTP->getDefaultArgumentLoc(), + Diag(TTP->getDefaultArgumentLoc(), diag::err_default_arg_in_partial_spec); TTP->setDefaultArgument(QualType(), SourceLocation(), false); } } else if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) { if (Expr *DefArg = NTTP->getDefaultArgument()) { - Diag(NTTP->getDefaultArgumentLoc(), + Diag(NTTP->getDefaultArgumentLoc(), diag::err_default_arg_in_partial_spec) << DefArg->getSourceRange(); NTTP->setDefaultArgument(0); @@ -2564,7 +2563,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, } else { TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(Param); if (Expr *DefArg = TTP->getDefaultArgument()) { - Diag(TTP->getDefaultArgumentLoc(), + Diag(TTP->getDefaultArgumentLoc(), diag::err_default_arg_in_partial_spec) << DefArg->getSourceRange(); TTP->setDefaultArgument(0); @@ -2586,13 +2585,13 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, case DeclSpec::TST_class: Kind = TagDecl::TK_class; break; } if (!isAcceptableTagRedeclaration(ClassTemplate->getTemplatedDecl(), - Kind, KWLoc, + Kind, KWLoc, *ClassTemplate->getIdentifier())) { - Diag(KWLoc, diag::err_use_with_wrong_tag) + Diag(KWLoc, diag::err_use_with_wrong_tag) << ClassTemplate - << CodeModificationHint::CreateReplacement(KWLoc, + << CodeModificationHint::CreateReplacement(KWLoc, ClassTemplate->getTemplatedDecl()->getKindName()); - Diag(ClassTemplate->getTemplatedDecl()->getLocation(), + Diag(ClassTemplate->getTemplatedDecl()->getLocation(), diag::note_previous_use); Kind = ClassTemplate->getTemplatedDecl()->getTagKind(); } @@ -2605,15 +2604,15 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // template. TemplateArgumentListBuilder Converted(ClassTemplate->getTemplateParameters(), TemplateArgs.size()); - if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, LAngleLoc, + if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, LAngleLoc, TemplateArgs.data(), TemplateArgs.size(), RAngleLoc, false, Converted)) return true; - assert((Converted.structuredSize() == + assert((Converted.structuredSize() == ClassTemplate->getTemplateParameters()->size()) && "Converted template argument list is too short!"); - + // Find the class template (partial) specialization declaration that // corresponds to these arguments. llvm::FoldingSetNodeID ID; @@ -2627,11 +2626,11 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, if (MirrorsPrimaryTemplate) { // C++ [temp.class.spec]p9b3: // - // -- The argument list of the specialization shall not be identical - // to the implicit argument list of the primary template. + // -- The argument list of the specialization shall not be identical + // to the implicit argument list of the primary template. Diag(TemplateNameLoc, diag::err_partial_spec_args_match_primary_template) << (TUK == TUK_Definition) - << CodeModificationHint::CreateRemoval(SourceRange(LAngleLoc, + << CodeModificationHint::CreateRemoval(SourceRange(LAngleLoc, RAngleLoc)); return CheckClassTemplate(S, TagSpec, TUK, KWLoc, SS, ClassTemplate->getIdentifier(), @@ -2642,7 +2641,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, } // FIXME: Template parameter list matters, too - ClassTemplatePartialSpecializationDecl::Profile(ID, + ClassTemplatePartialSpecializationDecl::Profile(ID, Converted.getFlatArguments(), Converted.flatSize(), Context); @@ -2656,7 +2655,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, if (isPartialSpecialization) PrevDecl - = ClassTemplate->getPartialSpecializations().FindNodeOrInsertPos(ID, + = ClassTemplate->getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos); else PrevDecl @@ -2667,7 +2666,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // Check whether we can declare a class template specialization in // the current scope. if (CheckClassTemplateSpecializationScope(ClassTemplate, PrevDecl, - TemplateNameLoc, + TemplateNameLoc, SS.getRange(), isPartialSpecialization, /*ExplicitInstantiation=*/false)) @@ -2693,12 +2692,12 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, Converted.flatSize()); // Create a new class template partial specialization declaration node. - TemplateParameterList *TemplateParams + TemplateParameterList *TemplateParams = static_cast<TemplateParameterList*>(*TemplateParameterLists.get()); ClassTemplatePartialSpecializationDecl *PrevPartial = cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl); - ClassTemplatePartialSpecializationDecl *Partial - = ClassTemplatePartialSpecializationDecl::Create(Context, + ClassTemplatePartialSpecializationDecl *Partial + = ClassTemplatePartialSpecializationDecl::Create(Context, ClassTemplate->getDeclContext(), TemplateNameLoc, TemplateParams, @@ -2734,11 +2733,11 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, if (!DeducibleParams[I]) { NamedDecl *Param = cast<NamedDecl>(TemplateParams->getParam(I)); if (Param->getDeclName()) - Diag(Param->getLocation(), + Diag(Param->getLocation(), diag::note_partial_spec_unused_parameter) << Param->getDeclName(); else - Diag(Param->getLocation(), + Diag(Param->getLocation(), diag::note_partial_spec_unused_parameter) << std::string("<anonymous>"); } @@ -2748,10 +2747,10 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // Create a new class template specialization declaration node for // this explicit specialization. Specialization - = ClassTemplateSpecializationDecl::Create(Context, + = ClassTemplateSpecializationDecl::Create(Context, ClassTemplate->getDeclContext(), TemplateNameLoc, - ClassTemplate, + ClassTemplate, Converted, PrevDecl); @@ -2759,7 +2758,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, ClassTemplate->getSpecializations().RemoveNode(PrevDecl); ClassTemplate->getSpecializations().GetOrInsertNode(Specialization); } else { - ClassTemplate->getSpecializations().InsertNode(Specialization, + ClassTemplate->getSpecializations().InsertNode(Specialization, InsertPos); } @@ -2775,7 +2774,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // FIXME: Should also handle explicit specialization after implicit // instantiation with a special diagnostic. SourceRange Range(TemplateNameLoc, RAngleLoc); - Diag(TemplateNameLoc, diag::err_redefinition) + Diag(TemplateNameLoc, diag::err_redefinition) << Context.getTypeDeclType(Specialization) << Range; Diag(Def->getLocation(), diag::note_previous_definition); Specialization->setInvalidDecl(); @@ -2790,8 +2789,8 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // actually wrote the specialization, rather than formatting the // name based on the "canonical" representation used to store the // template arguments in the specialization. - QualType WrittenTy - = Context.getTemplateSpecializationType(Name, + QualType WrittenTy + = Context.getTemplateSpecializationType(Name, TemplateArgs.data(), TemplateArgs.size(), CanonType); @@ -2807,7 +2806,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // but we also maintain the lexical context where the actual // definition occurs. Specialization->setLexicalDeclContext(CurContext); - + // We may be starting the definition of this specialization. if (TUK == TUK_Definition) Specialization->startDefinition(); @@ -2819,34 +2818,34 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, return DeclPtrTy::make(Specialization); } -Sema::DeclPtrTy -Sema::ActOnTemplateDeclarator(Scope *S, +Sema::DeclPtrTy +Sema::ActOnTemplateDeclarator(Scope *S, MultiTemplateParamsArg TemplateParameterLists, Declarator &D) { return HandleDeclarator(S, D, move(TemplateParameterLists), false); } -Sema::DeclPtrTy -Sema::ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, +Sema::DeclPtrTy +Sema::ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, MultiTemplateParamsArg TemplateParameterLists, Declarator &D) { assert(getCurFunctionDecl() == 0 && "Function parsing confused"); assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function && "Not a function declarator!"); DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun; - + if (FTI.hasPrototype) { - // FIXME: Diagnose arguments without names in C. + // FIXME: Diagnose arguments without names in C. } - + Scope *ParentScope = FnBodyScope->getParent(); - - DeclPtrTy DP = HandleDeclarator(ParentScope, D, + + DeclPtrTy DP = HandleDeclarator(ParentScope, D, move(TemplateParameterLists), /*IsFunctionDefinition=*/true); - if (FunctionTemplateDecl *FunctionTemplate + if (FunctionTemplateDecl *FunctionTemplate = dyn_cast_or_null<FunctionTemplateDecl>(DP.getAs<Decl>())) - return ActOnStartOfFunctionDef(FnBodyScope, + return ActOnStartOfFunctionDef(FnBodyScope, DeclPtrTy::make(FunctionTemplate->getTemplatedDecl())); if (FunctionDecl *Function = dyn_cast_or_null<FunctionDecl>(DP.getAs<Decl>())) return ActOnStartOfFunctionDef(FnBodyScope, DeclPtrTy::make(Function)); @@ -2856,10 +2855,10 @@ Sema::ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, // Explicit instantiation of a class template specialization // FIXME: Implement extern template semantics Sema::DeclResult -Sema::ActOnExplicitInstantiation(Scope *S, +Sema::ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, - unsigned TagSpec, + unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, TemplateTy TemplateD, @@ -2871,7 +2870,7 @@ Sema::ActOnExplicitInstantiation(Scope *S, AttributeList *Attr) { // Find the class template we're specializing TemplateName Name = TemplateD.getAsVal<TemplateName>(); - ClassTemplateDecl *ClassTemplate + ClassTemplateDecl *ClassTemplate = cast<ClassTemplateDecl>(Name.getAsTemplateDecl()); // Check that the specialization uses the same tag kind as the @@ -2884,13 +2883,13 @@ Sema::ActOnExplicitInstantiation(Scope *S, case DeclSpec::TST_class: Kind = TagDecl::TK_class; break; } if (!isAcceptableTagRedeclaration(ClassTemplate->getTemplatedDecl(), - Kind, KWLoc, + Kind, KWLoc, *ClassTemplate->getIdentifier())) { - Diag(KWLoc, diag::err_use_with_wrong_tag) + Diag(KWLoc, diag::err_use_with_wrong_tag) << ClassTemplate - << CodeModificationHint::CreateReplacement(KWLoc, + << CodeModificationHint::CreateReplacement(KWLoc, ClassTemplate->getTemplatedDecl()->getKindName()); - Diag(ClassTemplate->getTemplatedDecl()->getLocation(), + Diag(ClassTemplate->getTemplatedDecl()->getLocation(), diag::note_previous_use); Kind = ClassTemplate->getTemplatedDecl()->getTagKind(); } @@ -2901,7 +2900,7 @@ Sema::ActOnExplicitInstantiation(Scope *S, // // This is C++ DR 275. if (CheckClassTemplateSpecializationScope(ClassTemplate, 0, - TemplateNameLoc, + TemplateNameLoc, SS.getRange(), /*PartialSpecialization=*/false, /*ExplicitInstantiation=*/true)) @@ -2915,19 +2914,19 @@ Sema::ActOnExplicitInstantiation(Scope *S, // template. TemplateArgumentListBuilder Converted(ClassTemplate->getTemplateParameters(), TemplateArgs.size()); - if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, LAngleLoc, + if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, LAngleLoc, TemplateArgs.data(), TemplateArgs.size(), RAngleLoc, false, Converted)) return true; - assert((Converted.structuredSize() == + assert((Converted.structuredSize() == ClassTemplate->getTemplateParameters()->size()) && "Converted template argument list is too short!"); - + // Find the class template specialization declaration that // corresponds to these arguments. llvm::FoldingSetNodeID ID; - ClassTemplateSpecializationDecl::Profile(ID, + ClassTemplateSpecializationDecl::Profile(ID, Converted.getFlatArguments(), Converted.flatSize(), Context); @@ -2939,13 +2938,13 @@ Sema::ActOnExplicitInstantiation(Scope *S, bool SpecializationRequiresInstantiation = true; if (PrevDecl) { - if (PrevDecl->getSpecializationKind() + if (PrevDecl->getSpecializationKind() == TSK_ExplicitInstantiationDefinition) { // This particular specialization has already been declared or // instantiated. We cannot explicitly instantiate it. Diag(TemplateNameLoc, diag::err_explicit_instantiation_duplicate) << Context.getTypeDeclType(PrevDecl); - Diag(PrevDecl->getLocation(), + Diag(PrevDecl->getLocation(), diag::note_previous_explicit_instantiation); return DeclPtrTy::make(PrevDecl); } @@ -2957,10 +2956,10 @@ Sema::ActOnExplicitInstantiation(Scope *S, // an explicit specialization for that template, the explicit // instantiation has no effect. if (!getLangOptions().CPlusPlus0x) { - Diag(TemplateNameLoc, + Diag(TemplateNameLoc, diag::ext_explicit_instantiation_after_specialization) << Context.getTypeDeclType(PrevDecl); - Diag(PrevDecl->getLocation(), + Diag(PrevDecl->getLocation(), diag::note_previous_template_specialization); } @@ -2970,7 +2969,7 @@ Sema::ActOnExplicitInstantiation(Scope *S, // accurate reproduction of the source code; we don't actually // use it for anything, since it is semantically irrelevant. Specialization - = ClassTemplateSpecializationDecl::Create(Context, + = ClassTemplateSpecializationDecl::Create(Context, ClassTemplate->getDeclContext(), TemplateNameLoc, ClassTemplate, @@ -2996,13 +2995,13 @@ Sema::ActOnExplicitInstantiation(Scope *S, // Create a new class template specialization declaration node for // this explicit specialization. Specialization - = ClassTemplateSpecializationDecl::Create(Context, + = ClassTemplateSpecializationDecl::Create(Context, ClassTemplate->getDeclContext(), TemplateNameLoc, ClassTemplate, Converted, 0); - ClassTemplate->getSpecializations().InsertNode(Specialization, + ClassTemplate->getSpecializations().InsertNode(Specialization, InsertPos); } @@ -3013,8 +3012,8 @@ Sema::ActOnExplicitInstantiation(Scope *S, // the explicit instantiation, rather than formatting the name based // on the "canonical" representation used to store the template // arguments in the specialization. - QualType WrittenTy - = Context.getTemplateSpecializationType(Name, + QualType WrittenTy + = Context.getTemplateSpecializationType(Name, TemplateArgs.data(), TemplateArgs.size(), Context.getTypeDeclType(Specialization)); @@ -3035,7 +3034,7 @@ Sema::ActOnExplicitInstantiation(Scope *S, // This check comes when we actually try to perform the // instantiation. TemplateSpecializationKind TSK - = ExternLoc.isInvalid()? TSK_ExplicitInstantiationDefinition + = ExternLoc.isInvalid()? TSK_ExplicitInstantiationDefinition : TSK_ExplicitInstantiationDeclaration; if (SpecializationRequiresInstantiation) InstantiateClassTemplateSpecialization(Specialization, TSK); @@ -3048,10 +3047,10 @@ Sema::ActOnExplicitInstantiation(Scope *S, // Explicit instantiation of a member class of a class template. Sema::DeclResult -Sema::ActOnExplicitInstantiation(Scope *S, +Sema::ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, - unsigned TagSpec, + unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, IdentifierInfo *Name, @@ -3092,7 +3091,7 @@ Sema::ActOnExplicitInstantiation(Scope *S, if (getLangOptions().CPlusPlus0x) { // FIXME: In C++98, we would like to turn these errors into warnings, // dependent on a -Wc++0x flag. - DeclContext *PatternContext + DeclContext *PatternContext = Pattern->getDeclContext()->getEnclosingNamespaceContext(); if (!CurContext->Encloses(PatternContext)) { Diag(TemplateLoc, diag::err_explicit_instantiation_out_of_scope) @@ -3102,19 +3101,19 @@ Sema::ActOnExplicitInstantiation(Scope *S, } TemplateSpecializationKind TSK - = ExternLoc.isInvalid()? TSK_ExplicitInstantiationDefinition + = ExternLoc.isInvalid()? TSK_ExplicitInstantiationDefinition : TSK_ExplicitInstantiationDeclaration; - + if (!Record->getDefinition(Context)) { // If the class has a definition, instantiate it (and all of its // members, recursively). Pattern = cast_or_null<CXXRecordDecl>(Pattern->getDefinition(Context)); - if (Pattern && InstantiateClass(TemplateLoc, Record, Pattern, + if (Pattern && InstantiateClass(TemplateLoc, Record, Pattern, getTemplateInstantiationArgs(Record), TSK)) return true; } else // Instantiate all of the members of the class. - InstantiateClassMembers(TemplateLoc, Record, + InstantiateClassMembers(TemplateLoc, Record, getTemplateInstantiationArgs(Record), TSK); // FIXME: We don't have any representation for explicit instantiations of @@ -3127,7 +3126,7 @@ Sema::ActOnExplicitInstantiation(Scope *S, Sema::TypeResult Sema::ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS, const IdentifierInfo &II, SourceLocation IdLoc) { - NestedNameSpecifier *NNS + NestedNameSpecifier *NNS = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); if (!NNS) return true; @@ -3142,9 +3141,9 @@ Sema::TypeResult Sema::ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS, SourceLocation TemplateLoc, TypeTy *Ty) { QualType T = GetTypeFromParser(Ty); - NestedNameSpecifier *NNS + NestedNameSpecifier *NNS = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); - const TemplateSpecializationType *TemplateId + const TemplateSpecializationType *TemplateId = T->getAsTemplateSpecializationType(); assert(TemplateId && "Expected a template specialization type"); @@ -3152,11 +3151,11 @@ Sema::ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS, // If we can compute a declaration context, then the "typename" // keyword was superfluous. Just build a QualifiedNameType to keep // track of the nested-name-specifier. - + // FIXME: Note that the QualifiedNameType had the "typename" keyword! return Context.getQualifiedNameType(NNS, T).getAsOpaquePtr(); } - + return Context.getTypenameType(NNS, TemplateId).getAsOpaquePtr(); } @@ -3173,10 +3172,10 @@ Sema::CheckTypenameType(NestedNameSpecifier *NNS, const IdentifierInfo &II, // instantiation, then build a typename type. if (!CurrentInstantiation) return Context.getTypenameType(NNS, &II); - + // The nested-name-specifier refers to the current instantiation, so the // "typename" keyword itself is superfluous. In C++03, the program is - // actually ill-formed. However, DR 382 (in C++0x CD1) allows such + // actually ill-formed. However, DR 382 (in C++0x CD1) allows such // extraneous "typename" keywords, and we retroactively apply this DR to // C++03 code. } @@ -3197,7 +3196,7 @@ Sema::CheckTypenameType(NestedNameSpecifier *NNS, const IdentifierInfo &II, assert(Ctx && "No declaration context?"); DeclarationName Name(&II); - LookupResult Result = LookupQualifiedName(Ctx, Name, LookupOrdinaryName, + LookupResult Result = LookupQualifiedName(Ctx, Name, LookupOrdinaryName, false); unsigned DiagID = 0; Decl *Referenced = 0; @@ -3247,20 +3246,19 @@ Sema::CheckTypenameType(NestedNameSpecifier *NNS, const IdentifierInfo &II, namespace { // See Sema::RebuildTypeInCurrentInstantiation - class VISIBILITY_HIDDEN CurrentInstantiationRebuilder - : public TreeTransform<CurrentInstantiationRebuilder> - { + class VISIBILITY_HIDDEN CurrentInstantiationRebuilder + : public TreeTransform<CurrentInstantiationRebuilder> { SourceLocation Loc; DeclarationName Entity; - + public: - CurrentInstantiationRebuilder(Sema &SemaRef, + CurrentInstantiationRebuilder(Sema &SemaRef, SourceLocation Loc, - DeclarationName Entity) - : TreeTransform<CurrentInstantiationRebuilder>(SemaRef), + DeclarationName Entity) + : TreeTransform<CurrentInstantiationRebuilder>(SemaRef), Loc(Loc), Entity(Entity) { } - - /// \brief Determine whether the given type \p T has already been + + /// \brief Determine whether the given type \p T has already been /// transformed. /// /// For the purposes of type reconstruction, a type has already been @@ -3268,14 +3266,14 @@ namespace { bool AlreadyTransformed(QualType T) { return T.isNull() || !T->isDependentType(); } - - /// \brief Returns the location of the entity whose type is being + + /// \brief Returns the location of the entity whose type is being /// rebuilt. SourceLocation getBaseLocation() { return Loc; } - + /// \brief Returns the name of the entity whose type is being rebuilt. DeclarationName getBaseEntity() { return Entity; } - + /// \brief Transforms an expression by returning the expression itself /// (an identity function). /// @@ -3284,7 +3282,7 @@ namespace { Sema::OwningExprResult TransformExpr(Expr *E) { return getSema().Owned(E); } - + /// \brief Transforms a typename type by determining whether the type now /// refers to a member of the current instantiation, and then /// type-checking and building a QualifiedNameType (when possible). @@ -3292,7 +3290,7 @@ namespace { }; } -QualType +QualType CurrentInstantiationRebuilder::TransformTypenameType(const TypenameType *T) { NestedNameSpecifier *NNS = TransformNestedNameSpecifier(T->getQualifier(), @@ -3308,30 +3306,30 @@ CurrentInstantiationRebuilder::TransformTypenameType(const TypenameType *T) { SS.setScopeRep(NNS); if (NNS == T->getQualifier() && getSema().computeDeclContext(SS) == 0) return QualType(T, 0); - - // Rebuild the typename type, which will probably turn into a + + // Rebuild the typename type, which will probably turn into a // QualifiedNameType. if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { - QualType NewTemplateId + QualType NewTemplateId = TransformType(QualType(TemplateId, 0)); if (NewTemplateId.isNull()) return QualType(); - + if (NNS == T->getQualifier() && NewTemplateId == QualType(TemplateId, 0)) return QualType(T, 0); - + return getDerived().RebuildTypenameType(NNS, NewTemplateId); } - + return getDerived().RebuildTypenameType(NNS, T->getIdentifier()); } /// \brief Rebuilds a type within the context of the current instantiation. /// -/// The type \p T is part of the type of an out-of-line member definition of +/// The type \p T is part of the type of an out-of-line member definition of /// a class template (or class template partial specialization) that was parsed -/// and constructed before we entered the scope of the class template (or +/// and constructed before we entered the scope of the class template (or /// partial specialization thereof). This routine will rebuild that type now /// that we have entered the declarator's scope, which may produce different /// canonical types, e.g., @@ -3357,7 +3355,7 @@ QualType Sema::RebuildTypeInCurrentInstantiation(QualType T, SourceLocation Loc, DeclarationName Name) { if (T.isNull() || !T->isDependentType()) return T; - + CurrentInstantiationRebuilder Rebuilder(*this, Loc, Name); return Rebuilder.TransformType(T); } diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 2253a4e6a7..b861dcabfe 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -45,7 +45,7 @@ namespace clang { using namespace clang; static Sema::TemplateDeductionResult -DeduceTemplateArguments(ASTContext &Context, +DeduceTemplateArguments(ASTContext &Context, TemplateParameterList *TemplateParams, const TemplateArgument &Param, const TemplateArgument &Arg, @@ -58,27 +58,27 @@ DeduceTemplateArguments(ASTContext &Context, static NonTypeTemplateParmDecl *getDeducedParameterFromExpr(Expr *E) { if (ImplicitCastExpr *IC = dyn_cast<ImplicitCastExpr>(E)) E = IC->getSubExpr(); - + if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) return dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()); - + return 0; } -/// \brief Deduce the value of the given non-type template parameter +/// \brief Deduce the value of the given non-type template parameter /// from the given constant. static Sema::TemplateDeductionResult -DeduceNonTypeTemplateArgument(ASTContext &Context, - NonTypeTemplateParmDecl *NTTP, +DeduceNonTypeTemplateArgument(ASTContext &Context, + NonTypeTemplateParmDecl *NTTP, llvm::APSInt Value, Sema::TemplateDeductionInfo &Info, llvm::SmallVectorImpl<TemplateArgument> &Deduced) { - assert(NTTP->getDepth() == 0 && + assert(NTTP->getDepth() == 0 && "Cannot deduce non-type template argument with depth > 0"); - + if (Deduced[NTTP->getIndex()].isNull()) { QualType T = NTTP->getType(); - + // FIXME: Make sure we didn't overflow our data type! unsigned AllowedBits = Context.getTypeSize(T); if (Value.getBitWidth() != AllowedBits) @@ -88,10 +88,10 @@ DeduceNonTypeTemplateArgument(ASTContext &Context, Deduced[NTTP->getIndex()] = TemplateArgument(SourceLocation(), Value, T); return Sema::TDK_Success; } - + assert(Deduced[NTTP->getIndex()].getKind() == TemplateArgument::Integral); - - // If the template argument was previously deduced to a negative value, + + // If the template argument was previously deduced to a negative value, // then our deduction fails. const llvm::APSInt *PrevValuePtr = Deduced[NTTP->getIndex()].getAsIntegral(); if (PrevValuePtr->isNegative()) { @@ -117,35 +117,35 @@ DeduceNonTypeTemplateArgument(ASTContext &Context, return Sema::TDK_Success; } -/// \brief Deduce the value of the given non-type template parameter +/// \brief Deduce the value of the given non-type template parameter /// from the given type- or value-dependent expression. /// /// \returns true if deduction succeeded, false otherwise. static Sema::TemplateDeductionResult -DeduceNonTypeTemplateArgument(ASTContext &Context, +DeduceNonTypeTemplateArgument(ASTContext &Context, NonTypeTemplateParmDecl *NTTP, Expr *Value, Sema::TemplateDeductionInfo &Info, llvm::SmallVectorImpl<TemplateArgument> &Deduced) { - assert(NTTP->getDepth() == 0 && + assert(NTTP->getDepth() == 0 && "Cannot deduce non-type template argument with depth > 0"); assert((Value->isTypeDependent() || Value->isValueDependent()) && "Expression template argument must be type- or value-dependent."); - + if (Deduced[NTTP->getIndex()].isNull()) { // FIXME: Clone the Value? Deduced[NTTP->getIndex()] = TemplateArgument(Value); return Sema::TDK_Success; } - + if (Deduced[NTTP->getIndex()].getKind() == TemplateArgument::Integral) { - // Okay, we deduced a constant in one case and a dependent expression - // in another case. FIXME: Later, we will check that instantiating the + // Okay, we deduced a constant in one case and a dependent expression + // in another case. FIXME: Later, we will check that instantiating the // dependent expression gives us the constant value. return Sema::TDK_Success; } - + // FIXME: Compare the expressions for equality! return Sema::TDK_Success; } @@ -164,7 +164,7 @@ DeduceTemplateArguments(ASTContext &Context, TemplateDecl *ParamDecl = Param.getAsTemplateDecl(); TemplateDecl *ArgDecl = Arg.getAsTemplateDecl(); - + if (!ParamDecl || !ArgDecl) { // FIXME: fill in Info.Param/Info.FirstArg return Sema::TDK_Inconsistent; @@ -180,7 +180,7 @@ DeduceTemplateArguments(ASTContext &Context, return Sema::TDK_Success; } -/// \brief Deduce the template arguments by comparing the template parameter +/// \brief Deduce the template arguments by comparing the template parameter /// type (which is a template-id) with the template argument type. /// /// \param Context the AST context in which this deduction occurs. @@ -206,11 +206,11 @@ DeduceTemplateArguments(ASTContext &Context, Sema::TemplateDeductionInfo &Info, llvm::SmallVectorImpl<TemplateArgument> &Deduced) { assert(Arg->isCanonical() && "Argument type must be canonical"); - + // Check whether the template argument is a dependent template-id. // FIXME: This is untested code; it can be tested when we implement // partial ordering of class template partial specializations. - if (const TemplateSpecializationType *SpecArg + if (const TemplateSpecializationType *SpecArg = dyn_cast<TemplateSpecializationType>(Arg)) { // Perform template argument deduction for the template name. if (Sema::TemplateDeductionResult Result @@ -219,9 +219,9 @@ DeduceTemplateArguments(ASTContext &Context, SpecArg->getTemplateName(), Info, Deduced)) return Result; - + unsigned NumArgs = Param->getNumArgs(); - + // FIXME: When one of the template-names refers to a // declaration with default template arguments, do we need to // fill in those default template arguments here? Most likely, @@ -231,7 +231,7 @@ DeduceTemplateArguments(ASTContext &Context, // the template-id. if (SpecArg->getNumArgs() != NumArgs) return Sema::TDK_NonDeducedMismatch; - + // Perform template argument deduction on each template // argument. for (unsigned I = 0; I != NumArgs; ++I) @@ -241,49 +241,49 @@ DeduceTemplateArguments(ASTContext &Context, SpecArg->getArg(I), Info, Deduced)) return Result; - + return Sema::TDK_Success; } - + // If the argument type is a class template specialization, we // perform template argument deduction using its template // arguments. const RecordType *RecordArg = dyn_cast<RecordType>(Arg); if (!RecordArg) return Sema::TDK_NonDeducedMismatch; - - ClassTemplateSpecializationDecl *SpecArg + + ClassTemplateSpecializationDecl *SpecArg = dyn_cast<ClassTemplateSpecializationDecl>(RecordArg->getDecl()); if (!SpecArg) return Sema::TDK_NonDeducedMismatch; - + // Perform template argument deduction for the template name. if (Sema::TemplateDeductionResult Result - = DeduceTemplateArguments(Context, + = DeduceTemplateArguments(Context, Param->getTemplateName(), TemplateName(SpecArg->getSpecializedTemplate()), Info, Deduced)) return Result; - + // FIXME: Can the # of arguments in the parameter and the argument // differ due to default arguments? unsigned NumArgs = Param->getNumArgs(); const TemplateArgumentList &ArgArgs = SpecArg->getTemplateArgs(); if (NumArgs != ArgArgs.size()) return Sema::TDK_NonDeducedMismatch; - + for (unsigned I = 0; I != NumArgs; ++I) - if (Sema::TemplateDeductionResult Result + if (Sema::TemplateDeductionResult Result = DeduceTemplateArguments(Context, TemplateParams, Param->getArg(I), ArgArgs.get(I), Info, Deduced)) return Result; - + return Sema::TDK_Success; } -/// \brief Returns a completely-unqualified array type, capturing the +/// \brief Returns a completely-unqualified array type, capturing the /// qualifiers in CVRQuals. /// /// \param Context the AST context in which the array type was built. @@ -302,32 +302,32 @@ static QualType getUnqualifiedArrayType(ASTContext &Context, QualType T, CVRQuals = T.getCVRQualifiers(); return T.getUnqualifiedType(); } - + if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(T)) { QualType Elt = getUnqualifiedArrayType(Context, CAT->getElementType(), CVRQuals); if (Elt == CAT->getElementType()) return T; - return Context.getConstantArrayType(Elt, CAT->getSize(), + return Context.getConstantArrayType(Elt, CAT->getSize(), CAT->getSizeModifier(), 0); } - + if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(T)) { QualType Elt = getUnqualifiedArrayType(Context, IAT->getElementType(), CVRQuals); if (Elt == IAT->getElementType()) return T; - + return Context.getIncompleteArrayType(Elt, IAT->getSizeModifier(), 0); } - + const DependentSizedArrayType *DSAT = cast<DependentSizedArrayType>(T); QualType Elt = getUnqualifiedArrayType(Context, DSAT->getElementType(), CVRQuals); if (Elt == DSAT->getElementType()) return T; - + return Context.getDependentSizedArrayType(Elt, DSAT->getSizeExpr()->Retain(), DSAT->getSizeModifier(), 0, SourceRange()); @@ -349,13 +349,13 @@ static QualType getUnqualifiedArrayType(ASTContext &Context, QualType T, /// \param Deduced the deduced template arguments /// /// \param TDF bitwise OR of the TemplateDeductionFlags bits that describe -/// how template argument deduction is performed. +/// how template argument deduction is performed. /// /// \returns the result of template argument deduction so far. Note that a /// "success" result means that template argument deduction has not yet failed, /// but it may still fail, later, for other reasons. static Sema::TemplateDeductionResult -DeduceTemplateArguments(ASTContext &Context, +DeduceTemplateArguments(ASTContext &Context, TemplateParameterList *TemplateParams, QualType ParamIn, QualType ArgIn, Sema::TemplateDeductionInfo &Info, @@ -368,30 +368,30 @@ DeduceTemplateArguments(ASTContext &Context, // C++0x [temp.deduct.call]p4 bullet 1: // - If the original P is a reference type, the deduced A (i.e., the type - // referred to by the reference) can be more cv-qualified than the + // referred to by the reference) can be more cv-qualified than the // transformed A. if (TDF & TDF_ParamWithReferenceType) { - unsigned ExtraQualsOnParam + unsigned ExtraQualsOnParam = Param.getCVRQualifiers() & ~Arg.getCVRQualifiers(); Param.setCVRQualifiers(Param.getCVRQualifiers() & ~ExtraQualsOnParam); } - + // If the parameter type is not dependent, there is nothing to deduce. if (!Param->isDependentType()) return Sema::TDK_Success; // C++ [temp.deduct.type]p9: - // A template type argument T, a template template argument TT or a - // template non-type argument i can be deduced if P and A have one of + // A template type argument T, a template template argument TT or a + // template non-type argument i can be deduced if P and A have one of // the following forms: // // T // cv-list T - if (const TemplateTypeParmType *TemplateTypeParm + if (const TemplateTypeParmType *TemplateTypeParm = Param->getAsTemplateTypeParmType()) { unsigned Index = TemplateTypeParm->getIndex(); bool RecanonicalizeArg = false; - + // If the argument type is an array type, move the qualifiers up to the // top level, so they can be matched with the qualifiers on the parameter. // FIXME: address spaces, ObjC GC qualifiers @@ -403,7 +403,7 @@ DeduceTemplateArguments(ASTContext &Context, RecanonicalizeArg = true; } } - + // The argument type can not be less qualified than the parameter // type. if (Param.isMoreQualifiedThan(Arg) && !(TDF & TDF_IgnoreQualifiers)) { @@ -414,23 +414,23 @@ DeduceTemplateArguments(ASTContext &Context, } assert(TemplateTypeParm->getDepth() == 0 && "Can't deduce with depth > 0"); - + unsigned Quals = Arg.getCVRQualifiers() & ~Param.getCVRQualifiers(); QualType DeducedType = Arg.getQualifiedType(Quals); if (RecanonicalizeArg) DeducedType = Context.getCanonicalType(DeducedType); - + if (Deduced[Index].isNull()) Deduced[Index] = TemplateArgument(SourceLocation(), DeducedType); else { - // C++ [temp.deduct.type]p2: + // C++ [temp.deduct.type]p2: // [...] If type deduction cannot be done for any P/A pair, or if for - // any pair the deduction leads to more than one possible set of - // deduced values, or if different pairs yield different deduced - // values, or if any template argument remains neither deduced nor + // any pair the deduction leads to more than one possible set of + // deduced values, or if different pairs yield different deduced + // values, or if any template argument remains neither deduced nor // explicitly specified, template argument deduction fails. if (Deduced[Index].getAsType() != DeducedType) { - Info.Param + Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->getParam(Index)); Info.FirstArg = Deduced[Index]; Info.SecondArg = TemplateArgument(SourceLocation(), Arg); @@ -451,7 +451,7 @@ DeduceTemplateArguments(ASTContext &Context, return Sema::TDK_NonDeducedMismatch; } else { if (Param.getCVRQualifiers() != Arg.getCVRQualifiers()) - return Sema::TDK_NonDeducedMismatch; + return Sema::TDK_NonDeducedMismatch; } } @@ -459,26 +459,26 @@ DeduceTemplateArguments(ASTContext &Context, // No deduction possible for these types case Type::Builtin: return Sema::TDK_NonDeducedMismatch; - + // T * case Type::Pointer: { const PointerType *PointerArg = Arg->getAs<PointerType>(); if (!PointerArg) return Sema::TDK_NonDeducedMismatch; - + unsigned SubTDF = TDF & (TDF_IgnoreQualifiers | TDF_DerivedClass); return DeduceTemplateArguments(Context, TemplateParams, cast<PointerType>(Param)->getPointeeType(), PointerArg->getPointeeType(), Info, Deduced, SubTDF); } - + // T & case Type::LValueReference: { const LValueReferenceType *ReferenceArg = Arg->getAs<LValueReferenceType>(); if (!ReferenceArg) return Sema::TDK_NonDeducedMismatch; - + return DeduceTemplateArguments(Context, TemplateParams, cast<LValueReferenceType>(Param)->getPointeeType(), ReferenceArg->getPointeeType(), @@ -490,20 +490,20 @@ DeduceTemplateArguments(ASTContext &Context, const RValueReferenceType *ReferenceArg = Arg->getAs<RValueReferenceType>(); if (!ReferenceArg) return Sema::TDK_NonDeducedMismatch; - + return DeduceTemplateArguments(Context, TemplateParams, cast<RValueReferenceType>(Param)->getPointeeType(), ReferenceArg->getPointeeType(), Info, Deduced, 0); } - + // T [] (implied, but not stated explicitly) case Type::IncompleteArray: { - const IncompleteArrayType *IncompleteArrayArg = + const IncompleteArrayType *IncompleteArrayArg = Context.getAsIncompleteArrayType(Arg); if (!IncompleteArrayArg) return Sema::TDK_NonDeducedMismatch; - + return DeduceTemplateArguments(Context, TemplateParams, Context.getAsIncompleteArrayType(Param)->getElementType(), IncompleteArrayArg->getElementType(), @@ -512,16 +512,16 @@ DeduceTemplateArguments(ASTContext &Context, // T [integer-constant] case Type::ConstantArray: { - const ConstantArrayType *ConstantArrayArg = + const ConstantArrayType *ConstantArrayArg = Context.getAsConstantArrayType(Arg); if (!ConstantArrayArg) return Sema::TDK_NonDeducedMismatch; - - const ConstantArrayType *ConstantArrayParm = + + const ConstantArrayType *ConstantArrayParm = Context.getAsConstantArrayType(Param); if (ConstantArrayArg->getSize() != ConstantArrayParm->getSize()) return Sema::TDK_NonDeducedMismatch; - + return DeduceTemplateArguments(Context, TemplateParams, ConstantArrayParm->getElementType(), ConstantArrayArg->getElementType(), @@ -533,7 +533,7 @@ DeduceTemplateArguments(ASTContext &Context, const ArrayType *ArrayArg = dyn_cast<ArrayType>(Arg); if (!ArrayArg) return Sema::TDK_NonDeducedMismatch; - + // Check the element type of the arrays const DependentSizedArrayType *DependentArrayParm = cast<DependentSizedArrayType>(Param); @@ -543,18 +543,18 @@ DeduceTemplateArguments(ASTContext &Context, ArrayArg->getElementType(), Info, Deduced, 0)) return Result; - + // Determine the array bound is something we can deduce. - NonTypeTemplateParmDecl *NTTP + NonTypeTemplateParmDecl *NTTP = getDeducedParameterFromExpr(DependentArrayParm->getSizeExpr()); if (!NTTP) return Sema::TDK_Success; - - // We can perform template argument deduction for the given non-type + + // We can perform template argument deduction for the given non-type // template parameter. - assert(NTTP->getDepth() == 0 && + assert(NTTP->getDepth() == 0 && "Cannot deduce non-type template argument at depth > 0"); - if (const ConstantArrayType *ConstantArrayArg + if (const ConstantArrayType *ConstantArrayArg = dyn_cast<ConstantArrayType>(ArrayArg)) { llvm::APSInt Size(ConstantArrayArg->getSize()); return DeduceNonTypeTemplateArgument(Context, NTTP, Size, @@ -565,30 +565,30 @@ DeduceTemplateArguments(ASTContext &Context, return DeduceNonTypeTemplateArgument(Context, NTTP, DependentArrayArg->getSizeExpr(), Info, Deduced); - + // Incomplete type does not match a dependently-sized array type return Sema::TDK_NonDeducedMismatch; } - - // type(*)(T) - // T(*)() - // T(*)(T) + + // type(*)(T) + // T(*)() + // T(*)(T) case Type::FunctionProto: { - const FunctionProtoType *FunctionProtoArg = + const FunctionProtoType *FunctionProtoArg = dyn_cast<FunctionProtoType>(Arg); if (!FunctionProtoArg) return Sema::TDK_NonDeducedMismatch; - - const FunctionProtoType *FunctionProtoParam = + + const FunctionProtoType *FunctionProtoParam = cast<FunctionProtoType>(Param); - if (FunctionProtoParam->getTypeQuals() != + if (FunctionProtoParam->getTypeQuals() != FunctionProtoArg->getTypeQuals()) return Sema::TDK_NonDeducedMismatch; - + if (FunctionProtoParam->getNumArgs() != FunctionProtoArg->getNumArgs()) return Sema::TDK_NonDeducedMismatch; - + if (FunctionProtoParam->isVariadic() != FunctionProtoArg->isVariadic()) return Sema::TDK_NonDeducedMismatch; @@ -599,7 +599,7 @@ DeduceTemplateArguments(ASTContext &Context, FunctionProtoArg->getResultType(), Info, Deduced, 0)) return Result; - + for (unsigned I = 0, N = FunctionProtoParam->getNumArgs(); I != N; ++I) { // Check argument types. if (Sema::TemplateDeductionResult Result @@ -609,10 +609,10 @@ DeduceTemplateArguments(ASTContext &Context, Info, Deduced, 0)) return Result; } - + return Sema::TDK_Success; } - + // template-name<T> (where template-name refers to a class template) // template-name<i> // TT<T> (TODO) @@ -621,26 +621,26 @@ DeduceTemplateArguments(ASTContext &Context, case Type::TemplateSpecialization: { const TemplateSpecializationType *SpecParam = cast<TemplateSpecializationType>(Param); - + // Try to deduce template arguments from the template-id. Sema::TemplateDeductionResult Result - = DeduceTemplateArguments(Context, TemplateParams, SpecParam, Arg, + = DeduceTemplateArguments(Context, TemplateParams, SpecParam, Arg, Info, Deduced); - - if (Result && (TDF & TDF_DerivedClass) && + + if (Result && (TDF & TDF_DerivedClass) && Result != Sema::TDK_Inconsistent) { // C++ [temp.deduct.call]p3b3: // If P is a class, and P has the form template-id, then A can be a // derived class of the deduced A. Likewise, if P is a pointer to a - // class of the form template-id, A can be a pointer to a derived + // class of the form template-id, A can be a pointer to a derived // class pointed to by the deduced A. // // More importantly: - // These alternatives are considered only if type deduction would + // These alternatives are considered only if type deduction would // otherwise fail. if (const RecordType *RecordT = dyn_cast<RecordType>(Arg)) { // Use data recursion to crawl through the list of base classes. - // Visited contains the set of nodes we have already visited, while + // Visited contains the set of nodes we have already visited, while // ToVisit is our stack of records that we still need to visit. llvm::SmallPtrSet<const RecordType *, 8> Visited; llvm::SmallVector<const RecordType *, 8> ToVisit; @@ -650,18 +650,18 @@ DeduceTemplateArguments(ASTContext &Context, // Retrieve the next class in the inheritance hierarchy. const RecordType *NextT = ToVisit.back(); ToVisit.pop_back(); - + // If we have already seen this type, skip it. if (!Visited.insert(NextT)) continue; - + // If this is a base class, try to perform template argument // deduction from it. if (NextT != RecordT) { Sema::TemplateDeductionResult BaseResult = DeduceTemplateArguments(Context, TemplateParams, SpecParam, QualType(NextT, 0), Info, Deduced); - + // If template argument deduction for this base was successful, // note that we had some success. if (BaseResult == Sema::TDK_Success) @@ -672,24 +672,24 @@ DeduceTemplateArguments(ASTContext &Context, else if (BaseResult == Sema::TDK_Inconsistent) return BaseResult; } - + // Visit base classes CXXRecordDecl *Next = cast<CXXRecordDecl>(NextT->getDecl()); for (CXXRecordDecl::base_class_iterator Base = Next->bases_begin(), BaseEnd = Next->bases_end(); Base != BaseEnd; ++Base) { - assert(Base->getType()->isRecordType() && + assert(Base->getType()->isRecordType() && "Base class that isn't a record?"); ToVisit.push_back(Base->getType()->getAs<RecordType>()); } } - + if (Successful) return Sema::TDK_Success; } - + } - + return Result; } @@ -724,16 +724,16 @@ DeduceTemplateArguments(ASTContext &Context, // (clang extension) // - // type(^)(T) - // T(^)() - // T(^)(T) + // type(^)(T) + // T(^)() + // T(^)(T) case Type::BlockPointer: { const BlockPointerType *BlockPtrParam = cast<BlockPointerType>(Param); const BlockPointerType *BlockPtrArg = dyn_cast<BlockPointerType>(Arg); - + if (!BlockPtrArg) return Sema::TDK_NonDeducedMismatch; - + return DeduceTemplateArguments(Context, TemplateParams, BlockPtrParam->getPointeeType(), BlockPtrArg->getPointeeType(), Info, @@ -755,7 +755,7 @@ DeduceTemplateArguments(ASTContext &Context, } static Sema::TemplateDeductionResult -DeduceTemplateArguments(ASTContext &Context, +DeduceTemplateArguments(ASTContext &Context, TemplateParameterList *TemplateParams, const TemplateArgument &Param, const TemplateArgument &Arg, @@ -765,8 +765,8 @@ DeduceTemplateArguments(ASTContext &Context, case TemplateArgument::Null: assert(false && "Null template argument in parameter list"); break; - - case TemplateArgument::Type: + + case TemplateArgument::Type: assert(Arg.getKind() == TemplateArgument::Type && "Type/value mismatch"); return DeduceTemplateArguments(Context, TemplateParams, Param.getAsType(), Arg.getAsType(), Info, Deduced, 0); @@ -777,7 +777,7 @@ DeduceTemplateArguments(ASTContext &Context, Info.FirstArg = Param; Info.SecondArg = Arg; return Sema::TDK_NonDeducedMismatch; - + case TemplateArgument::Integral: if (Arg.getKind() == TemplateArgument::Integral) { // FIXME: Zero extension + sign checking here? @@ -799,25 +799,25 @@ DeduceTemplateArguments(ASTContext &Context, Info.FirstArg = Param; Info.SecondArg = Arg; return Sema::TDK_NonDeducedMismatch; - + case TemplateArgument::Expression: { - if (NonTypeTemplateParmDecl *NTTP + if (NonTypeTemplateParmDecl *NTTP = getDeducedParameterFromExpr(Param.getAsExpr())) { if (Arg.getKind() == TemplateArgument::Integral) // FIXME: Sign problems here - return DeduceNonTypeTemplateArgument(Context, NTTP, - *Arg.getAsIntegral(), + return DeduceNonTypeTemplateArgument(Context, NTTP, + *Arg.getAsIntegral(), Info, Deduced); if (Arg.getKind() == TemplateArgument::Expression) return DeduceNonTypeTemplateArgument(Context, NTTP, Arg.getAsExpr(), Info, Deduced); - + assert(false && "Type/value mismatch"); Info.FirstArg = Param; Info.SecondArg = Arg; return Sema::TDK_NonDeducedMismatch; } - + // Can't deduce anything, but that's okay. return Sema::TDK_Success; } @@ -825,11 +825,11 @@ DeduceTemplateArguments(ASTContext &Context, assert(0 && "FIXME: Implement!"); break; } - + return Sema::TDK_Success; } -static Sema::TemplateDeductionResult +static Sema::TemplateDeductionResult DeduceTemplateArguments(ASTContext &Context, TemplateParameterList *TemplateParams, const TemplateArgumentList &ParamList, @@ -840,7 +840,7 @@ DeduceTemplateArguments(ASTContext &Context, for (unsigned I = 0, N = ParamList.size(); I != N; ++I) { if (Sema::TemplateDeductionResult Result = DeduceTemplateArguments(Context, TemplateParams, - ParamList[I], ArgList[I], + ParamList[I], ArgList[I], Info, Deduced)) return Result; } @@ -848,41 +848,41 @@ DeduceTemplateArguments(ASTContext &Context, } /// \brief Determine whether two template arguments are the same. -static bool isSameTemplateArg(ASTContext &Context, +static bool isSameTemplateArg(ASTContext &Context, const TemplateArgument &X, const TemplateArgument &Y) { if (X.getKind() != Y.getKind()) return false; - + switch (X.getKind()) { case TemplateArgument::Null: assert(false && "Comparing NULL template argument"); break; - + case TemplateArgument::Type: return Context.getCanonicalType(X.getAsType()) == Context.getCanonicalType(Y.getAsType()); - + case TemplateArgument::Declaration: return X.getAsDecl()->getCanonicalDecl() == Y.getAsDecl()->getCanonicalDecl(); - + case TemplateArgument::Integral: return *X.getAsIntegral() == *Y.getAsIntegral(); - + case TemplateArgument::Expression: // FIXME: We assume that all expressions are distinct, but we should // really check their canonical forms. return false; - + case TemplateArgument::Pack: if (X.pack_size() != Y.pack_size()) return false; - - for (TemplateArgument::pack_iterator XP = X.pack_begin(), - XPEnd = X.pack_end(), + + for (TemplateArgument::pack_iterator XP = X.pack_begin(), + XPEnd = X.pack_end(), YP = Y.pack_begin(); - XP != XPEnd; ++XP, ++YP) + XP != XPEnd; ++XP, ++YP) if (!isSameTemplateArg(Context, *XP, *YP)) return false; @@ -899,7 +899,7 @@ static TemplateParameter makeTemplateParameter(Decl *D) { return TemplateParameter(TTP); else if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) return TemplateParameter(NTTP); - + return TemplateParameter(cast<TemplateTemplateParmDecl>(D)); } @@ -919,9 +919,9 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, llvm::SmallVector<TemplateArgument, 4> Deduced; Deduced.resize(Partial->getTemplateParameters()->size()); if (TemplateDeductionResult Result - = ::DeduceTemplateArguments(Context, + = ::DeduceTemplateArguments(Context, Partial->getTemplateParameters(), - Partial->getTemplateArgs(), + Partial->getTemplateArgs(), TemplateArgs, Info, Deduced)) return Result; @@ -937,11 +937,11 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, Deduced.size()); for (unsigned I = 0, N = Deduced.size(); I != N; ++I) { if (Deduced[I].isNull()) { - Decl *Param + Decl *Param = const_cast<Decl *>(Partial->getTemplateParameters()->getParam(I)); if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) Info.Param = TTP; - else if (NonTypeTemplateParmDecl *NTTP + else if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) Info.Param = NTTP; else @@ -953,7 +953,7 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, } // Form the template argument list from the deduced template arguments. - TemplateArgumentList *DeducedArgumentList + TemplateArgumentList *DeducedArgumentList = new (Context) TemplateArgumentList(Context, Builder, /*TakeArgs=*/true); Info.reset(DeducedArgumentList); @@ -961,45 +961,45 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, // arguments of the class template partial specialization, and // verify that the instantiated template arguments are both valid // and are equivalent to the template arguments originally provided - // to the class template. + // to the class template. ClassTemplateDecl *ClassTemplate = Partial->getSpecializedTemplate(); const TemplateArgumentList &PartialTemplateArgs = Partial->getTemplateArgs(); for (unsigned I = 0, N = PartialTemplateArgs.flat_size(); I != N; ++I) { Decl *Param = const_cast<Decl *>( ClassTemplate->getTemplateParameters()->getParam(I)); - TemplateArgument InstArg + TemplateArgument InstArg = Subst(PartialTemplateArgs[I], MultiLevelTemplateArgumentList(*DeducedArgumentList)); if (InstArg.isNull()) { Info.Param = makeTemplateParameter(Param); Info.FirstArg = PartialTemplateArgs[I]; - return TDK_SubstitutionFailure; + return TDK_SubstitutionFailure; } - + if (InstArg.getKind() == TemplateArgument::Expression) { - // When the argument is an expression, check the expression result + // When the argument is an expression, check the expression result // against the actual template parameter to get down to the canonical // template argument. Expr *InstExpr = InstArg.getAsExpr(); - if (NonTypeTemplateParmDecl *NTTP + if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) { if (CheckTemplateArgument(NTTP, NTTP->getType(), InstExpr, InstArg)) { Info.Param = makeTemplateParameter(Param); Info.FirstArg = PartialTemplateArgs[I]; - return TDK_SubstitutionFailure; + return TDK_SubstitutionFailure; } - } else if (TemplateTemplateParmDecl *TTP + } else if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) { // FIXME: template template arguments should really resolve to decls DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(InstExpr); if (!DRE || CheckTemplateArgument(TTP, DRE)) { Info.Param = makeTemplateParameter(Param); Info.FirstArg = PartialTemplateArgs[I]; - return TDK_SubstitutionFailure; + return TDK_SubstitutionFailure; } } } - + if (!isSameTemplateArg(Context, TemplateArgs[I], InstArg)) { Info.Param = makeTemplateParameter(Param); Info.FirstArg = TemplateArgs[I]; @@ -1016,10 +1016,10 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, /// \brief Determine whether the given type T is a simple-template-id type. static bool isSimpleTemplateIdType(QualType T) { - if (const TemplateSpecializationType *Spec + if (const TemplateSpecializationType *Spec = T->getAsTemplateSpecializationType()) return Spec->getTemplateName().getAsTemplateDecl() != 0; - + return false; } @@ -1029,16 +1029,16 @@ static bool isSimpleTemplateIdType(QualType T) { /// \param FunctionTemplate the function template into which the explicit /// template arguments will be substituted. /// -/// \param ExplicitTemplateArguments the explicitly-specified template +/// \param ExplicitTemplateArguments the explicitly-specified template /// arguments. /// -/// \param NumExplicitTemplateArguments the number of explicitly-specified +/// \param NumExplicitTemplateArguments the number of explicitly-specified /// template arguments in @p ExplicitTemplateArguments. This value may be zero. /// -/// \param Deduced the deduced template arguments, which will be populated +/// \param Deduced the deduced template arguments, which will be populated /// with the converted and checked explicit template arguments. /// -/// \param ParamTypes will be populated with the instantiated function +/// \param ParamTypes will be populated with the instantiated function /// parameters. /// /// \param FunctionType if non-NULL, the result type of the function template @@ -1071,33 +1071,33 @@ Sema::SubstituteExplicitTemplateArguments( P != PEnd; ++P) ParamTypes.push_back((*P)->getType()); - + if (FunctionType) *FunctionType = Function->getType(); return TDK_Success; } - + // Substitution of the explicit template arguments into a function template /// is a SFINAE context. Trap any errors that might occur. - SFINAETrap Trap(*this); - + SFINAETrap Trap(*this); + // C++ [temp.arg.explicit]p3: - // Template arguments that are present shall be specified in the - // declaration order of their corresponding template-parameters. The + // Template arguments that are present shall be specified in the + // declaration order of their corresponding template-parameters. The // template argument list shall not specify more template-arguments than - // there are corresponding template-parameters. - TemplateArgumentListBuilder Builder(TemplateParams, + // there are corresponding template-parameters. + TemplateArgumentListBuilder Builder(TemplateParams, NumExplicitTemplateArgs); - - // Enter a new template instantiation context where we check the + + // Enter a new template instantiation context where we check the // explicitly-specified template arguments against this function template, // and then substitute them into the function parameter types. - InstantiatingTemplate Inst(*this, FunctionTemplate->getLocation(), + InstantiatingTemplate Inst(*this, FunctionTemplate->getLocation(), FunctionTemplate, Deduced.data(), Deduced.size(), ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution); if (Inst) return TDK_InstantiationDepth; - + if (CheckTemplateArgumentList(FunctionTemplate, SourceLocation(), SourceLocation(), ExplicitTemplateArgs, @@ -1106,26 +1106,26 @@ Sema::SubstituteExplicitTemplateArguments( true, Builder) || Trap.hasErrorOccurred()) return TDK_InvalidExplicitArguments; - + // Form the template argument list from the explicitly-specified // template arguments. - TemplateArgumentList *ExplicitArgumentList + TemplateArgumentList *ExplicitArgumentList = new (Context) TemplateArgumentList(Context, Builder, /*TakeArgs=*/true); Info.reset(ExplicitArgumentList); - + // Instantiate the types of each of the function parameters given the // explicitly-specified template arguments. for (FunctionDecl::param_iterator P = Function->param_begin(), PEnd = Function->param_end(); P != PEnd; ++P) { - QualType ParamType - = SubstType((*P)->getType(), + QualType ParamType + = SubstType((*P)->getType(), MultiLevelTemplateArgumentList(*ExplicitArgumentList), (*P)->getLocation(), (*P)->getDeclName()); if (ParamType.isNull() || Trap.hasErrorOccurred()) return TDK_SubstitutionFailure; - + ParamTypes.push_back(ParamType); } @@ -1133,19 +1133,19 @@ Sema::SubstituteExplicitTemplateArguments( // type and form that function type. if (FunctionType) { // FIXME: exception-specifications? - const FunctionProtoType *Proto + const FunctionProtoType *Proto = Function->getType()->getAsFunctionProtoType(); assert(Proto && "Function template does not have a prototype?"); - - QualType ResultType + + QualType ResultType = SubstType(Proto->getResultType(), MultiLevelTemplateArgumentList(*ExplicitArgumentList), Function->getTypeSpecStartLoc(), Function->getDeclName()); if (ResultType.isNull() || Trap.hasErrorOccurred()) return TDK_SubstitutionFailure; - - *FunctionType = BuildFunctionType(ResultType, + + *FunctionType = BuildFunctionType(ResultType, ParamTypes.data(), ParamTypes.size(), Proto->isVariadic(), Proto->getTypeQuals(), @@ -1154,33 +1154,33 @@ Sema::SubstituteExplicitTemplateArguments( if (FunctionType->isNull() || Trap.hasErrorOccurred()) return TDK_SubstitutionFailure; } - + // C++ [temp.arg.explicit]p2: - // Trailing template arguments that can be deduced (14.8.2) may be - // omitted from the list of explicit template-arguments. If all of the + // Trailing template arguments that can be deduced (14.8.2) may be + // omitted from the list of explicit template-arguments. If all of the // template arguments can be deduced, they may all be omitted; in this // case, the empty template argument list <> itself may also be omitted. // // Take all of the explicitly-specified arguments and put them into the - // set of deduced template arguments. + // set of deduced template arguments. Deduced.reserve(TemplateParams->size()); for (unsigned I = 0, N = ExplicitArgumentList->size(); I != N; ++I) - Deduced.push_back(ExplicitArgumentList->get(I)); - + Deduced.push_back(ExplicitArgumentList->get(I)); + return TDK_Success; } -/// \brief Finish template argument deduction for a function template, +/// \brief Finish template argument deduction for a function template, /// checking the deduced template arguments for completeness and forming /// the function template specialization. -Sema::TemplateDeductionResult +Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, llvm::SmallVectorImpl<TemplateArgument> &Deduced, FunctionDecl *&Specialization, TemplateDeductionInfo &Info) { TemplateParameterList *TemplateParams = FunctionTemplate->getTemplateParameters(); - + // C++ [temp.deduct.type]p2: // [...] or if any template argument remains neither deduced nor // explicitly specified, template argument deduction fails. @@ -1191,28 +1191,28 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, const_cast<Decl *>(TemplateParams->getParam(I))); return TDK_Incomplete; } - + Builder.Append(Deduced[I]); } - + // Form the template argument list from the deduced template arguments. - TemplateArgumentList *DeducedArgumentList + TemplateArgumentList *DeducedArgumentList = new (Context) TemplateArgumentList(Context, Builder, /*TakeArgs=*/true); Info.reset(DeducedArgumentList); - + // Template argument deduction for function templates in a SFINAE context. // Trap any errors that might occur. - SFINAETrap Trap(*this); - + SFINAETrap Trap(*this); + // Enter a new template instantiation context while we instantiate the // actual function declaration. - InstantiatingTemplate Inst(*this, FunctionTemplate->getLocation(), + InstantiatingTemplate Inst(*this, FunctionTemplate->getLocation(), FunctionTemplate, Deduced.data(), Deduced.size(), ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution); if (Inst) - return TDK_InstantiationDepth; - - // Substitute the deduced template arguments into the function template + return TDK_InstantiationDepth; + + // Substitute the deduced template arguments into the function template // declaration to produce the function template specialization. Specialization = cast_or_null<FunctionDecl>( SubstDecl(FunctionTemplate->getTemplatedDecl(), @@ -1220,12 +1220,12 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, MultiLevelTemplateArgumentList(*DeducedArgumentList))); if (!Specialization) return TDK_SubstitutionFailure; - - // If the template argument list is owned by the function template + + // If the template argument list is owned by the function template // specialization, release it. if (Specialization->getTemplateSpecializationArgs() == DeducedArgumentList) Info.take(); - + // There may have been an error that did not prevent us from constructing a // declaration. Mark the declaration invalid and return with a substitution // failure. @@ -1233,8 +1233,8 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, Specialization->setInvalidDecl(true); return TDK_SubstitutionFailure; } - - return TDK_Success; + + return TDK_Success; } /// \brief Perform template argument deduction from a function call @@ -1243,14 +1243,14 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, /// \param FunctionTemplate the function template for which we are performing /// template argument deduction. /// -/// \param HasExplicitTemplateArgs whether any template arguments were +/// \param HasExplicitTemplateArgs whether any template arguments were /// explicitly specified. /// /// \param ExplicitTemplateArguments when @p HasExplicitTemplateArgs is true, /// the explicitly-specified template arguments. /// /// \param NumExplicitTemplateArguments when @p HasExplicitTemplateArgs is true, -/// the number of explicitly-specified template arguments in +/// the number of explicitly-specified template arguments in /// @p ExplicitTemplateArguments. This value may be zero. /// /// \param Args the function call arguments @@ -1258,7 +1258,7 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, /// \param NumArgs the number of arguments in Args /// /// \param Specialization if template argument deduction was successful, -/// this will be set to the function template specialization produced by +/// this will be set to the function template specialization produced by /// template argument deduction. /// /// \param Info the argument will be updated to provide additional information @@ -1283,14 +1283,14 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, if (NumArgs < Function->getMinRequiredArguments()) return TDK_TooFewArguments; else if (NumArgs > Function->getNumParams()) { - const FunctionProtoType *Proto + const FunctionProtoType *Proto = Function->getType()->getAsFunctionProtoType(); if (!Proto->isVariadic()) return TDK_TooManyArguments; - + CheckArgs = Function->getNumParams(); } - + // The types of the parameters from which we will perform template argument // deduction. TemplateParameterList *TemplateParams @@ -1313,25 +1313,25 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, for (unsigned I = 0; I != CheckArgs; ++I) ParamTypes.push_back(Function->getParamDecl(I)->getType()); } - + // Deduce template arguments from the function parameters. - Deduced.resize(TemplateParams->size()); + Deduced.resize(TemplateParams->size()); for (unsigned I = 0; I != CheckArgs; ++I) { QualType ParamType = ParamTypes[I]; QualType ArgType = Args[I]->getType(); - + // C++ [temp.deduct.call]p2: // If P is not a reference type: QualType CanonParamType = Context.getCanonicalType(ParamType); bool ParamWasReference = isa<ReferenceType>(CanonParamType); if (!ParamWasReference) { - // - If A is an array type, the pointer type produced by the - // array-to-pointer standard conversion (4.2) is used in place of + // - If A is an array type, the pointer type produced by the + // array-to-pointer standard conversion (4.2) is used in place of // A for type deduction; otherwise, if (ArgType->isArrayType()) ArgType = Context.getArrayDecayedType(ArgType); - // - If A is a function type, the pointer type produced by the - // function-to-pointer standard conversion (4.3) is used in place + // - If A is a function type, the pointer type produced by the + // function-to-pointer standard conversion (4.3) is used in place // of A for type deduction; otherwise, else if (ArgType->isFunctionType()) ArgType = Context.getPointerType(ArgType); @@ -1343,67 +1343,67 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, ArgType = CanonArgType.getUnqualifiedType(); } } - + // C++0x [temp.deduct.call]p3: // If P is a cv-qualified type, the top level cv-qualifiers of P’s type - // are ignored for type deduction. + // are ignored for type deduction. if (CanonParamType.getCVRQualifiers()) ParamType = CanonParamType.getUnqualifiedType(); if (const ReferenceType *ParamRefType = ParamType->getAs<ReferenceType>()) { - // [...] If P is a reference type, the type referred to by P is used - // for type deduction. + // [...] If P is a reference type, the type referred to by P is used + // for type deduction. ParamType = ParamRefType->getPointeeType(); - - // [...] If P is of the form T&&, where T is a template parameter, and - // the argument is an lvalue, the type A& is used in place of A for + + // [...] If P is of the form T&&, where T is a template parameter, and + // the argument is an lvalue, the type A& is used in place of A for // type deduction. if (isa<RValueReferenceType>(ParamRefType) && ParamRefType->getAsTemplateTypeParmType() && Args[I]->isLvalue(Context) == Expr::LV_Valid) ArgType = Context.getLValueReferenceType(ArgType); } - + // C++0x [temp.deduct.call]p4: // In general, the deduction process attempts to find template argument // values that will make the deduced A identical to A (after the type A // is transformed as described above). [...] unsigned TDF = 0; - + // - If the original P is a reference type, the deduced A (i.e., the // type referred to by the reference) can be more cv-qualified than // the transformed A. if (ParamWasReference) TDF |= TDF_ParamWithReferenceType; - // - The transformed A can be another pointer or pointer to member - // type that can be converted to the deduced A via a qualification + // - The transformed A can be another pointer or pointer to member + // type that can be converted to the deduced A via a qualification // conversion (4.4). if (ArgType->isPointerType() || ArgType->isMemberPointerType()) TDF |= TDF_IgnoreQualifiers; - // - If P is a class and P has the form simple-template-id, then the + // - If P is a class and P has the form simple-template-id, then the // transformed A can be a derived class of the deduced A. Likewise, // if P is a pointer to a class of the form simple-template-id, the // transformed A can be a pointer to a derived class pointed to by // the deduced A. if (isSimpleTemplateIdType(ParamType) || - (isa<PointerType>(ParamType) && + (isa<PointerType>(ParamType) && isSimpleTemplateIdType( ParamType->getAs<PointerType>()->getPointeeType()))) TDF |= TDF_DerivedClass; - + if (TemplateDeductionResult Result = ::DeduceTemplateArguments(Context, TemplateParams, ParamType, ArgType, Info, Deduced, TDF)) return Result; - + // FIXME: C++0x [temp.deduct.call] paragraphs 6-9 deal with function - // pointer parameters. + // pointer parameters. // FIXME: we need to check that the deduced A is the same as A, // modulo the various allowed differences. } - return FinishTemplateArgumentDeduction(FunctionTemplate, Deduced, + return FinishTemplateArgumentDeduction(FunctionTemplate, Deduced, Specialization, Info); } @@ -1413,14 +1413,14 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, /// \param FunctionTemplate the function template for which we are performing /// template argument deduction. /// -/// \param HasExplicitTemplateArgs whether any template arguments were +/// \param HasExplicitTemplateArgs whether any template arguments were /// explicitly specified. /// /// \param ExplicitTemplateArguments when @p HasExplicitTemplateArgs is true, /// the explicitly-specified template arguments. /// /// \param NumExplicitTemplateArguments when @p HasExplicitTemplateArgs is true, -/// the number of explicitly-specified template arguments in +/// the number of explicitly-specified template arguments in /// @p ExplicitTemplateArguments. This value may be zero. /// /// \param ArgFunctionType the function type that will be used as the @@ -1428,7 +1428,7 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, /// function template's function type. /// /// \param Specialization if template argument deduction was successful, -/// this will be set to the function template specialization produced by +/// this will be set to the function template specialization produced by /// template argument deduction. /// /// \param Info the argument will be updated to provide additional information @@ -1447,33 +1447,33 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, TemplateParameterList *TemplateParams = FunctionTemplate->getTemplateParameters(); QualType FunctionType = Function->getType(); - + // Substitute any explicit template arguments. llvm::SmallVector<TemplateArgument, 4> Deduced; llvm::SmallVector<QualType, 4> ParamTypes; if (HasExplicitTemplateArgs) { - if (TemplateDeductionResult Result - = SubstituteExplicitTemplateArguments(FunctionTemplate, - ExplicitTemplateArgs, + if (TemplateDeductionResult Result + = SubstituteExplicitTemplateArguments(FunctionTemplate, + ExplicitTemplateArgs, NumExplicitTemplateArgs, - Deduced, ParamTypes, + Deduced, ParamTypes, &FunctionType, Info)) return Result; } // Template argument deduction for function templates in a SFINAE context. // Trap any errors that might occur. - SFINAETrap Trap(*this); - + SFINAETrap Trap(*this); + // Deduce template arguments from the function type. - Deduced.resize(TemplateParams->size()); + Deduced.resize(TemplateParams->size()); if (TemplateDeductionResult Result = ::DeduceTemplateArguments(Context, TemplateParams, - FunctionType, ArgFunctionType, Info, + FunctionType, ArgFunctionType, Info, Deduced, 0)) return Result; - - return FinishTemplateArgumentDeduction(FunctionTemplate, Deduced, + + return FinishTemplateArgumentDeduction(FunctionTemplate, Deduced, Specialization, Info); } @@ -1485,7 +1485,7 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, QualType ToType, CXXConversionDecl *&Specialization, TemplateDeductionInfo &Info) { - CXXConversionDecl *Conv + CXXConversionDecl *Conv = cast<CXXConversionDecl>(FunctionTemplate->getTemplatedDecl()); QualType FromType = Conv->getConversionType(); @@ -1506,12 +1506,12 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, A = ARef->getPointeeType(); // C++ [temp.deduct.conv]p2: // - // If A is not a reference type: + // If A is not a reference type: else { assert(!A->isReferenceType() && "Reference types were handled above"); // - If P is an array type, the pointer type produced by the - // array-to-pointer standard conversion (4.2) is used in place + // array-to-pointer standard conversion (4.2) is used in place // of P for type deduction; otherwise, if (P->isArrayType()) P = Context.getArrayDecayedType(P); @@ -1533,7 +1533,7 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, // Template argument deduction for function templates in a SFINAE context. // Trap any errors that might occur. - SFINAETrap Trap(*this); + SFINAETrap Trap(*this); // C++ [temp.deduct.conv]p1: // Template argument deduction is done by comparing the return @@ -1543,7 +1543,7 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, TemplateParameterList *TemplateParams = FunctionTemplate->getTemplateParameters(); llvm::SmallVector<TemplateArgument, 4> Deduced; - Deduced.resize(TemplateParams->size()); + Deduced.resize(TemplateParams->size()); // C++0x [temp.deduct.conv]p4: // In general, the deduction process attempts to find template @@ -1572,7 +1572,7 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, // FIXME: we need to check that the deduced A is the same as A, // modulo the various allowed differences. - + // Finish template argument deduction. FunctionDecl *Spec = 0; TemplateDeductionResult Result @@ -1591,7 +1591,7 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, /// \param isCallContext whether partial ordering is being performed /// for a function call (which ignores the return types of the /// functions). -/// +/// /// \returns the more specialization function template. If neither /// template is more specialized, returns NULL. FunctionTemplateDecl * @@ -1613,21 +1613,21 @@ Sema::getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, #endif } -static void +static void MarkDeducedTemplateParameters(Sema &SemaRef, const TemplateArgument &TemplateArg, llvm::SmallVectorImpl<bool> &Deduced); /// \brief Mark the template arguments that are deduced by the given /// expression. -static void -MarkDeducedTemplateParameters(const Expr *E, +static void +MarkDeducedTemplateParameters(const Expr *E, llvm::SmallVectorImpl<bool> &Deduced) { const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E); if (!E) return; - const NonTypeTemplateParmDecl *NTTP + const NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()); if (!NTTP) return; @@ -1637,7 +1637,7 @@ MarkDeducedTemplateParameters(const Expr *E, /// \brief Mark the template parameters that are deduced by the given /// type. -static void +static void MarkDeducedTemplateParameters(Sema &SemaRef, QualType T, llvm::SmallVectorImpl<bool> &Deduced) { // Non-dependent types have nothing deducible @@ -1647,7 +1647,7 @@ MarkDeducedTemplateParameters(Sema &SemaRef, QualType T, T = SemaRef.Context.getCanonicalType(T); switch (T->getTypeClass()) { case Type::ExtQual: - MarkDeducedTemplateParameters(SemaRef, + MarkDeducedTemplateParameters(SemaRef, QualType(cast<ExtQualType>(T)->getBaseType(), 0), Deduced); break; @@ -1719,13 +1719,13 @@ MarkDeducedTemplateParameters(Sema &SemaRef, QualType T, break; case Type::TemplateSpecialization: { - const TemplateSpecializationType *Spec + const TemplateSpecializationType *Spec = cast<TemplateSpecializationType>(T); if (TemplateDecl *Template = Spec->getTemplateName().getAsTemplateDecl()) - if (TemplateTemplateParmDecl *TTP + if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(Template)) Deduced[TTP->getIndex()] = true; - + for (unsigned I = 0, N = Spec->getNumArgs(); I != N; ++I) MarkDeducedTemplateParameters(SemaRef, Spec->getArg(I), Deduced); @@ -1754,7 +1754,7 @@ MarkDeducedTemplateParameters(Sema &SemaRef, QualType T, /// \brief Mark the template parameters that are deduced by this /// template argument. -static void +static void MarkDeducedTemplateParameters(Sema &SemaRef, const TemplateArgument &TemplateArg, llvm::SmallVectorImpl<bool> &Deduced) { @@ -1762,13 +1762,13 @@ MarkDeducedTemplateParameters(Sema &SemaRef, case TemplateArgument::Null: case TemplateArgument::Integral: break; - + case TemplateArgument::Type: MarkDeducedTemplateParameters(SemaRef, TemplateArg.getAsType(), Deduced); break; case TemplateArgument::Declaration: - if (TemplateTemplateParmDecl *TTP + if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(TemplateArg.getAsDecl())) Deduced[TTP->getIndex()] = true; break; @@ -1791,7 +1791,7 @@ MarkDeducedTemplateParameters(Sema &SemaRef, /// \param Deduced a bit vector whose elements will be set to \c true /// to indicate when the corresponding template parameter will be /// deduced. -void +void Sema::MarkDeducedTemplateParameters(const TemplateArgumentList &TemplateArgs, llvm::SmallVectorImpl<bool> &Deduced) { for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 97b58adb06..912b965507 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -32,22 +32,22 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(NamedDecl *D) { // Accumulate the set of template argument lists in this structure. MultiLevelTemplateArgumentList Result; - + DeclContext *Ctx = dyn_cast<DeclContext>(D); if (!Ctx) Ctx = D->getDeclContext(); - + while (!Ctx->isFileContext()) { // Add template arguments from a class template instantiation. - if (ClassTemplateSpecializationDecl *Spec + if (ClassTemplateSpecializationDecl *Spec = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) { // We're done when we hit an explicit specialization. if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization) break; - + Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); - } - + } + // Add template arguments from a function template specialization. else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { // FIXME: Check whether this is an explicit specialization. @@ -67,7 +67,7 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D) { Ctx = Ctx->getParent(); } - + return Result; } @@ -92,7 +92,7 @@ InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, } } -Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, +Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template, const TemplateArgument *TemplateArgs, @@ -104,7 +104,7 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, InstantiationRange); if (!Invalid) { ActiveTemplateInstantiation Inst; - Inst.Kind + Inst.Kind = ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation; Inst.PointOfInstantiation = PointOfInstantiation; Inst.Entity = reinterpret_cast<uintptr_t>(Template); @@ -116,7 +116,7 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, } } -Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, +Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionTemplateDecl *FunctionTemplate, const TemplateArgument *TemplateArgs, @@ -124,7 +124,7 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, ActiveTemplateInstantiation::InstantiationKind Kind, SourceRange InstantiationRange) : SemaRef(SemaRef) { - + Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); if (!Invalid) { @@ -140,7 +140,7 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, } } -Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, +Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgument *TemplateArgs, @@ -152,7 +152,7 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, InstantiationRange); if (!Invalid) { ActiveTemplateInstantiation Inst; - Inst.Kind + Inst.Kind = ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution; Inst.PointOfInstantiation = PointOfInstantiation; Inst.Entity = reinterpret_cast<uintptr_t>(PartialSpec); @@ -164,14 +164,14 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, } } -Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, +Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantation, ParmVarDecl *Param, const TemplateArgument *TemplateArgs, unsigned NumTemplateArgs, SourceRange InstantiationRange) : SemaRef(SemaRef) { - + Invalid = CheckInstantiationDepth(PointOfInstantation, InstantiationRange); if (!Invalid) { @@ -198,11 +198,11 @@ void Sema::InstantiatingTemplate::Clear() { bool Sema::InstantiatingTemplate::CheckInstantiationDepth( SourceLocation PointOfInstantiation, SourceRange InstantiationRange) { - if (SemaRef.ActiveTemplateInstantiations.size() + if (SemaRef.ActiveTemplateInstantiations.size() <= SemaRef.getLangOptions().InstantiationDepth) return false; - SemaRef.Diag(PointOfInstantiation, + SemaRef.Diag(PointOfInstantiation, diag::err_template_recursion_depth_exceeded) << SemaRef.getLangOptions().InstantiationDepth << InstantiationRange; @@ -227,7 +227,7 @@ void Sema::PrintInstantiationStack() { unsigned DiagID = diag::note_template_member_class_here; if (isa<ClassTemplateSpecializationDecl>(Record)) DiagID = diag::note_template_class_instantiation_here; - Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), + Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), DiagID) << Context.getTypeDeclType(Record) << Active->InstantiationRange; @@ -237,7 +237,7 @@ void Sema::PrintInstantiationStack() { DiagID = diag::note_function_template_spec_here; else DiagID = diag::note_template_member_function_here; - Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), + Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), DiagID) << Function << Active->InstantiationRange; @@ -254,7 +254,7 @@ void Sema::PrintInstantiationStack() { TemplateDecl *Template = cast<TemplateDecl>((Decl *)Active->Entity); std::string TemplateArgsStr = TemplateSpecializationType::PrintTemplateArgumentList( - Active->TemplateArgs, + Active->TemplateArgs, Active->NumTemplateArgs, Context.PrintingPolicy); Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), @@ -265,14 +265,14 @@ void Sema::PrintInstantiationStack() { } case ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution: { - FunctionTemplateDecl *FnTmpl + FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>((Decl *)Active->Entity); Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), diag::note_explicit_template_arg_substitution_here) << FnTmpl << Active->InstantiationRange; break; } - + case ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution: if (ClassTemplatePartialSpecializationDecl *PartialSpec = dyn_cast<ClassTemplatePartialSpecializationDecl>( @@ -293,10 +293,10 @@ void Sema::PrintInstantiationStack() { case ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation: { ParmVarDecl *Param = cast<ParmVarDecl>((Decl *)Active->Entity); FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext()); - + std::string TemplateArgsStr = TemplateSpecializationType::PrintTemplateArgumentList( - Active->TemplateArgs, + Active->TemplateArgs, Active->NumTemplateArgs, Context.PrintingPolicy); Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), @@ -305,7 +305,7 @@ void Sema::PrintInstantiationStack() { << Active->InstantiationRange; break; } - + } } } @@ -324,12 +324,12 @@ bool Sema::isSFINAEContext() const { // This is a template instantiation, so there is no SFINAE. return false; - + case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: // A default template argument instantiation may or may not be a // SFINAE context; look further up the stack. break; - + case ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution: case ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution: // We're either substitution explicitly-specified template arguments @@ -345,24 +345,23 @@ bool Sema::isSFINAEContext() const { // Template Instantiation for Types //===----------------------------------------------------------------------===/ namespace { - class VISIBILITY_HIDDEN TemplateInstantiator - : public TreeTransform<TemplateInstantiator> - { + class VISIBILITY_HIDDEN TemplateInstantiator + : public TreeTransform<TemplateInstantiator> { const MultiLevelTemplateArgumentList &TemplateArgs; SourceLocation Loc; DeclarationName Entity; public: typedef TreeTransform<TemplateInstantiator> inherited; - - TemplateInstantiator(Sema &SemaRef, + + TemplateInstantiator(Sema &SemaRef, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, - DeclarationName Entity) - : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), + DeclarationName Entity) + : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), Entity(Entity) { } - /// \brief Determine whether the given type \p T has already been + /// \brief Determine whether the given type \p T has already been /// transformed. /// /// For the purposes of template instantiation, a type has already been @@ -370,31 +369,31 @@ namespace { bool AlreadyTransformed(QualType T) { return T.isNull() || !T->isDependentType(); } - + /// \brief Returns the location of the entity being instantiated, if known. SourceLocation getBaseLocation() { return Loc; } - + /// \brief Returns the name of the entity being instantiated, if any. DeclarationName getBaseEntity() { return Entity; } - + /// \brief Transform the given declaration by instantiating a reference to /// this declaration. Decl *TransformDecl(Decl *D); - /// \brief Transform the definition of the given declaration by + /// \brief Transform the definition of the given declaration by /// instantiating it. Decl *TransformDefinition(Decl *D); - + /// \brief Rebuild the exception declaration and register the declaration /// as an instantiated local. - VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, + VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, DeclaratorInfo *Declarator, IdentifierInfo *Name, SourceLocation Loc, SourceRange TypeRange); - + Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E); - - /// \brief Transforms a template type parameter type by performing + + /// \brief Transforms a template type parameter type by performing /// substitution of the corresponding template type argument. QualType TransformTemplateTypeParmType(const TemplateTypeParmType *T); }; @@ -403,28 +402,28 @@ namespace { Decl *TemplateInstantiator::TransformDecl(Decl *D) { if (!D) return 0; - + if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { if (TTP->getDepth() < TemplateArgs.getNumLevels()) { assert(TemplateArgs(TTP->getDepth(), TTP->getPosition()).getAsDecl() && "Wrong kind of template template argument"); - return cast<TemplateDecl>(TemplateArgs(TTP->getDepth(), + return cast<TemplateDecl>(TemplateArgs(TTP->getDepth(), TTP->getPosition()).getAsDecl()); } - - // If the corresponding template argument is NULL or non-existent, it's - // because we are performing instantiation from explicitly-specified + + // If the corresponding template argument is NULL or non-existent, it's + // because we are performing instantiation from explicitly-specified // template arguments in a function template, but there were some // arguments left unspecified. - if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), + if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), TTP->getPosition())) return D; - + // FIXME: Implement depth reduction of template template parameters - assert(false && + assert(false && "Reducing depth of template template parameters is not yet implemented"); } - + return SemaRef.FindInstantiatedDecl(cast<NamedDecl>(D)); } @@ -432,17 +431,17 @@ Decl *TemplateInstantiator::TransformDefinition(Decl *D) { Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); if (!Inst) return 0; - + getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); return Inst; } VarDecl * TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, - QualType T, + QualType T, DeclaratorInfo *Declarator, IdentifierInfo *Name, - SourceLocation Loc, + SourceLocation Loc, SourceRange TypeRange) { VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, T, Declarator, Name, Loc, TypeRange); @@ -451,7 +450,7 @@ TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, return Var; } -Sema::OwningExprResult +Sema::OwningExprResult TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { // FIXME: Clean this up a bit NamedDecl *D = E->getDecl(); @@ -460,91 +459,91 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { assert(false && "Cannot reduce non-type template parameter depth yet"); return getSema().ExprError(); } - - // If the corresponding template argument is NULL or non-existent, it's - // because we are performing instantiation from explicitly-specified + + // If the corresponding template argument is NULL or non-existent, it's + // because we are performing instantiation from explicitly-specified // template arguments in a function template, but there were some // arguments left unspecified. - if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), + if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), NTTP->getPosition())) return SemaRef.Owned(E->Retain()); - - const TemplateArgument &Arg = TemplateArgs(NTTP->getDepth(), + + const TemplateArgument &Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition()); - + // The template argument itself might be an expression, in which // case we just return that expression. if (Arg.getKind() == TemplateArgument::Expression) return SemaRef.Owned(Arg.getAsExpr()->Retain()); - + if (Arg.getKind() == TemplateArgument::Declaration) { ValueDecl *VD = cast<ValueDecl>(Arg.getAsDecl()); - + VD = cast_or_null<ValueDecl>(getSema().FindInstantiatedDecl(VD)); if (!VD) return SemaRef.ExprError(); - - return SemaRef.BuildDeclRefExpr(VD, VD->getType(), E->getLocation(), + + return SemaRef.BuildDeclRefExpr(VD, VD->getType(), E->getLocation(), /*FIXME:*/false, /*FIXME:*/false); } - + assert(Arg.getKind() == TemplateArgument::Integral); QualType T = Arg.getIntegralType(); if (T->isCharType() || T->isWideCharType()) return SemaRef.Owned(new (SemaRef.Context) CharacterLiteral( Arg.getAsIntegral()->getZExtValue(), T->isWideCharType(), - T, + T, E->getSourceRange().getBegin())); if (T->isBooleanType()) return SemaRef.Owned(new (SemaRef.Context) CXXBoolLiteralExpr( Arg.getAsIntegral()->getBoolValue(), - T, + T, E->getSourceRange().getBegin())); - + assert(Arg.getAsIntegral()->getBitWidth() == SemaRef.Context.getIntWidth(T)); return SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( *Arg.getAsIntegral(), - T, + T, E->getSourceRange().getBegin())); } - + NamedDecl *InstD = SemaRef.FindInstantiatedDecl(D); if (!InstD) return SemaRef.ExprError(); - + // If we instantiated an UnresolvedUsingDecl and got back an UsingDecl, - // we need to get the underlying decl. + // we need to get the underlying decl. // FIXME: Is this correct? Maybe FindInstantiatedDecl should do this? InstD = InstD->getUnderlyingDecl(); - + // FIXME: nested-name-specifier for QualifiedDeclRefExpr - return SemaRef.BuildDeclarationNameExpr(E->getLocation(), InstD, + return SemaRef.BuildDeclarationNameExpr(E->getLocation(), InstD, /*FIXME:*/false, - /*FIXME:*/0, - /*FIXME:*/false); + /*FIXME:*/0, + /*FIXME:*/false); } -QualType +QualType TemplateInstantiator::TransformTemplateTypeParmType( const TemplateTypeParmType *T) { if (T->getDepth() < TemplateArgs.getNumLevels()) { // Replace the template type parameter with its corresponding // template argument. - - // If the corresponding template argument is NULL or doesn't exist, it's - // because we are performing instantiation from explicitly-specified - // template arguments in a function template class, but there were some + + // If the corresponding template argument is NULL or doesn't exist, it's + // because we are performing instantiation from explicitly-specified + // template arguments in a function template class, but there were some // arguments left unspecified. if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) return QualType(T, 0); - - assert(TemplateArgs(T->getDepth(), T->getIndex()).getKind() + + assert(TemplateArgs(T->getDepth(), T->getIndex()).getKind() == TemplateArgument::Type && "Template argument kind mismatch"); return TemplateArgs(T->getDepth(), T->getIndex()).getAsType(); - } + } // The template type parameter comes from an inner template (e.g., // the template parameter list of a member template inside the @@ -584,7 +583,7 @@ TemplateInstantiator::TransformTemplateTypeParmType( /// /// \returns If the instantiation succeeds, the instantiated /// type. Otherwise, produces diagnostics and returns a NULL type. -QualType Sema::SubstType(QualType T, +QualType Sema::SubstType(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity) { assert(!ActiveTemplateInstantiations.empty() && @@ -605,13 +604,13 @@ QualType Sema::SubstType(QualType T, /// Produces a diagnostic and returns true on error, returns false and /// attaches the instantiated base classes to the class template /// specialization if successful. -bool +bool Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs) { bool Invalid = false; llvm::SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; - for (ClassTemplateSpecializationDecl::base_class_iterator + for (ClassTemplateSpecializationDecl::base_class_iterator Base = Pattern->bases_begin(), BaseEnd = Pattern->bases_end(); Base != BaseEnd; ++Base) { if (!Base->getType()->isDependentType()) { @@ -619,8 +618,8 @@ Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, continue; } - QualType BaseType = SubstType(Base->getType(), - TemplateArgs, + QualType BaseType = SubstType(Base->getType(), + TemplateArgs, Base->getSourceRange().getBegin(), DeclarationName()); if (BaseType.isNull()) { @@ -679,7 +678,7 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, bool Complain) { bool Invalid = false; - CXXRecordDecl *PatternDef + CXXRecordDecl *PatternDef = cast_or_null<CXXRecordDecl>(Pattern->getDefinition(Context)); if (!PatternDef) { if (!Complain) { @@ -717,7 +716,7 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, llvm::SmallVector<DeclPtrTy, 4> Fields; for (RecordDecl::decl_iterator Member = Pattern->decls_begin(), - MemberEnd = Pattern->decls_end(); + MemberEnd = Pattern->decls_end(); Member != MemberEnd; ++Member) { Decl *NewMember = SubstDecl(*Member, Instantiation, TemplateArgs); if (NewMember) { @@ -758,7 +757,7 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, return Invalid; } -bool +bool Sema::InstantiateClassTemplateSpecialization( ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, @@ -787,14 +786,14 @@ Sema::InstantiateClassTemplateSpecialization( typedef std::pair<ClassTemplatePartialSpecializationDecl *, TemplateArgumentList *> MatchResult; llvm::SmallVector<MatchResult, 4> Matched; - for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator + for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator Partial = Template->getPartialSpecializations().begin(), PartialEnd = Template->getPartialSpecializations().end(); Partial != PartialEnd; ++Partial) { TemplateDeductionInfo Info(Context); if (TemplateDeductionResult Result - = DeduceTemplateArguments(&*Partial, + = DeduceTemplateArguments(&*Partial, ClassTemplateSpec->getTemplateArgs(), Info)) { // FIXME: Store the failed-deduction information for use in @@ -820,14 +819,14 @@ Sema::InstantiateClassTemplateSpecialization( // ambiguous and the program is ill-formed. // FIXME: Implement partial ordering of class template partial // specializations. - Diag(ClassTemplateSpec->getLocation(), + Diag(ClassTemplateSpec->getLocation(), diag::unsup_template_partial_spec_ordering); // FIXME: Temporary hack to fall back to the primary template ClassTemplateDecl *OrigTemplate = Template; while (OrigTemplate->getInstantiatedFromMemberTemplate()) OrigTemplate = OrigTemplate->getInstantiatedFromMemberTemplate(); - + Pattern = OrigTemplate->getTemplatedDecl(); } else { // -- If no matches are found, the instantiation is generated @@ -835,7 +834,7 @@ Sema::InstantiateClassTemplateSpecialization( ClassTemplateDecl *OrigTemplate = Template; while (OrigTemplate->getInstantiatedFromMemberTemplate()) OrigTemplate = OrigTemplate->getInstantiatedFromMemberTemplate(); - + Pattern = OrigTemplate->getTemplatedDecl(); } @@ -843,17 +842,17 @@ Sema::InstantiateClassTemplateSpecialization( ClassTemplateSpec->setSpecializationKind(TSK); bool Result = InstantiateClass(ClassTemplateSpec->getLocation(), - ClassTemplateSpec, Pattern, + ClassTemplateSpec, Pattern, getTemplateInstantiationArgs(ClassTemplateSpec), TSK, Complain); - + for (unsigned I = 0, N = Matched.size(); I != N; ++I) { // FIXME: Implement TemplateArgumentList::Destroy! // if (Matched[I].first != Pattern) // Matched[I].second->Destroy(Context); } - + return Result; } @@ -877,7 +876,7 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, InstantiateStaticDataMemberDefinition(PointOfInstantiation, Var); } else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(*D)) { if (!Record->isInjectedClassName() && !Record->getDefinition(Context)) { - assert(Record->getInstantiatedFromMemberClass() && + assert(Record->getInstantiatedFromMemberClass() && "Missing instantiated-from-template information"); InstantiateClass(PointOfInstantiation, Record, Record->getInstantiatedFromMemberClass(), @@ -891,7 +890,7 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, /// \brief Instantiate the definitions of all of the members of the /// given class template specialization, which was named as part of an /// explicit instantiation. -void +void Sema::InstantiateClassTemplateSpecializationMembers( SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, @@ -909,7 +908,7 @@ Sema::InstantiateClassTemplateSpecializationMembers( TSK); } -Sema::OwningStmtResult +Sema::OwningStmtResult Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) { if (!S) return Owned(S); @@ -920,11 +919,11 @@ Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) { return Instantiator.TransformStmt(S); } -Sema::OwningExprResult +Sema::OwningExprResult Sema::SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs) { if (!E) return Owned(E); - + TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(), DeclarationName()); @@ -949,7 +948,7 @@ Sema::SubstTemplateName(TemplateName Name, SourceLocation Loc, return Instantiator.TransformTemplateName(Name); } -TemplateArgument Sema::Subst(TemplateArgument Arg, +TemplateArgument Sema::Subst(TemplateArgument Arg, const MultiLevelTemplateArgumentList &TemplateArgs) { TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(), DeclarationName()); diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index b63fc400a5..f0597be879 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -22,19 +22,19 @@ using namespace clang; namespace { - class VISIBILITY_HIDDEN TemplateDeclInstantiator + class VISIBILITY_HIDDEN TemplateDeclInstantiator : public DeclVisitor<TemplateDeclInstantiator, Decl *> { Sema &SemaRef; DeclContext *Owner; const MultiLevelTemplateArgumentList &TemplateArgs; - + public: typedef Sema::OwningExprResult OwningExprResult; TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs) : SemaRef(SemaRef), Owner(Owner), TemplateArgs(TemplateArgs) { } - + // FIXME: Once we get closer to completion, replace these manually-written // declarations with automatically-generated ones from // clang/AST/DeclNodes.def. @@ -60,9 +60,9 @@ namespace { Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); Decl *VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D); - + // Base case. FIXME: Remove once we can instantiate everything. - Decl *VisitDecl(Decl *) { + Decl *VisitDecl(Decl *) { assert(false && "Template instantiation of unknown declaration kind!"); return 0; } @@ -98,14 +98,14 @@ Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) { bool Invalid = false; QualType T = D->getUnderlyingType(); if (T->isDependentType()) { - T = SemaRef.SubstType(T, TemplateArgs, + T = SemaRef.SubstType(T, TemplateArgs, D->getLocation(), D->getDeclName()); if (T.isNull()) { Invalid = true; T = SemaRef.Context.IntTy; } } - + // Create the new typedef TypedefDecl *Typedef = TypedefDecl::Create(SemaRef.Context, Owner, D->getLocation(), @@ -114,7 +114,7 @@ Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) { Typedef->setInvalidDecl(); Owner->addDecl(Typedef); - + return Typedef; } @@ -134,32 +134,32 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { Var->setThreadSpecified(D->isThreadSpecified()); Var->setCXXDirectInitializer(D->hasCXXDirectInitializer()); Var->setDeclaredInCondition(D->isDeclaredInCondition()); - - // If we are instantiating a static data member defined + + // If we are instantiating a static data member defined // out-of-line, the instantiation will have the same lexical // context (which will be a namespace scope) as the template. if (D->isOutOfLine()) Var->setLexicalDeclContext(D->getLexicalDeclContext()); - + // FIXME: In theory, we could have a previous declaration for variables that // are not static data members. bool Redeclaration = false; SemaRef.CheckVariableDeclaration(Var, 0, Redeclaration); - + if (D->isOutOfLine()) { D->getLexicalDeclContext()->addDecl(Var); Owner->makeDeclVisibleInContext(Var); } else { Owner->addDecl(Var); } - + if (D->getInit()) { - OwningExprResult Init + OwningExprResult Init = SemaRef.SubstExpr(D->getInit(), TemplateArgs); if (Init.isInvalid()) Var->setInvalidDecl(); else if (ParenListExpr *PLE = dyn_cast<ParenListExpr>((Expr *)Init.get())) { - // FIXME: We're faking all of the comma locations, which is suboptimal. + // FIXME: We're faking all of the comma locations, which is suboptimal. // Do we even need these comma locations? llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; if (PLE->getNumExprs() > 0) { @@ -171,16 +171,16 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { } PLE->getExpr(PLE->getNumExprs() - 1)->Retain(); } - + // Add the direct initializer to the declaration. SemaRef.AddCXXDirectInitializerToDecl(Sema::DeclPtrTy::make(Var), - PLE->getLParenLoc(), + PLE->getLParenLoc(), Sema::MultiExprArg(SemaRef, (void**)PLE->getExprs(), PLE->getNumExprs()), FakeCommaLocs.data(), PLE->getRParenLoc()); - + // When Init is destroyed, it will destroy the instantiated ParenListExpr; // we've explicitly retained all of its subexpressions already. } else @@ -193,7 +193,7 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { // which they were instantiated. if (Var->isStaticDataMember()) SemaRef.Context.setInstantiatedFromStaticDataMember(Var, D); - + return Var; } @@ -223,7 +223,7 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { else if (BitWidth) { // The bit-width expression is not potentially evaluated. EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); - + OwningExprResult InstantiatedBitWidth = SemaRef.SubstExpr(BitWidth, TemplateArgs); if (InstantiatedBitWidth.isInvalid()) { @@ -235,7 +235,7 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(), T, D->getDeclaratorInfo(), - cast<RecordDecl>(Owner), + cast<RecordDecl>(Owner), D->getLocation(), D->isMutable(), BitWidth, @@ -244,15 +244,15 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { 0); if (!Field) return 0; - + if (Invalid) Field->setInvalidDecl(); - + if (!Field->getDeclName()) { // Keep track of where this decl came from. SemaRef.Context.setInstantiatedFromUnnamedFieldDecl(Field, D); } - + Field->setImplicit(D->isImplicit()); Owner->addDecl(Field); @@ -282,7 +282,7 @@ Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) { FU = cast<NamedDecl>(NewND); } - + FriendDecl *FD = FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(), FU, D->getFriendLoc()); @@ -293,10 +293,10 @@ Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) { Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) { Expr *AssertExpr = D->getAssertExpr(); - + // The expression in a static assertion is not potentially evaluated. EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); - + OwningExprResult InstantiatedAssertExpr = SemaRef.SubstExpr(AssertExpr, TemplateArgs); if (InstantiatedAssertExpr.isInvalid()) @@ -304,15 +304,15 @@ Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) { OwningExprResult Message(SemaRef, D->getMessage()); D->getMessage()->Retain(); - Decl *StaticAssert - = SemaRef.ActOnStaticAssertDeclaration(D->getLocation(), + Decl *StaticAssert + = SemaRef.ActOnStaticAssertDeclaration(D->getLocation(), move(InstantiatedAssertExpr), move(Message)).getAs<Decl>(); return StaticAssert; } Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { - EnumDecl *Enum = EnumDecl::Create(SemaRef.Context, Owner, + EnumDecl *Enum = EnumDecl::Create(SemaRef.Context, Owner, D->getLocation(), D->getIdentifier(), D->getTagKeywordLoc(), /*PrevDecl=*/0); @@ -331,9 +331,9 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { OwningExprResult Value = SemaRef.Owned((Expr *)0); if (Expr *UninstValue = EC->getInitExpr()) { // The enumerator's value expression is not potentially evaluated. - EnterExpressionEvaluationContext Unevaluated(SemaRef, + EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); - + Value = SemaRef.SubstExpr(UninstValue, TemplateArgs); } @@ -344,7 +344,7 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { isInvalid = true; } - EnumConstantDecl *EnumConst + EnumConstantDecl *EnumConst = SemaRef.CheckEnumConstant(Enum, LastEnumConst, EC->getLocation(), EC->getIdentifier(), move(Value)); @@ -361,7 +361,7 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { LastEnumConst = EnumConst; } } - + // FIXME: Fixup LBraceLoc and RBraceLoc // FIXME: Empty Scope and AttributeList (required to handle attribute packed). SemaRef.ActOnEnumBody(Enum->getLocation(), SourceLocation(), SourceLocation(), @@ -380,7 +380,7 @@ Decl *TemplateDeclInstantiator::VisitEnumConstantDecl(EnumConstantDecl *D) { Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { TemplateParameterList *TempParams = D->getTemplateParameters(); TemplateParameterList *InstParams = SubstTemplateParams(TempParams); - if (!InstParams) + if (!InstParams) return NULL; CXXRecordDecl *Pattern = D->getTemplatedDecl(); @@ -403,23 +403,23 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { Decl * TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { // FIXME: Dig out the out-of-line definition of this function template? - + TemplateParameterList *TempParams = D->getTemplateParameters(); TemplateParameterList *InstParams = SubstTemplateParams(TempParams); - if (!InstParams) + if (!InstParams) return NULL; - - // FIXME: Handle instantiation of nested function templates that aren't + + // FIXME: Handle instantiation of nested function templates that aren't // member function templates. This could happen inside a FriendDecl. assert(isa<CXXMethodDecl>(D->getTemplatedDecl())); - CXXMethodDecl *InstMethod + CXXMethodDecl *InstMethod = cast_or_null<CXXMethodDecl>( - VisitCXXMethodDecl(cast<CXXMethodDecl>(D->getTemplatedDecl()), + VisitCXXMethodDecl(cast<CXXMethodDecl>(D->getTemplatedDecl()), InstParams)); if (!InstMethod) return 0; - // Link the instantiated function template declaration to the function + // Link the instantiated function template declaration to the function // template from which it was instantiated. FunctionTemplateDecl *InstTemplate = InstMethod->getDescribedFunctionTemplate(); assert(InstTemplate && "VisitCXXMethodDecl didn't create a template!"); @@ -434,7 +434,7 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { PrevDecl = cast<CXXRecordDecl>(Owner); CXXRecordDecl *Record - = CXXRecordDecl::Create(SemaRef.Context, D->getTagKind(), Owner, + = CXXRecordDecl::Create(SemaRef.Context, D->getTagKind(), Owner, D->getLocation(), D->getIdentifier(), D->getTagKeywordLoc(), PrevDecl); Record->setImplicit(D->isImplicit()); @@ -469,22 +469,22 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D) { void *InsertPos = 0; if (FunctionTemplate) { llvm::FoldingSetNodeID ID; - FunctionTemplateSpecializationInfo::Profile(ID, + FunctionTemplateSpecializationInfo::Profile(ID, TemplateArgs.getInnermost().getFlatArgumentList(), TemplateArgs.getInnermost().flat_size(), SemaRef.Context); - - FunctionTemplateSpecializationInfo *Info - = FunctionTemplate->getSpecializations().FindNodeOrInsertPos(ID, + + FunctionTemplateSpecializationInfo *Info + = FunctionTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos); - + // If we already have a function template specialization, return it. if (Info) return Info->Function; } - + Sema::LocalInstantiationScope Scope(SemaRef); - + llvm::SmallVector<ParmVarDecl *, 4> Params; QualType T = SubstFunctionType(D, Params); if (T.isNull()) @@ -493,12 +493,12 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D) { // Build the instantiated method declaration. DeclContext *DC = SemaRef.FindInstantiatedContext(D->getDeclContext()); FunctionDecl *Function = - FunctionDecl::Create(SemaRef.Context, DC, D->getLocation(), + FunctionDecl::Create(SemaRef.Context, DC, D->getLocation(), D->getDeclName(), T, D->getDeclaratorInfo(), D->getStorageClass(), D->isInline(), D->hasWrittenPrototype()); Function->setLexicalDeclContext(Owner); - + // Attach the parameters for (unsigned P = 0; P < Params.size(); ++P) Params[P]->setOwningFunction(Function); @@ -514,10 +514,10 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D) { Function->setInstantiationOfMemberFunction(D); } - + if (InitFunctionInstantiation(Function, D)) Function->setInvalidDecl(); - + bool Redeclaration = false; bool OverloadableAttrRequired = false; NamedDecl *PrevDecl = 0; @@ -541,19 +541,19 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate(); void *InsertPos = 0; if (FunctionTemplate && !TemplateParams) { - // We are creating a function template specialization from a function - // template. Check whether there is already a function template + // We are creating a function template specialization from a function + // template. Check whether there is already a function template // specialization for this particular set of template arguments. llvm::FoldingSetNodeID ID; - FunctionTemplateSpecializationInfo::Profile(ID, + FunctionTemplateSpecializationInfo::Profile(ID, TemplateArgs.getInnermost().getFlatArgumentList(), TemplateArgs.getInnermost().flat_size(), SemaRef.Context); - - FunctionTemplateSpecializationInfo *Info - = FunctionTemplate->getSpecializations().FindNodeOrInsertPos(ID, + + FunctionTemplateSpecializationInfo *Info + = FunctionTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos); - + // If we already have a function template specialization, return it. if (Info) return Info->Function; @@ -569,17 +569,17 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, // Build the instantiated method declaration. CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner); CXXMethodDecl *Method = 0; - + DeclarationName Name = D->getDeclName(); if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { QualType ClassTy = SemaRef.Context.getTypeDeclType(Record); Name = SemaRef.Context.DeclarationNames.getCXXConstructorName( SemaRef.Context.getCanonicalType(ClassTy)); - Method = CXXConstructorDecl::Create(SemaRef.Context, Record, - Constructor->getLocation(), - Name, T, + Method = CXXConstructorDecl::Create(SemaRef.Context, Record, + Constructor->getLocation(), + Name, T, Constructor->getDeclaratorInfo(), - Constructor->isExplicit(), + Constructor->isExplicit(), Constructor->isInline(), false); } else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) { QualType ClassTy = SemaRef.Context.getTypeDeclType(Record); @@ -589,7 +589,7 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, Destructor->getLocation(), Name, T, Destructor->isInline(), false); } else if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) { - CanQualType ConvTy + CanQualType ConvTy = SemaRef.Context.getCanonicalType( T->getAsFunctionType()->getResultType()); Name = SemaRef.Context.DeclarationNames.getCXXConversionFunctionName( @@ -597,10 +597,10 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, Method = CXXConversionDecl::Create(SemaRef.Context, Record, Conversion->getLocation(), Name, T, Conversion->getDeclaratorInfo(), - Conversion->isInline(), + Conversion->isInline(), Conversion->isExplicit()); } else { - Method = CXXMethodDecl::Create(SemaRef.Context, Record, D->getLocation(), + Method = CXXMethodDecl::Create(SemaRef.Context, Record, D->getLocation(), D->getDeclName(), T, D->getDeclaratorInfo(), D->isStatic(), D->isInline()); } @@ -608,7 +608,7 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, if (TemplateParams) { // Our resulting instantiation is actually a function template, since we // are substituting only the outer template parameters. For example, given - // + // // template<typename T> // struct X { // template<typename U> void f(T, U); @@ -621,20 +621,20 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, // Build the function template itself. FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, Record, Method->getLocation(), - Method->getDeclName(), + Method->getDeclName(), TemplateParams, Method); if (D->isOutOfLine()) - FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext()); + FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext()); Method->setDescribedFunctionTemplate(FunctionTemplate); } else if (!FunctionTemplate) Method->setInstantiationOfMemberFunction(D); - // If we are instantiating a member function defined + // If we are instantiating a member function defined // out-of-line, the instantiation will have the same lexical // context (which will be a namespace scope) as the template. if (D->isOutOfLine()) Method->setLexicalDeclContext(D->getLexicalDeclContext()); - + // Attach the parameters for (unsigned P = 0; P < Params.size(); ++P) Params[P]->setOwningFunction(Method); @@ -644,11 +644,11 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, Method->setInvalidDecl(); NamedDecl *PrevDecl = 0; - + if (!FunctionTemplate || TemplateParams) { - PrevDecl = SemaRef.LookupQualifiedName(Owner, Name, + PrevDecl = SemaRef.LookupQualifiedName(Owner, Name, Sema::LookupOrdinaryName, true); - + // In C++, the previous declaration we find might be a tag type // (class or enum). In this case, the new declaration will hide the // tag type. Note that this does does not apply if we're declaring a @@ -663,7 +663,7 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, FunctionTemplate, &TemplateArgs.getInnermost(), InsertPos); - + bool Redeclaration = false; bool OverloadableAttrRequired = false; SemaRef.CheckFunctionDeclaration(Method, PrevDecl, Redeclaration, @@ -671,7 +671,7 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, if (!FunctionTemplate && (!Method->isInvalidDecl() || !PrevDecl)) Owner->addDecl(Method); - + return Method; } @@ -702,7 +702,7 @@ ParmVarDecl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) { D->getIdentifier(), T, D->getDeclaratorInfo(), D->getStorageClass(), 0); else - Param = OriginalParmVarDecl::Create(SemaRef.Context, Owner, + Param = OriginalParmVarDecl::Create(SemaRef.Context, Owner, D->getLocation(), D->getIdentifier(), T, D->getDeclaratorInfo(), OrigT, D->getStorageClass(), 0); @@ -710,7 +710,7 @@ ParmVarDecl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) { // Mark the default argument as being uninstantiated. if (Expr *Arg = D->getDefaultArg()) Param->setUninstantiatedDefaultArg(Arg); - + // Note: we don't try to instantiate function parameters until after // we've instantiated the function's type. Therefore, we don't have // to check for 'void' parameter types here. @@ -733,7 +733,7 @@ Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl( const Type* T = D->getTypeForDecl(); assert(T->isTemplateTypeParmType()); const TemplateTypeParmType *TTPT = T->getAs<TemplateTypeParmType>(); - + TemplateTypeParmDecl *Inst = TemplateTypeParmDecl::Create(SemaRef.Context, Owner, D->getLocation(), TTPT->getDepth(), TTPT->getIndex(), @@ -747,7 +747,7 @@ Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl( = SemaRef.SubstType(DefaultPattern, TemplateArgs, D->getDefaultArgumentLoc(), D->getDeclName()); - + Inst->setDefaultArgument(DefaultInst, D->getDefaultArgumentLoc(), D->defaultArgumentWasInherited() /* preserve? */); @@ -758,23 +758,23 @@ Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl( Decl * TemplateDeclInstantiator::VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D) { - NestedNameSpecifier *NNS = - SemaRef.SubstNestedNameSpecifier(D->getTargetNestedNameSpecifier(), - D->getTargetNestedNameRange(), + NestedNameSpecifier *NNS = + SemaRef.SubstNestedNameSpecifier(D->getTargetNestedNameSpecifier(), + D->getTargetNestedNameRange(), TemplateArgs); if (!NNS) return 0; - + CXXScopeSpec SS; SS.setRange(D->getTargetNestedNameRange()); SS.setScopeRep(NNS); - - NamedDecl *UD = - SemaRef.BuildUsingDeclaration(D->getLocation(), SS, - D->getTargetNameLocation(), + + NamedDecl *UD = + SemaRef.BuildUsingDeclaration(D->getLocation(), SS, + D->getTargetNameLocation(), D->getTargetName(), 0, D->isTypeName()); if (UD) - SemaRef.Context.setInstantiatedFromUnresolvedUsingDecl(cast<UsingDecl>(UD), + SemaRef.Context.setInstantiatedFromUnresolvedUsingDecl(cast<UsingDecl>(UD), D); return UD; } @@ -821,7 +821,7 @@ TemplateDeclInstantiator::SubstTemplateParams(TemplateParameterList *L) { L->getLAngleLoc(), &Params.front(), N, L->getRAngleLoc()); return InstL; -} +} /// \brief Does substitution on the type of the given function, including /// all of the function parameters. @@ -832,7 +832,7 @@ TemplateDeclInstantiator::SubstTemplateParams(TemplateParameterList *L) { /// \returns the instantiated function's type if successful, a NULL /// type if there was an error. -QualType +QualType TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, llvm::SmallVectorImpl<ParmVarDecl *> &Params) { bool InvalidDecl = false; @@ -840,14 +840,14 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, // Substitute all of the function's formal parameter types. TemplateDeclInstantiator ParamInstantiator(SemaRef, 0, TemplateArgs); llvm::SmallVector<QualType, 4> ParamTys; - for (FunctionDecl::param_iterator P = D->param_begin(), + for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end(); P != PEnd; ++P) { if (ParmVarDecl *PInst = ParamInstantiator.VisitParmVarDecl(*P)) { if (PInst->getType()->isVoidType()) { SemaRef.Diag(PInst->getLocation(), diag::err_param_with_void_type); PInst->setInvalidDecl(); - } else if (SemaRef.RequireNonAbstractType(PInst->getLocation(), + } else if (SemaRef.RequireNonAbstractType(PInst->getLocation(), PInst->getType(), diag::err_abstract_type_in_decl, Sema::AbstractParamType)) @@ -858,7 +858,7 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, if (PInst->isInvalidDecl()) InvalidDecl = true; - } else + } else InvalidDecl = true; } @@ -868,7 +868,7 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, const FunctionProtoType *Proto = D->getType()->getAsFunctionProtoType(); assert(Proto && "Missing prototype?"); - QualType ResultType + QualType ResultType = SemaRef.SubstType(Proto->getResultType(), TemplateArgs, D->getLocation(), D->getDeclName()); if (ResultType.isNull()) @@ -879,21 +879,21 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, D->getLocation(), D->getDeclName()); } -/// \brief Initializes the common fields of an instantiation function +/// \brief Initializes the common fields of an instantiation function /// declaration (New) from the corresponding fields of its template (Tmpl). /// /// \returns true if there was an error -bool -TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, +bool +TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, FunctionDecl *Tmpl) { if (Tmpl->isDeleted()) New->setDeleted(); - + // If we are performing substituting explicitly-specified template arguments // or deduced template arguments into a function template and we reach this // point, we are now past the point where SFINAE applies and have committed - // to keeping the new function template specialization. We therefore - // convert the active template instantiation for the function template + // to keeping the new function template specialization. We therefore + // convert the active template instantiation for the function template // into a template instantiation for this specific function template // specialization, which is not a SFINAE context, so that we diagnose any // further errors in the declaration itself. @@ -901,16 +901,16 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, ActiveInstType &ActiveInst = SemaRef.ActiveTemplateInstantiations.back(); if (ActiveInst.Kind == ActiveInstType::ExplicitTemplateArgumentSubstitution || ActiveInst.Kind == ActiveInstType::DeducedTemplateArgumentSubstitution) { - if (FunctionTemplateDecl *FunTmpl + if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>((Decl *)ActiveInst.Entity)) { - assert(FunTmpl->getTemplatedDecl() == Tmpl && + assert(FunTmpl->getTemplatedDecl() == Tmpl && "Deduction from the wrong function template?"); (void) FunTmpl; ActiveInst.Kind = ActiveInstType::TemplateInstantiation; ActiveInst.Entity = reinterpret_cast<uintptr_t>(New); } } - + return false; } @@ -919,12 +919,12 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, /// (Tmpl). /// /// \returns true if there was an error -bool -TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New, +bool +TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New, CXXMethodDecl *Tmpl) { if (InitFunctionInstantiation(New, Tmpl)) return true; - + CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner); New->setAccess(Tmpl->getAccess()); if (Tmpl->isVirtualAsWritten()) { @@ -964,15 +964,15 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, return; assert(!Function->getBody() && "Already instantiated!"); - + // Find the function body that we'll be substituting. const FunctionDecl *PatternDecl = 0; if (FunctionTemplateDecl *Primary = Function->getPrimaryTemplate()) { while (Primary->getInstantiatedFromMemberTemplate()) Primary = Primary->getInstantiatedFromMemberTemplate(); - + PatternDecl = Primary->getTemplatedDecl(); - } else + } else PatternDecl = Function->getInstantiatedFromMemberFunction(); Stmt *Pattern = 0; if (PatternDecl) @@ -983,13 +983,13 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // C++0x [temp.explicit]p9: // Except for inline functions, other explicit instantiation declarations - // have the effect of suppressing the implicit instantiation of the entity + // have the effect of suppressing the implicit instantiation of the entity // to which they refer. - if (Function->getTemplateSpecializationKind() + if (Function->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDeclaration && PatternDecl->isOutOfLine() && !PatternDecl->isInline()) return; - + InstantiatingTemplate Inst(*this, PointOfInstantiation, Function); if (Inst) return; @@ -1000,13 +1000,13 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, std::deque<PendingImplicitInstantiation> SavedPendingImplicitInstantiations; if (Recursive) PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); - + ActOnStartOfFunctionDef(0, DeclPtrTy::make(Function)); // Introduce a new scope where local variable instantiations will be // recorded. LocalInstantiationScope Scope(*this); - + // Introduce the instantiated function parameters into the local // instantiation scope. for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) @@ -1018,32 +1018,32 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, DeclContext *PreviousContext = CurContext; CurContext = Function; - MultiLevelTemplateArgumentList TemplateArgs = + MultiLevelTemplateArgumentList TemplateArgs = getTemplateInstantiationArgs(Function); // If this is a constructor, instantiate the member initializers. - if (const CXXConstructorDecl *Ctor = + if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(PatternDecl)) { InstantiateMemInitializers(cast<CXXConstructorDecl>(Function), Ctor, TemplateArgs); - } - + } + // Instantiate the function body. OwningStmtResult Body = SubstStmt(Pattern, TemplateArgs); - ActOnFinishFunctionBody(DeclPtrTy::make(Function), move(Body), + ActOnFinishFunctionBody(DeclPtrTy::make(Function), move(Body), /*IsInstantiation=*/true); CurContext = PreviousContext; DeclGroupRef DG(Function); Consumer.HandleTopLevelDecl(DG); - + if (Recursive) { // Instantiate any pending implicit instantiations found during the - // instantiation of this template. + // instantiation of this template. PerformPendingImplicitInstantiations(); - + // Restore the set of pending implicit instantiations. PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); } @@ -1067,14 +1067,14 @@ void Sema::InstantiateStaticDataMemberDefinition( bool Recursive) { if (Var->isInvalidDecl()) return; - + // Find the out-of-line definition of this static data member. // FIXME: Do we have to look for specializations separately? VarDecl *Def = Var->getInstantiatedFromStaticDataMember(); bool FoundOutOfLineDef = false; assert(Def && "This data member was not instantiated from a template?"); - assert(Def->isStaticDataMember() && "Not a static data member?"); - for (VarDecl::redecl_iterator RD = Def->redecls_begin(), + assert(Def->isStaticDataMember() && "Not a static data member?"); + for (VarDecl::redecl_iterator RD = Def->redecls_begin(), RDEnd = Def->redecls_end(); RD != RDEnd; ++RD) { if (RD->getLexicalDeclContext()->isFileContext()) { @@ -1082,58 +1082,58 @@ void Sema::InstantiateStaticDataMemberDefinition( FoundOutOfLineDef = true; } } - + if (!FoundOutOfLineDef) { // We did not find an out-of-line definition of this static data member, // so we won't perform any instantiation. Rather, we rely on the user to - // instantiate this definition (or provide a specialization for it) in - // another translation unit. + // instantiate this definition (or provide a specialization for it) in + // another translation unit. return; } // FIXME: extern templates - + InstantiatingTemplate Inst(*this, PointOfInstantiation, Var); if (Inst) return; - + // If we're performing recursive template instantiation, create our own // queue of pending implicit instantiations that we will instantiate later, // while we're still within our own instantiation context. std::deque<PendingImplicitInstantiation> SavedPendingImplicitInstantiations; if (Recursive) PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); - + // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. DeclContext *PreviousContext = CurContext; CurContext = Var->getDeclContext(); - + Var = cast_or_null<VarDecl>(SubstDecl(Def, Var->getDeclContext(), getTemplateInstantiationArgs(Var))); - + CurContext = PreviousContext; if (Var) { DeclGroupRef DG(Var); Consumer.HandleTopLevelDecl(DG); } - + if (Recursive) { // Instantiate any pending implicit instantiations found during the - // instantiation of this template. + // instantiation of this template. PerformPendingImplicitInstantiations(); - + // Restore the set of pending implicit instantiations. PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); - } + } } void Sema::InstantiateMemInitializers(CXXConstructorDecl *New, const CXXConstructorDecl *Tmpl, const MultiLevelTemplateArgumentList &TemplateArgs) { - + llvm::SmallVector<MemInitTy*, 4> NewInits; // Instantiate all the initializers. @@ -1143,7 +1143,7 @@ Sema::InstantiateMemInitializers(CXXConstructorDecl *New, CXXBaseOrMemberInitializer *Init = *Inits; ASTOwningVector<&ActionBase::DeleteExpr> NewArgs(*this); - + // Instantiate all the arguments. for (ExprIterator Args = Init->arg_begin(), ArgsEnd = Init->arg_end(); Args != ArgsEnd; ++Args) { @@ -1163,21 +1163,21 @@ Sema::InstantiateMemInitializers(CXXConstructorDecl *New, New->getDeclName()); NewInit = BuildBaseInitializer(BaseType, - (Expr **)NewArgs.data(), + (Expr **)NewArgs.data(), NewArgs.size(), Init->getSourceLocation(), Init->getRParenLoc(), New->getParent()); } else if (Init->isMemberInitializer()) { FieldDecl *Member; - + // Is this an anonymous union? if (FieldDecl *UnionInit = Init->getAnonUnionMember()) Member = cast<FieldDecl>(FindInstantiatedDecl(UnionInit)); else Member = cast<FieldDecl>(FindInstantiatedDecl(Init->getMember())); - - NewInit = BuildMemberInitializer(Member, (Expr **)NewArgs.data(), + + NewInit = BuildMemberInitializer(Member, (Expr **)NewArgs.data(), NewArgs.size(), Init->getSourceLocation(), Init->getRParenLoc()); @@ -1188,16 +1188,16 @@ Sema::InstantiateMemInitializers(CXXConstructorDecl *New, else { // FIXME: It would be nice if ASTOwningVector had a release function. NewArgs.take(); - + NewInits.push_back((MemInitTy *)NewInit.get()); } } - + // Assign all the initializers to the new constructor. - ActOnMemInitializers(DeclPtrTy::make(New), + ActOnMemInitializers(DeclPtrTy::make(New), /*FIXME: ColonLoc */ SourceLocation(), - NewInits.data(), NewInits.size()); + NewInits.data(), NewInits.size()); } // TODO: this could be templated if the various decl types used the @@ -1285,10 +1285,10 @@ static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) { return false; } - + if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other)) return isInstantiationOf(cast<CXXRecordDecl>(D), Record); - + if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other)) return isInstantiationOf(cast<FunctionDecl>(D), Function); @@ -1305,17 +1305,17 @@ static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) { if (FieldDecl *Field = dyn_cast<FieldDecl>(Other)) { if (!Field->getDeclName()) { // This is an unnamed field. - return Ctx.getInstantiatedFromUnnamedFieldDecl(Field) == + return Ctx.getInstantiatedFromUnnamedFieldDecl(Field) == cast<FieldDecl>(D); } } - + return D->getDeclName() && isa<NamedDecl>(Other) && D->getDeclName() == cast<NamedDecl>(Other)->getDeclName(); } template<typename ForwardIterator> -static NamedDecl *findInstantiationOf(ASTContext &Ctx, +static NamedDecl *findInstantiationOf(ASTContext &Ctx, NamedDecl *D, ForwardIterator first, ForwardIterator last) { @@ -1366,19 +1366,19 @@ DeclContext *Sema::FindInstantiatedContext(DeclContext* DC) { NamedDecl *Sema::FindInstantiatedDecl(NamedDecl *D) { if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) { // Transform all of the elements of the overloaded function set. - OverloadedFunctionDecl *Result + OverloadedFunctionDecl *Result = OverloadedFunctionDecl::Create(Context, CurContext, Ovl->getDeclName()); - + for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin(), FEnd = Ovl->function_end(); F != FEnd; ++F) { Result->addOverload( AnyFunctionDecl::getFromNamedDecl(FindInstantiatedDecl(*F))); } - + return Result; - } - + } + DeclContext *ParentDC = D->getDeclContext(); if (isa<ParmVarDecl>(D) || ParentDC->isFunctionOrMethod()) { // D is a local of some kind. Look into the map of local @@ -1387,7 +1387,7 @@ NamedDecl *Sema::FindInstantiatedDecl(NamedDecl *D) { } if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) - if (ClassTemplateDecl *ClassTemplate + if (ClassTemplateDecl *ClassTemplate = Record->getDescribedClassTemplate()) { // When the declaration D was parsed, it referred to the current // instantiation. Therefore, look through the current context, @@ -1396,22 +1396,22 @@ NamedDecl *Sema::FindInstantiatedDecl(NamedDecl *D) { // to. Alternatively, we could just instantiate the // injected-class-name with the current template arguments, but // such an instantiation is far more expensive. - for (DeclContext *DC = CurContext; !DC->isFileContext(); + for (DeclContext *DC = CurContext; !DC->isFileContext(); DC = DC->getParent()) { - if (ClassTemplateSpecializationDecl *Spec + if (ClassTemplateSpecializationDecl *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) if (isInstantiationOf(ClassTemplate, Spec->getSpecializedTemplate())) return Spec; } - assert(false && + assert(false && "Unable to find declaration for the current instantiation"); } ParentDC = FindInstantiatedContext(ParentDC); - if (!ParentDC) + if (!ParentDC) return 0; - + if (ParentDC != D->getDeclContext()) { // We performed some kind of instantiation in the parent context, // so now we need to look into the instantiated parent context to @@ -1429,11 +1429,11 @@ NamedDecl *Sema::FindInstantiatedDecl(NamedDecl *D) { // - unnamed class/struct/union/enum within a template // // FIXME: Find a better way to find these instantiations! - Result = findInstantiationOf(Context, D, + Result = findInstantiationOf(Context, D, ParentDC->decls_begin(), ParentDC->decls_end()); } - + assert(Result && "Unable to find instantiation of declaration!"); D = Result; } @@ -1441,35 +1441,35 @@ NamedDecl *Sema::FindInstantiatedDecl(NamedDecl *D) { return D; } -/// \brief Performs template instantiation for all implicit template +/// \brief Performs template instantiation for all implicit template /// instantiations we have seen until this point. void Sema::PerformPendingImplicitInstantiations() { while (!PendingImplicitInstantiations.empty()) { PendingImplicitInstantiation Inst = PendingImplicitInstantiations.front(); PendingImplicitInstantiations.pop_front(); - + // Instantiate function definitions if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first)) { - PrettyStackTraceActionsDecl CrashInfo(DeclPtrTy::make(Function), + PrettyStackTraceActionsDecl CrashInfo(DeclPtrTy::make(Function), Function->getLocation(), *this, Context.getSourceManager(), "instantiating function definition"); - + if (!Function->getBody()) InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function, true); continue; } - + // Instantiate static data member definitions. VarDecl *Var = cast<VarDecl>(Inst.first); assert(Var->isStaticDataMember() && "Not a static data member?"); - PrettyStackTraceActionsDecl CrashInfo(DeclPtrTy::make(Var), + PrettyStackTraceActionsDecl CrashInfo(DeclPtrTy::make(Var), Var->getLocation(), *this, Context.getSourceManager(), "instantiating static data member " "definition"); - + InstantiateStaticDataMemberDefinition(/*FIXME:*/Inst.second, Var, true); } } diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index b6db829de6..c4064e135e 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -26,8 +26,8 @@ using namespace clang; /// \brief Perform adjustment on the parameter type of a function. /// /// This routine adjusts the given parameter type @p T to the actual -/// parameter type used by semantic analysis (C99 6.7.5.3p[7,8], -/// C++ [dcl.fct]p3). The adjusted parameter type is returned. +/// parameter type used by semantic analysis (C99 6.7.5.3p[7,8], +/// C++ [dcl.fct]p3). The adjusted parameter type is returned. QualType Sema::adjustParameterType(QualType T) { // C99 6.7.5.3p7: if (T->isArrayType()) { @@ -59,7 +59,7 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, // FIXME: Should move the logic from DeclSpec::Finish to here for validity // checking. QualType Result; - + switch (DS.getTypeSpecType()) { case DeclSpec::TST_void: Result = Context.VoidTy; @@ -103,12 +103,12 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, case DeclSpec::TST_unspecified: // "<proto1,proto2>" is an objc qualified ID with a missing id. if (DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers()) { - Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy, + Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy, (ObjCProtocolDecl**)PQ, DS.getNumProtocolQualifiers()); break; } - + // Unspecified typespec defaults to int in C90. However, the C90 grammar // [C90 6.5] only allows a decl-spec if there was *some* type-specifier, // type-qualifier, or storage-class-specifier. If not, emit an extwarn. @@ -139,7 +139,7 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, if (getLangOptions().CPlusPlus && !getLangOptions().Microsoft) { Diag(DeclLoc, diag::err_missing_type_specifier) << DS.getSourceRange(); - + // When this occurs in C++ code, often something is very broken with the // value being declared, poison it as invalid so we don't get chains of // errors. @@ -149,8 +149,8 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, << DS.getSourceRange(); } } - - // FALL THROUGH. + + // FALL THROUGH. case DeclSpec::TST_int: { if (DS.getTypeSpecSign() != DeclSpec::TSS_unsigned) { switch (DS.getTypeSpecWidth()) { @@ -202,11 +202,11 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, = TagDecl::getTagKindForTypeSpec(DS.getTypeSpecType()); Result = Context.getElaboratedType(Result, Tag); } - + if (D->isInvalidDecl()) isInvalid = true; break; - } + } case DeclSpec::TST_typename: { assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && DS.getTypeSpecSign() == 0 && @@ -218,7 +218,7 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, // It would be nice if protocol qualifiers were only stored with the // ObjCObjectPointerType. Unfortunately, this isn't possible due // to the following typedef idiom (which is uncommon, but allowed): - // + // // typedef Foo<P> T; // static void func() { // Foo<P> *yy; @@ -229,13 +229,13 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, DS.getNumProtocolQualifiers()); else if (Result->isObjCIdType()) // id<protocol-list> - Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy, + Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy, (ObjCProtocolDecl**)PQ, DS.getNumProtocolQualifiers()); else if (Result->isObjCClassType()) { if (DeclLoc.isInvalid()) DeclLoc = DS.getSourceRange().getBegin(); // Class<protocol-list> - Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinClassTy, + Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinClassTy, (ObjCProtocolDecl**)PQ, DS.getNumProtocolQualifiers()); } else { if (DeclLoc.isInvalid()) @@ -245,12 +245,12 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, isInvalid = true; } } - + // If this is a reference to an invalid typedef, propagate the invalidity. if (TypedefType *TDT = dyn_cast<TypedefType>(Result)) if (TDT->getDecl()->isInvalidDecl()) isInvalid = true; - + // TypeQuals handled by caller. break; } @@ -284,28 +284,28 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, Result = Context.UndeducedAutoTy; break; } - + case DeclSpec::TST_error: Result = Context.IntTy; isInvalid = true; break; } - + // Handle complex types. if (DS.getTypeSpecComplex() == DeclSpec::TSC_complex) { if (getLangOptions().Freestanding) Diag(DS.getTypeSpecComplexLoc(), diag::ext_freestanding_complex); Result = Context.getComplexType(Result); } - + assert(DS.getTypeSpecComplex() != DeclSpec::TSC_imaginary && "FIXME: imaginary types not supported yet!"); - + // See if there are any attributes on the declspec that apply to the type (as // opposed to the decl). if (const AttributeList *AL = DS.getAttributes()) ProcessTypeAttributeList(Result, AL); - + // Apply const/volatile/restrict qualifiers to T. if (unsigned TypeQuals = DS.getTypeQualifiers()) { @@ -314,10 +314,10 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, // restrict-qualified references. if (TypeQuals & QualType::Restrict) { if (Result->isPointerType() || Result->isReferenceType()) { - QualType EltTy = Result->isPointerType() ? + QualType EltTy = Result->isPointerType() ? Result->getAs<PointerType>()->getPointeeType() : Result->getAs<ReferenceType>()->getPointeeType(); - + // If we have a pointer or reference, the pointee must have an object // incomplete type. if (!EltTy->isIncompleteOrObjectType()) { @@ -333,7 +333,7 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, TypeQuals &= ~QualType::Restrict; // Remove the restrict qualifier. } } - + // Warn about CV qualifiers on functions: C99 6.7.3p8: "If the specification // of a function type includes any type qualifiers, the behavior is // undefined." @@ -350,7 +350,7 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, Diag(Loc, diag::warn_typecheck_function_qualifiers) << Result << DS.getSourceRange(); } - + // C++ [dcl.ref]p1: // Cv-qualified references are ill-formed except when the // cv-qualifiers are introduced through the use of a typedef @@ -361,8 +361,8 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, TypeQuals && Result->isReferenceType()) { TypeQuals &= ~QualType::Const; TypeQuals &= ~QualType::Volatile; - } - + } + Result = Result.getQualifiedType(TypeQuals); } return Result; @@ -371,7 +371,7 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, static std::string getPrintableNameForEntity(DeclarationName Entity) { if (Entity) return Entity.getAsString(); - + return "type name"; } @@ -390,7 +390,7 @@ static std::string getPrintableNameForEntity(DeclarationName Entity) { /// /// \returns A suitable pointer type, if there are no /// errors. Otherwise, returns a NULL type. -QualType Sema::BuildPointerType(QualType T, unsigned Quals, +QualType Sema::BuildPointerType(QualType T, unsigned Quals, SourceLocation Loc, DeclarationName Entity) { if (T->isReferenceType()) { // C++ 8.3.2p4: There shall be no ... pointers to references ... @@ -441,7 +441,7 @@ QualType Sema::BuildReferenceType(QualType T, bool LValueRef, unsigned Quals, } if (T->isReferenceType()) { // C++ [dcl.ref]p4: There shall be no references to references. - // + // // According to C++ DR 106, references to references are only // diagnosed when they are written directly (e.g., "int & &"), // but not when they happen via a typedef: @@ -495,8 +495,8 @@ QualType Sema::BuildReferenceType(QualType T, bool LValueRef, unsigned Quals, /// \param T The type of each element in the array. /// /// \param ASM C99 array size modifier (e.g., '*', 'static'). -/// -/// \param ArraySize Expression describing the size of the array. +/// +/// \param ArraySize Expression describing the size of the array. /// /// \param Quals The cvr-qualifiers to be applied to the array's /// element type. @@ -514,9 +514,9 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, Expr *ArraySize, unsigned Quals, SourceRange Brackets, DeclarationName Entity) { SourceLocation Loc = Brackets.getBegin(); - // C99 6.7.5.2p1: If the element type is an incomplete or function type, + // C99 6.7.5.2p1: If the element type is an incomplete or function type, // reject it (e.g. void ary[7], struct foo ary[7], void ary[7]()) - if (RequireCompleteType(Loc, T, + if (RequireCompleteType(Loc, T, diag::err_illegal_decl_array_incomplete_type)) return QualType(); @@ -525,20 +525,20 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, << getPrintableNameForEntity(Entity); return QualType(); } - + // C++ 8.3.2p4: There shall be no ... arrays of references ... if (T->isReferenceType()) { Diag(Loc, diag::err_illegal_decl_array_of_references) << getPrintableNameForEntity(Entity); return QualType(); - } + } if (Context.getCanonicalType(T) == Context.UndeducedAutoTy) { - Diag(Loc, diag::err_illegal_decl_array_of_auto) + Diag(Loc, diag::err_illegal_decl_array_of_auto) << getPrintableNameForEntity(Entity); return QualType(); } - + if (const RecordType *EltTy = T->getAs<RecordType>()) { // If the element type is a struct or union that contains a variadic // array, accept it as a GNU extension: C99 6.7.2.1p2. @@ -548,7 +548,7 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, Diag(Loc, diag::err_objc_array_of_interfaces) << T; return QualType(); } - + // C99 6.7.5.2p1: The size expression shall have integer type. if (ArraySize && !ArraySize->isTypeDependent() && !ArraySize->getType()->isIntegerType()) { @@ -584,14 +584,14 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, Diag(ArraySize->getLocStart(), diag::ext_typecheck_zero_array_size) << ArraySize->getSourceRange(); } - } + } T = Context.getConstantArrayWithExprType(T, ConstVal, ArraySize, ASM, Quals, Brackets); } // If this is not C99, extwarn about VLA's and C99 array size modifiers. if (!getLangOptions().C99) { - if (ArraySize && !ArraySize->isTypeDependent() && - !ArraySize->isValueDependent() && + if (ArraySize && !ArraySize->isTypeDependent() && + !ArraySize->isValueDependent() && !ArraySize->isIntegerConstantExpr(Context)) Diag(Loc, diag::ext_vla); else if (ASM != ArrayType::Normal || Quals != 0) @@ -604,14 +604,14 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, /// \brief Build an ext-vector type. /// /// Run the required checks for the extended vector type. -QualType Sema::BuildExtVectorType(QualType T, ExprArg ArraySize, +QualType Sema::BuildExtVectorType(QualType T, ExprArg ArraySize, SourceLocation AttrLoc) { Expr *Arg = (Expr *)ArraySize.get(); // unlike gcc's vector_size attribute, we do not allow vectors to be defined // in conjunction with complex types (pointers, arrays, functions, etc.). - if (!T->isDependentType() && + if (!T->isDependentType() && !T->isIntegerType() && !T->isRealFloatingType()) { Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << T; return QualType(); @@ -624,25 +624,25 @@ QualType Sema::BuildExtVectorType(QualType T, ExprArg ArraySize, << "ext_vector_type" << Arg->getSourceRange(); return QualType(); } - - // unlike gcc's vector_size attribute, the size is specified as the + + // unlike gcc's vector_size attribute, the size is specified as the // number of elements, not the number of bytes. - unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue()); - + unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue()); + if (vectorSize == 0) { Diag(AttrLoc, diag::err_attribute_zero_size) << Arg->getSourceRange(); return QualType(); } - + if (!T->isDependentType()) return Context.getExtVectorType(T, vectorSize); - } - - return Context.getDependentSizedExtVectorType(T, ArraySize.takeAs<Expr>(), + } + + return Context.getDependentSizedExtVectorType(T, ArraySize.takeAs<Expr>(), AttrLoc); } - + /// \brief Build a function type. /// /// This routine checks the function type according to C++ rules and @@ -673,7 +673,7 @@ QualType Sema::BuildExtVectorType(QualType T, ExprArg ArraySize, /// \returns A suitable function type, if there are no /// errors. Otherwise, returns a NULL type. QualType Sema::BuildFunctionType(QualType T, - QualType *ParamTypes, + QualType *ParamTypes, unsigned NumParamTypes, bool Variadic, unsigned Quals, SourceLocation Loc, DeclarationName Entity) { @@ -681,7 +681,7 @@ QualType Sema::BuildFunctionType(QualType T, Diag(Loc, diag::err_func_returning_array_function) << T; return QualType(); } - + bool Invalid = false; for (unsigned Idx = 0; Idx < NumParamTypes; ++Idx) { QualType ParamType = adjustParameterType(ParamTypes[Idx]); @@ -696,10 +696,10 @@ QualType Sema::BuildFunctionType(QualType T, if (Invalid) return QualType(); - return Context.getFunctionType(T, ParamTypes, NumParamTypes, Variadic, + return Context.getFunctionType(T, ParamTypes, NumParamTypes, Variadic, Quals); } - + /// \brief Build a member pointer type \c T Class::*. /// /// \param T the type to which the member pointer refers. @@ -710,8 +710,8 @@ QualType Sema::BuildFunctionType(QualType T, /// /// \returns a member pointer type, if successful, or a NULL type if there was /// an error. -QualType Sema::BuildMemberPointerType(QualType T, QualType Class, - unsigned Quals, SourceLocation Loc, +QualType Sema::BuildMemberPointerType(QualType T, QualType Class, + unsigned Quals, SourceLocation Loc, DeclarationName Entity) { // Verify that we're not building a pointer to pointer to function with // exception specification. @@ -757,9 +757,9 @@ QualType Sema::BuildMemberPointerType(QualType T, QualType Class, } return Context.getMemberPointerType(T, Class.getTypePtr()) - .getQualifiedType(Quals); + .getQualifiedType(Quals); } - + /// \brief Build a block pointer type. /// /// \param T The type to which we'll be building a block pointer. @@ -776,13 +776,13 @@ QualType Sema::BuildMemberPointerType(QualType T, QualType Class, /// \returns A suitable block pointer type, if there are no /// errors. Otherwise, returns a NULL type. QualType Sema::BuildBlockPointerType(QualType T, unsigned Quals, - SourceLocation Loc, + SourceLocation Loc, DeclarationName Entity) { if (!T.getTypePtr()->isFunctionType()) { Diag(Loc, diag::err_nonfunction_block_type); return QualType(); } - + return Context.getBlockPointerType(T).getQualifiedType(Quals); } @@ -793,7 +793,7 @@ QualType Sema::GetTypeFromParser(TypeTy *Ty, DeclaratorInfo **DInfo) { QT = LIT->getType(); DI = LIT->getDeclaratorInfo(); } - + if (DInfo) *DInfo = DI; return QT; } @@ -858,7 +858,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, if (T == Context.UndeducedAutoTy) { int Error = -1; - + switch (D.getContext()) { case Declarator::KNRTypeListContext: assert(0 && "K&R type lists aren't allowed in C++"); @@ -872,7 +872,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, case TagDecl::TK_struct: Error = 1; /* Struct member */ break; case TagDecl::TK_union: Error = 2; /* Union member */ break; case TagDecl::TK_class: Error = 3; /* Class member */ break; - } + } break; case Declarator::CXXCatchContext: Error = 4; // Exception declaration @@ -898,12 +898,12 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, D.setInvalidType(true); } } - + // The name we're declaring, if any. DeclarationName Name; if (D.getIdentifier()) Name = D.getIdentifier(); - + bool ShouldBuildInfo = DInfo != 0; // The QualType referring to the type as written in source code. We can't use // T because it can change due to semantic analysis. @@ -930,8 +930,8 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, // If blocks are disabled, emit an error. if (!LangOpts.Blocks) Diag(DeclType.Loc, diag::err_blocks_disable); - - T = BuildBlockPointerType(T, DeclType.Cls.TypeQuals, D.getIdentifierLoc(), + + T = BuildBlockPointerType(T, DeclType.Cls.TypeQuals, D.getIdentifierLoc(), Name); break; case DeclaratorChunk::Pointer: @@ -961,7 +961,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, SourceTy = Context.getLValueReferenceType(SourceTy); else SourceTy = Context.getRValueReferenceType(SourceTy); - unsigned Quals = DeclType.Ref.HasRestrict ? QualType::Restrict : 0; + unsigned Quals = DeclType.Ref.HasRestrict ? QualType::Restrict : 0; SourceTy = SourceTy.getQualifiedType(Quals); } @@ -1015,7 +1015,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, if (ShouldBuildInfo) { const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun; llvm::SmallVector<QualType, 16> ArgTys; - + for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) { ParmVarDecl *Param = FTI.ArgInfo[i].Param.getAs<ParmVarDecl>(); if (Param) @@ -1059,7 +1059,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, // function takes no arguments. llvm::SmallVector<QualType, 4> Exceptions; Exceptions.reserve(FTI.NumExceptions); - for(unsigned ei = 0, ee = FTI.NumExceptions; ei != ee; ++ei) { + for (unsigned ei = 0, ee = FTI.NumExceptions; ei != ee; ++ei) { // FIXME: Preserve type source info. QualType ET = GetTypeFromParser(FTI.Exceptions[ei].Ty); // Check that the type is valid for an exception spec, and drop it @@ -1093,12 +1093,12 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, } } else if (FTI.ArgInfo[0].Param == 0) { // C99 6.7.5.3p3: Reject int(x,y,z) when it's not a function definition. - Diag(FTI.ArgInfo[0].IdentLoc, diag::err_ident_list_in_fn_declaration); + Diag(FTI.ArgInfo[0].IdentLoc, diag::err_ident_list_in_fn_declaration); } else { // Otherwise, we have a function with an argument list that is // potentially variadic. llvm::SmallVector<QualType, 16> ArgTys; - + for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) { ParmVarDecl *Param = cast<ParmVarDecl>(FTI.ArgInfo[i].Param.getAs<Decl>()); @@ -1129,7 +1129,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, // Reject, but continue to parse 'float(const void)'. if (ArgTy.getCVRQualifiers()) Diag(DeclType.Loc, diag::err_void_param_qualified); - + // Do not add 'void' to the ArgTys list. break; } @@ -1141,13 +1141,13 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, ArgTy = Context.DoubleTy; } } - + ArgTys.push_back(ArgTy); } llvm::SmallVector<QualType, 4> Exceptions; Exceptions.reserve(FTI.NumExceptions); - for(unsigned ei = 0, ee = FTI.NumExceptions; ei != ee; ++ei) { + for (unsigned ei = 0, ee = FTI.NumExceptions; ei != ee; ++ei) { // FIXME: Preserve type source info. QualType ET = GetTypeFromParser(FTI.Exceptions[ei].Ty); // Check that the type is valid for an exception spec, and drop it if @@ -1175,11 +1175,11 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, // The scope spec must refer to a class, or be dependent. QualType ClsType; if (isDependentScopeSpecifier(DeclType.Mem.Scope())) { - NestedNameSpecifier *NNS + NestedNameSpecifier *NNS = (NestedNameSpecifier *)DeclType.Mem.Scope().getScopeRep(); assert(NNS->getAsType() && "Nested-name-specifier must name a type"); ClsType = QualType(NNS->getAsType(), 0); - } else if (CXXRecordDecl *RD + } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>( computeDeclContext(DeclType.Mem.Scope()))) { ClsType = Context.getTagDeclType(RD); @@ -1243,7 +1243,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, FnTy->getNumArgs(), FnTy->isVariadic(), 0); } } - + // If there were any type attributes applied to the decl itself (not the // type, apply the type attribute to the type!) if (const AttributeList *Attrs = D.getAttributes()) @@ -1315,12 +1315,12 @@ Sema::GetDeclaratorInfoForDeclarator(Declarator &D, QualType T, unsigned Skip) { //FIXME: Class location. break; } - + } CurrTL = CurrTL.getNextTypeLoc(); } - + if (TypedefLoc *TL = dyn_cast<TypedefLoc>(&CurrTL)) { TL->setNameLoc(D.getDeclSpec().getTypeSpecTypeLoc()); } else { @@ -1446,8 +1446,7 @@ bool Sema::CheckEquivalentExceptionSpec( /// type. This is used by override and pointer assignment checks. bool Sema::CheckExceptionSpecSubset(unsigned DiagID, unsigned NoteID, const FunctionProtoType *Superset, SourceLocation SuperLoc, - const FunctionProtoType *Subset, SourceLocation SubLoc) -{ + const FunctionProtoType *Subset, SourceLocation SubLoc) { // FIXME: As usual, we could be more specific in our error messages, but // that better waits until we've got types with source locations. @@ -1537,7 +1536,7 @@ QualType Sema::ObjCGetTypeForMethodDefinition(DeclPtrTy D) { ObjCMethodDecl *MDecl = cast<ObjCMethodDecl>(D.getAs<Decl>()); QualType T = MDecl->getResultType(); llvm::SmallVector<QualType, 16> ArgTys; - + // Add the first two invisible argument types for self and _cmd. if (MDecl->isInstanceMethod()) { QualType selfTy = Context.getObjCInterfaceType(MDecl->getClassInterface()); @@ -1546,7 +1545,7 @@ QualType Sema::ObjCGetTypeForMethodDefinition(DeclPtrTy D) { } else ArgTys.push_back(Context.getObjCIdType()); ArgTys.push_back(Context.getObjCSelType()); - + for (ObjCMethodDecl::param_iterator PI = MDecl->param_begin(), E = MDecl->param_end(); PI != E; ++PI) { QualType ArgTy = (*PI)->getType(); @@ -1592,7 +1591,7 @@ Sema::TypeResult Sema::ActOnTypeName(Scope *S, Declarator &D) { // C99 6.7.6: Type names have no identifier. This is already validated by // the parser. assert(D.getIdentifier() == 0 && "Type name should have no identifier!"); - + DeclaratorInfo *DInfo = 0; TagDecl *OwnedTag = 0; QualType T = GetTypeForDeclarator(D, S, &DInfo, /*Skip=*/0, &OwnedTag); @@ -1627,7 +1626,7 @@ Sema::TypeResult Sema::ActOnTypeName(Scope *S, Declarator &D) { /// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the /// specified type. The attribute contains 1 argument, the id of the address /// space for the type. -static void HandleAddressSpaceTypeAttribute(QualType &Type, +static void HandleAddressSpaceTypeAttribute(QualType &Type, const AttributeList &Attr, Sema &S){ // If this type is already address space qualified, reject it. // Clause 6.7.3 - Type qualifiers: "No type shall be qualified by qualifiers @@ -1636,7 +1635,7 @@ static void HandleAddressSpaceTypeAttribute(QualType &Type, S.Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers); return; } - + // Check the attribute arguments. if (Attr.getNumArgs() != 1) { S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; @@ -1667,21 +1666,21 @@ static void HandleAddressSpaceTypeAttribute(QualType &Type, return; } - unsigned ASIdx = static_cast<unsigned>(addrSpace.getZExtValue()); + unsigned ASIdx = static_cast<unsigned>(addrSpace.getZExtValue()); Type = S.Context.getAddrSpaceQualType(Type, ASIdx); } /// HandleObjCGCTypeAttribute - Process an objc's gc attribute on the /// specified type. The attribute contains 1 argument, weak or strong. -static void HandleObjCGCTypeAttribute(QualType &Type, +static void HandleObjCGCTypeAttribute(QualType &Type, const AttributeList &Attr, Sema &S) { if (Type.getObjCGCAttr() != QualType::GCNone) { S.Diag(Attr.getLoc(), diag::err_attribute_multiple_objc_gc); return; } - + // Check the attribute arguments. - if (!Attr.getParameterName()) { + if (!Attr.getParameterName()) { S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string) << "objc_gc" << 1; return; @@ -1691,7 +1690,7 @@ static void HandleObjCGCTypeAttribute(QualType &Type, S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; return; } - if (Attr.getParameterName()->isStr("weak")) + if (Attr.getParameterName()->isStr("weak")) GCAttr = QualType::Weak; else if (Attr.getParameterName()->isStr("strong")) GCAttr = QualType::Strong; @@ -1700,13 +1699,13 @@ static void HandleObjCGCTypeAttribute(QualType &Type, << "objc_gc" << Attr.getParameterName(); return; } - + Type = S.Context.getObjCGCQualType(Type, GCAttr); } /// HandleNoReturnTypeAttribute - Process the noreturn attribute on the /// specified type. The attribute contains 0 arguments. -static void HandleNoReturnTypeAttribute(QualType &Type, +static void HandleNoReturnTypeAttribute(QualType &Type, const AttributeList &Attr, Sema &S) { if (Attr.getNumArgs() != 0) return; @@ -1743,7 +1742,7 @@ void Sema::ProcessTypeAttributeList(QualType &Result, const AttributeList *AL) { } } -/// @brief Ensure that the type T is a complete type. +/// @brief Ensure that the type T is a complete type. /// /// This routine checks whether the type @p T is complete in any /// context where a complete type is required. If @p T is a complete @@ -1758,7 +1757,7 @@ void Sema::ProcessTypeAttributeList(QualType &Result, const AttributeList *AL) { /// /// @param T The type that this routine is examining for completeness. /// -/// @param PD The partial diagnostic that will be printed out if T is not a +/// @param PD The partial diagnostic that will be printed out if T is not a /// complete type. /// /// @returns @c true if @p T is incomplete and a diagnostic was emitted, @@ -1766,11 +1765,11 @@ void Sema::ProcessTypeAttributeList(QualType &Result, const AttributeList *AL) { bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, const PartialDiagnostic &PD) { unsigned diag = PD.getDiagID(); - + // FIXME: Add this assertion to help us flush out problems with // checking for dependent types and type-dependent expressions. // - // assert(!T->isDependentType() && + // assert(!T->isDependentType() && // "Can't ask whether a dependent type is complete"); // If we have a complete type, we're done. @@ -1791,11 +1790,11 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, TSK_ImplicitInstantiation, /*Complain=*/diag != 0); } - } else if (CXXRecordDecl *Rec + } else if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Record->getDecl())) { if (CXXRecordDecl *Pattern = Rec->getInstantiatedFromMemberClass()) { // This record was instantiated from a class within a template. - return InstantiateClass(Loc, Rec, Pattern, + return InstantiateClass(Loc, Rec, Pattern, getTemplateInstantiationArgs(Rec), TSK_ImplicitInstantiation, /*Complain=*/diag != 0); @@ -1805,12 +1804,12 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, if (diag == 0) return true; - + // We have an incomplete type. Produce a diagnostic. Diag(Loc, PD) << T; // If the type was a forward declaration of a class/struct/union - // type, produce + // type, produce const TagType *Tag = 0; if (const RecordType *Record = T->getAs<RecordType>()) Tag = Record; @@ -1818,7 +1817,7 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, Tag = Enum; if (Tag && !Tag->getDecl()->isInvalidDecl()) - Diag(Tag->getDecl()->getLocation(), + Diag(Tag->getDecl()->getLocation(), Tag->isBeingDefined() ? diag::note_type_being_defined : diag::note_forward_declaration) << QualType(Tag, 0); @@ -1831,7 +1830,7 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, QualType Sema::getQualifiedNameType(const CXXScopeSpec &SS, QualType T) { if (!SS.isSet() || SS.isInvalid() || T.isNull()) return T; - + NestedNameSpecifier *NNS = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); return Context.getQualifiedNameType(NNS, T); @@ -1843,7 +1842,7 @@ QualType Sema::BuildTypeofExprType(Expr *E) { QualType Sema::BuildDecltypeType(Expr *E) { if (E->getType() == Context.OverloadTy) { - Diag(E->getLocStart(), + Diag(E->getLocStart(), diag::err_cannot_determine_declared_type_of_overloaded_function); return QualType(); } diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index d19653d157..bd7fb4f2f8 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -28,13 +28,13 @@ #include <algorithm> namespace clang { - + /// \brief A semantic tree transformation that allows one to transform one /// abstract syntax tree into another. /// -/// A new tree transformation is defined by creating a new subclass \c X of -/// \c TreeTransform<X> and then overriding certain operations to provide -/// behavior specific to that transformation. For example, template +/// A new tree transformation is defined by creating a new subclass \c X of +/// \c TreeTransform<X> and then overriding certain operations to provide +/// behavior specific to that transformation. For example, template /// instantiation is implemented as a tree transformation where the /// transformation of TemplateTypeParmType nodes involves substituting the /// template arguments for their corresponding template parameters; a similar @@ -42,7 +42,7 @@ namespace clang { /// template template parameters. /// /// This tree-transformation template uses static polymorphism to allow -/// subclasses to customize any of its operations. Thus, a subclass can +/// subclasses to customize any of its operations. Thus, a subclass can /// override any of the transformation or rebuild operators by providing an /// operation with the same signature as the default implementation. The /// overridding function should not be virtual. @@ -57,7 +57,7 @@ namespace clang { /// were changed by the transformation, invokes the rebuild operation to create /// a new AST node. /// -/// Subclasses can customize the transformation at various levels. The +/// Subclasses can customize the transformation at various levels. The /// most coarse-grained transformations involve replacing TransformType(), /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), /// TransformTemplateName(), or TransformTemplateArgument() with entirely @@ -67,7 +67,7 @@ namespace clang { /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, /// replacing TransformTemplateTypeParmType() allows template instantiation -/// to substitute template arguments for their corresponding template +/// to substitute template arguments for their corresponding template /// parameters. Additionally, subclasses can override the \c RebuildXXX /// functions to control how AST nodes are rebuilt when their operands change. /// By default, \c TreeTransform will invoke semantic analysis to rebuild @@ -75,7 +75,7 @@ namespace clang { /// be able to use more efficient rebuild steps. /// /// There are a handful of other functions that can be overridden, allowing one -/// to avoid traversing nodes that don't need any transformation +/// to avoid traversing nodes that don't need any transformation /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their /// operands have not changed (\c AlwaysRebuild()), and customize the /// default locations and entity names used for type-checking @@ -84,45 +84,45 @@ template<typename Derived> class TreeTransform { protected: Sema &SemaRef; - -public: + +public: typedef Sema::OwningStmtResult OwningStmtResult; typedef Sema::OwningExprResult OwningExprResult; typedef Sema::StmtArg StmtArg; typedef Sema::ExprArg ExprArg; typedef Sema::MultiExprArg MultiExprArg; typedef Sema::MultiStmtArg MultiStmtArg; - + /// \brief Initializes a new tree transformer. TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } - + /// \brief Retrieves a reference to the derived class. Derived &getDerived() { return static_cast<Derived&>(*this); } /// \brief Retrieves a reference to the derived class. - const Derived &getDerived() const { - return static_cast<const Derived&>(*this); + const Derived &getDerived() const { + return static_cast<const Derived&>(*this); } /// \brief Retrieves a reference to the semantic analysis object used for /// this tree transform. Sema &getSema() const { return SemaRef; } - + /// \brief Whether the transformation should always rebuild AST nodes, even /// if none of the children have changed. /// /// Subclasses may override this function to specify when the transformation /// should rebuild all AST nodes. bool AlwaysRebuild() { return false; } - + /// \brief Returns the location of the entity being transformed, if that /// information was not available elsewhere in the AST. /// - /// By default, returns no source-location information. Subclasses can + /// By default, returns no source-location information. Subclasses can /// provide an alternative implementation that provides better location /// information. SourceLocation getBaseLocation() { return SourceLocation(); } - + /// \brief Returns the name of the entity being transformed, if that /// information was not available elsewhere in the AST. /// @@ -136,33 +136,32 @@ public: /// By default, the source location and entity are ignored. Subclasses can /// override this function to provide a customized implementation. void setBase(SourceLocation Loc, DeclarationName Entity) { } - + /// \brief RAII object that temporarily sets the base location and entity /// used for reporting diagnostics in types. class TemporaryBase { TreeTransform &Self; SourceLocation OldLocation; DeclarationName OldEntity; - + public: TemporaryBase(TreeTransform &Self, SourceLocation Location, - DeclarationName Entity) : Self(Self) - { + DeclarationName Entity) : Self(Self) { OldLocation = Self.getDerived().getBaseLocation(); OldEntity = Self.getDerived().getBaseEntity(); Self.getDerived().setBase(Location, Entity); } - + ~TemporaryBase() { Self.getDerived().setBase(OldLocation, OldEntity); } }; - - /// \brief Determine whether the given type \p T has already been + + /// \brief Determine whether the given type \p T has already been /// transformed. /// /// Subclasses can provide an alternative implementation of this routine - /// to short-circuit evaluation when it is known that a given type will + /// to short-circuit evaluation when it is known that a given type will /// not change. For example, template instantiation need not traverse /// non-dependent types. bool AlreadyTransformed(QualType T) { @@ -172,15 +171,15 @@ public: /// \brief Transforms the given type into another type. /// /// By default, this routine transforms a type by delegating to the - /// appropriate TransformXXXType to build a new type, then applying - /// the qualifiers on \p T to the resulting type with AddTypeQualifiers. - /// Subclasses may override this function (to take over all type + /// appropriate TransformXXXType to build a new type, then applying + /// the qualifiers on \p T to the resulting type with AddTypeQualifiers. + /// Subclasses may override this function (to take over all type /// transformations), some set of the TransformXXXType functions, or /// the AddTypeQualifiers function to alter the transformation. /// /// \returns the transformed type. QualType TransformType(QualType T); - + /// \brief Transform the given type by adding the given set of qualifiers /// and returning the result. /// @@ -190,10 +189,10 @@ public: /// is the right thing for template instantiation, but probably not for /// other clients. QualType AddTypeQualifiers(QualType T, unsigned CVRQualifiers); - + /// \brief Transform the given statement. /// - /// By default, this routine transforms a statement by delegating to the + /// By default, this routine transforms a statement by delegating to the /// appropriate TransformXXXStmt function to transform a specific kind of /// statement or the TransformExpr() function to transform an expression. /// Subclasses may override this function to transform statements using some @@ -201,7 +200,7 @@ public: /// /// \returns the transformed statement. OwningStmtResult TransformStmt(Stmt *S); - + /// \brief Transform the given expression. /// /// By default, this routine transforms an expression by delegating to the @@ -223,7 +222,7 @@ public: /// /// \returns the transformed expression. OwningExprResult TransformExpr(Expr *E, bool isAddressOfOperand); - + /// \brief Transform the given declaration, which is referenced from a type /// or expression. /// @@ -233,20 +232,20 @@ public: /// \brief Transform the definition of the given declaration. /// - /// By default, invokes TransformDecl() to transform the declaration. + /// By default, invokes TransformDecl() to transform the declaration. /// Subclasses may override this function to provide alternate behavior. Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); } - + /// \brief Transform the given nested-name-specifier. /// - /// By default, transforms all of the types and declarations within the + /// By default, transforms all of the types and declarations within the /// nested-name-specifier. Subclasses may override this function to provide /// alternate behavior. NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, SourceRange Range, QualType ObjectType = QualType(), NamedDecl *FirstQualifierInScope = 0); - + /// \brief Transform the given declaration name. /// /// By default, transforms the types of conversion function, constructor, @@ -255,37 +254,37 @@ public: /// override this function to provide alternate behavior. DeclarationName TransformDeclarationName(DeclarationName Name, SourceLocation Loc); - + /// \brief Transform the given template name. - /// + /// /// By default, transforms the template name by transforming the declarations - /// and nested-name-specifiers that occur within the template name. + /// and nested-name-specifiers that occur within the template name. /// Subclasses may override this function to provide alternate behavior. TemplateName TransformTemplateName(TemplateName Name, QualType ObjectType = QualType()); - + /// \brief Transform the given template argument. /// - /// By default, this operation transforms the type, expression, or - /// declaration stored within the template argument and constructs a + /// By default, this operation transforms the type, expression, or + /// declaration stored within the template argument and constructs a /// new template argument from the transformed result. Subclasses may /// override this function to provide alternate behavior. TemplateArgument TransformTemplateArgument(const TemplateArgument &Arg); - + #define ABSTRACT_TYPE(CLASS, PARENT) #define TYPE(CLASS, PARENT) \ QualType Transform##CLASS##Type(const CLASS##Type *T); -#include "clang/AST/TypeNodes.def" +#include "clang/AST/TypeNodes.def" OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); - + #define STMT(Node, Parent) \ OwningStmtResult Transform##Node(Node *S); #define EXPR(Node, Parent) \ OwningExprResult Transform##Node(Node *E); #define ABSTRACT_EXPR(Node, Parent) #include "clang/AST/StmtNodes.def" - + /// \brief Build a new pointer type given its pointee type. /// /// By default, performs semantic analysis when building the pointer type. @@ -294,7 +293,7 @@ public: /// \brief Build a new block pointer type given its pointee type. /// - /// By default, performs semantic analysis when building the block pointer + /// By default, performs semantic analysis when building the block pointer /// type. Subclasses may override this routine to provide different behavior. QualType RebuildBlockPointerType(QualType PointeeType); @@ -309,45 +308,45 @@ public: /// By default, performs semantic analysis when building the rvalue reference /// type. Subclasses may override this routine to provide different behavior. QualType RebuildRValueReferenceType(QualType ReferentType); - + /// \brief Build a new member pointer type given the pointee type and the /// class type it refers into. /// /// By default, performs semantic analysis when building the member pointer /// type. Subclasses may override this routine to provide different behavior. QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType); - + /// \brief Build a new array type given the element type, size /// modifier, size of the array (if known), size expression, and index type /// qualifiers. /// /// By default, performs semantic analysis when building the array type. /// Subclasses may override this routine to provide different behavior. - /// Also by default, all of the other Rebuild*Array + /// Also by default, all of the other Rebuild*Array QualType RebuildArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt *Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange); - + /// \brief Build a new constant array type given the element type, size /// modifier, (known) size of the array, and index type qualifiers. /// /// By default, performs semantic analysis when building the array type. /// Subclasses may override this routine to provide different behavior. - QualType RebuildConstantArrayType(QualType ElementType, + QualType RebuildConstantArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt &Size, unsigned IndexTypeQuals); /// \brief Build a new constant array type given the element type, size - /// modifier, (known) size of the array, size expression, and index type + /// modifier, (known) size of the array, size expression, and index type /// qualifiers. /// /// By default, performs semantic analysis when building the array type. /// Subclasses may override this routine to provide different behavior. - QualType RebuildConstantArrayWithExprType(QualType ElementType, + QualType RebuildConstantArrayWithExprType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt &Size, Expr *SizeExpr, @@ -359,7 +358,7 @@ public: /// /// By default, performs semantic analysis when building the array type. /// Subclasses may override this routine to provide different behavior. - QualType RebuildConstantArrayWithoutExprType(QualType ElementType, + QualType RebuildConstantArrayWithoutExprType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt &Size, unsigned IndexTypeQuals); @@ -369,27 +368,27 @@ public: /// /// By default, performs semantic analysis when building the array type. /// Subclasses may override this routine to provide different behavior. - QualType RebuildIncompleteArrayType(QualType ElementType, + QualType RebuildIncompleteArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, unsigned IndexTypeQuals); - /// \brief Build a new variable-length array type given the element type, + /// \brief Build a new variable-length array type given the element type, /// size modifier, size expression, and index type qualifiers. /// /// By default, performs semantic analysis when building the array type. /// Subclasses may override this routine to provide different behavior. - QualType RebuildVariableArrayType(QualType ElementType, + QualType RebuildVariableArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, ExprArg SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange); - /// \brief Build a new dependent-sized array type given the element type, + /// \brief Build a new dependent-sized array type given the element type, /// size modifier, size expression, and index type qualifiers. /// /// By default, performs semantic analysis when building the array type. /// Subclasses may override this routine to provide different behavior. - QualType RebuildDependentSizedArrayType(QualType ElementType, + QualType RebuildDependentSizedArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, ExprArg SizeExpr, unsigned IndexTypeQuals, @@ -401,7 +400,7 @@ public: /// By default, performs semantic analysis when building the vector type. /// Subclasses may override this routine to provide different behavior. QualType RebuildVectorType(QualType ElementType, unsigned NumElements); - + /// \brief Build a new extended vector type given the element type and /// number of elements. /// @@ -409,25 +408,25 @@ public: /// Subclasses may override this routine to provide different behavior. QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, SourceLocation AttributeLoc); - - /// \brief Build a new potentially dependently-sized extended vector type + + /// \brief Build a new potentially dependently-sized extended vector type /// given the element type and number of elements. /// /// By default, performs semantic analysis when building the vector type. /// Subclasses may override this routine to provide different behavior. - QualType RebuildDependentSizedExtVectorType(QualType ElementType, + QualType RebuildDependentSizedExtVectorType(QualType ElementType, ExprArg SizeExpr, SourceLocation AttributeLoc); - + /// \brief Build a new function type. /// /// By default, performs semantic analysis when building the function type. /// Subclasses may override this routine to provide different behavior. QualType RebuildFunctionProtoType(QualType T, - QualType *ParamTypes, + QualType *ParamTypes, unsigned NumParamTypes, bool Variadic, unsigned Quals); - + /// \brief Build a new typedef type. QualType RebuildTypedefType(TypedefDecl *Typedef) { return SemaRef.Context.getTypeDeclType(Typedef); @@ -447,24 +446,24 @@ public: QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { return SemaRef.Context.getElaboratedType(T, Tag); } - - /// \brief Build a new typeof(expr) type. + + /// \brief Build a new typeof(expr) type. /// /// By default, performs semantic analysis when building the typeof type. /// Subclasses may override this routine to provide different behavior. QualType RebuildTypeOfExprType(ExprArg Underlying); - /// \brief Build a new typeof(type) type. + /// \brief Build a new typeof(type) type. /// /// By default, builds a new TypeOfType with the given underlying type. QualType RebuildTypeOfType(QualType Underlying); - /// \brief Build a new C++0x decltype type. + /// \brief Build a new C++0x decltype type. /// /// By default, performs semantic analysis when building the decltype type. /// Subclasses may override this routine to provide different behavior. QualType RebuildDecltypeType(ExprArg Underlying); - + /// \brief Build a new template specialization type. /// /// By default, performs semantic analysis when building the template @@ -473,40 +472,40 @@ public: QualType RebuildTemplateSpecializationType(TemplateName Template, const TemplateArgument *Args, unsigned NumArgs); - + /// \brief Build a new qualified name type. /// - /// By default, builds a new QualifiedNameType type from the - /// nested-name-specifier and the named type. Subclasses may override + /// By default, builds a new QualifiedNameType type from the + /// nested-name-specifier and the named type. Subclasses may override /// this routine to provide different behavior. QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { return SemaRef.Context.getQualifiedNameType(NNS, Named); - } + } /// \brief Build a new typename type that refers to a template-id. /// /// By default, builds a new TypenameType type from the nested-name-specifier - /// and the given type. Subclasses may override this routine to provide + /// and the given type. Subclasses may override this routine to provide /// different behavior. QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { if (NNS->isDependent()) - return SemaRef.Context.getTypenameType(NNS, + return SemaRef.Context.getTypenameType(NNS, cast<TemplateSpecializationType>(T)); - + return SemaRef.Context.getQualifiedNameType(NNS, T); - } + } /// \brief Build a new typename type that refers to an identifier. /// /// By default, performs semantic analysis when building the typename type - /// (or qualified name type). Subclasses may override this routine to provide + /// (or qualified name type). Subclasses may override this routine to provide /// different behavior. - QualType RebuildTypenameType(NestedNameSpecifier *NNS, + QualType RebuildTypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Id) { return SemaRef.CheckTypenameType(NNS, *Id, SourceRange(getDerived().getBaseLocation())); } - + /// \brief Build a new nested-name-specifier given the prefix and an /// identifier that names the next step in the nested-name-specifier. /// @@ -559,7 +558,7 @@ public: TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, bool TemplateKW, OverloadedFunctionDecl *Ovl); - + /// \brief Build a new template name given a nested name specifier and the /// name that is referred to as a template. /// @@ -570,8 +569,8 @@ public: TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, const IdentifierInfo &II, QualType ObjectType); - - + + /// \brief Build a new compound statement. /// /// By default, performs semantic analysis to build the new statement. @@ -593,10 +592,10 @@ public: SourceLocation EllipsisLoc, ExprArg RHS, SourceLocation ColonLoc) { - return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), + return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), ColonLoc); } - + /// \brief Attach the body to a new case statement. /// /// By default, performs semantic analysis to build the new statement. @@ -605,39 +604,39 @@ public: getSema().ActOnCaseStmtBody(S.get(), move(Body)); return move(S); } - + /// \brief Build a new default statement. /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, + OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, StmtArg SubStmt) { - return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), + return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), /*CurScope=*/0); } - + /// \brief Build a new label statement. /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, + OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, IdentifierInfo *Id, SourceLocation ColonLoc, StmtArg SubStmt) { return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); } - + /// \brief Build a new "if" statement. /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, - StmtArg Then, SourceLocation ElseLoc, + OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, + StmtArg Then, SourceLocation ElseLoc, StmtArg Else) { return getSema().ActOnIfStmt(IfLoc, Cond, move(Then), ElseLoc, move(Else)); } - + /// \brief Start building a new switch statement. /// /// By default, performs semantic analysis to build the new statement. @@ -645,12 +644,12 @@ public: OwningStmtResult RebuildSwitchStmtStart(ExprArg Cond) { return getSema().ActOnStartOfSwitchStmt(move(Cond)); } - + /// \brief Attach the body to the switch statement. /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, + OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, StmtArg Switch, StmtArg Body) { return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), move(Body)); @@ -665,7 +664,7 @@ public: StmtArg Body) { return getSema().ActOnWhileStmt(WhileLoc, Cond, move(Body)); } - + /// \brief Build a new do-while statement. /// /// By default, performs semantic analysis to build the new statement. @@ -675,7 +674,7 @@ public: SourceLocation LParenLoc, ExprArg Cond, SourceLocation RParenLoc) { - return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, + return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, move(Cond), RParenLoc); } @@ -683,14 +682,14 @@ public: /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - OwningStmtResult RebuildForStmt(SourceLocation ForLoc, + OwningStmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, StmtArg Init, ExprArg Cond, ExprArg Inc, SourceLocation RParenLoc, StmtArg Body) { - return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond), + return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond), move(Inc), RParenLoc, move(Body)); } - + /// \brief Build a new goto statement. /// /// By default, performs semantic analysis to build the new statement. @@ -710,23 +709,23 @@ public: ExprArg Target) { return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); } - + /// \brief Build a new return statement. /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, ExprArg Result) { - + return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); } - + /// \brief Build a new declaration statement. /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, - SourceLocation StartLoc, + SourceLocation StartLoc, SourceLocation EndLoc) { return getSema().Owned( new (getSema().Context) DeclStmt( @@ -734,17 +733,17 @@ public: Decls, NumDecls), StartLoc, EndLoc)); } - + /// \brief Build a new C++ exception declaration. /// /// By default, performs semantic analysis to build the new decaration. /// Subclasses may override this routine to provide different behavior. - VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, + VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, DeclaratorInfo *Declarator, IdentifierInfo *Name, SourceLocation Loc, SourceRange TypeRange) { - return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, + return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, TypeRange); } @@ -756,10 +755,10 @@ public: VarDecl *ExceptionDecl, StmtArg Handler) { return getSema().Owned( - new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, + new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, Handler.takeAs<Stmt>())); } - + /// \brief Build a new C++ try statement. /// /// By default, performs semantic analysis to build the new statement. @@ -769,7 +768,7 @@ public: MultiStmtArg Handlers) { return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); } - + /// \brief Build a new expression that references a declaration. /// /// By default, performs semantic analysis to build the new expression. @@ -780,9 +779,9 @@ public: /*SS=*/0, /*FIXME:*/false); } - + /// \brief Build a new expression in parentheses. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, @@ -791,7 +790,7 @@ public: } /// \brief Build a new pseudo-destructor expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, @@ -807,21 +806,21 @@ public: SS.setScopeRep(Qualifier); } - DeclarationName Name + DeclarationName Name = SemaRef.Context.DeclarationNames.getCXXDestructorName( SemaRef.Context.getCanonicalType(DestroyedType)); - - return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), + + return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OperatorLoc, isArrow? tok::arrow : tok::period, DestroyedTypeLoc, Name, Sema::DeclPtrTy::make((Decl *)0), &SS); - } - + } + /// \brief Build a new unary operator expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, @@ -829,9 +828,9 @@ public: ExprArg SubExpr) { return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(SubExpr)); } - + /// \brief Build a new sizeof or alignof expression with a type argument. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildSizeOfAlignOf(QualType T, SourceLocation OpLoc, @@ -839,38 +838,38 @@ public: return getSema().CreateSizeOfAlignOfExpr(T, OpLoc, isSizeOf, R); } - /// \brief Build a new sizeof or alignof expression with an expression + /// \brief Build a new sizeof or alignof expression with an expression /// argument. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, bool isSizeOf, SourceRange R) { - OwningExprResult Result + OwningExprResult Result = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), OpLoc, isSizeOf, R); if (Result.isInvalid()) return getSema().ExprError(); - + SubExpr.release(); return move(Result); } - + /// \brief Build a new array subscript expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, + OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, SourceLocation LBracketLoc, ExprArg RHS, SourceLocation RBracketLoc) { return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), - LBracketLoc, move(RHS), + LBracketLoc, move(RHS), RBracketLoc); } /// \brief Build a new call expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, @@ -882,11 +881,11 @@ public: } /// \brief Build a new member access expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, - bool isArrow, + bool isArrow, NestedNameSpecifier *Qualifier, SourceRange QualifierRange, SourceLocation MemberLoc, @@ -894,14 +893,14 @@ public: if (!Member->getDeclName()) { // We have a reference to an unnamed field. assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); - - MemberExpr *ME = + + MemberExpr *ME = new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow, Member, MemberLoc, cast<FieldDecl>(Member)->getType()); return getSema().Owned(ME); } - + CXXScopeSpec SS; if (Qualifier) { SS.setRange(QualifierRange); @@ -915,27 +914,27 @@ public: /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0), &SS); } - + /// \brief Build a new binary operator expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperator::Opcode Opc, ExprArg LHS, ExprArg RHS) { OwningExprResult Result - = getSema().CreateBuiltinBinOp(OpLoc, Opc, (Expr *)LHS.get(), + = getSema().CreateBuiltinBinOp(OpLoc, Opc, (Expr *)LHS.get(), (Expr *)RHS.get()); if (Result.isInvalid()) return SemaRef.ExprError(); - + LHS.release(); RHS.release(); return move(Result); } /// \brief Build a new conditional operator expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildConditionalOperator(ExprArg Cond, @@ -943,25 +942,25 @@ public: ExprArg LHS, SourceLocation ColonLoc, ExprArg RHS) { - return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), + return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), move(LHS), move(RHS)); } /// \brief Build a new implicit cast expression. - /// + /// /// By default, builds a new implicit cast without any semantic analysis. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind, ExprArg SubExpr, bool isLvalue) { ImplicitCastExpr *ICE - = new (getSema().Context) ImplicitCastExpr(T, Kind, + = new (getSema().Context) ImplicitCastExpr(T, Kind, (Expr *)SubExpr.release(), isLvalue); return getSema().Owned(ICE); } /// \brief Build a new C-style cast expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc, @@ -974,9 +973,9 @@ public: RParenLoc, move(SubExpr)); } - + /// \brief Build a new compound literal expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, @@ -986,12 +985,12 @@ public: return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(), RParenLoc, move(Init)); } - + /// \brief Build a new extended vector element access expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, + OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, SourceLocation OpLoc, SourceLocation AccessorLoc, IdentifierInfo &Accessor) { @@ -1000,9 +999,9 @@ public: Accessor, /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0)); } - + /// \brief Build a new initializer list expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildInitList(SourceLocation LBraceLoc, @@ -1010,9 +1009,9 @@ public: SourceLocation RBraceLoc) { return SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); } - + /// \brief Build a new designated initializer expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, @@ -1025,32 +1024,32 @@ public: move(Init)); if (Result.isInvalid()) return SemaRef.ExprError(); - + ArrayExprs.release(); return move(Result); } - + /// \brief Build a new value-initialized expression. - /// + /// /// By default, builds the implicit value initialization without performing /// any semantic analysis. Subclasses may override this routine to provide /// different behavior. OwningExprResult RebuildImplicitValueInitExpr(QualType T) { return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); } - + /// \brief Build a new \c va_arg expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, QualType T, SourceLocation RParenLoc) { - return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), + return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), RParenLoc); } /// \brief Build a new expression list in parentheses. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, @@ -1058,10 +1057,10 @@ public: SourceLocation RParenLoc) { return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs)); } - + /// \brief Build a new address-of-label expression. - /// - /// By default, performs semantic analysis, using the name of the label + /// + /// By default, performs semantic analysis, using the name of the label /// rather than attempting to map the label statement itself. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, @@ -1069,9 +1068,9 @@ public: LabelStmt *Label) { return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); } - + /// \brief Build a new GNU statement expression. - /// + /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, @@ -1079,7 +1078,7 @@ public: SourceLocation RParenLoc) { return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); } - + /// \brief Build a new __builtin_types_compatible_p expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1092,7 +1091,7 @@ public: T2.getAsOpaquePtr(), RParenLoc); } - + /// \brief Build a new __builtin_choose_expr expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1104,13 +1103,13 @@ public: move(Cond), move(LHS), move(RHS), RParenLoc); } - + /// \brief Build a new overloaded operator call expression. /// /// By default, performs semantic analysis to build the new expression. /// The semantic analysis provides the behavior of template instantiation, /// copying with transformations that turn what looks like an overloaded - /// operator call into a use of a builtin operator, performing + /// operator call into a use of a builtin operator, performing /// argument-dependent lookup, etc. Subclasses may override this routine to /// provide different behavior. OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, @@ -1118,12 +1117,12 @@ public: ExprArg Callee, ExprArg First, ExprArg Second); - - /// \brief Build a new C++ "named" cast expression, such as static_cast or + + /// \brief Build a new C++ "named" cast expression, such as static_cast or /// reinterpret_cast. /// /// By default, this routine dispatches to one of the more-specific routines - /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). + /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, Stmt::StmtClass Class, @@ -1135,34 +1134,34 @@ public: SourceLocation RParenLoc) { switch (Class) { case Stmt::CXXStaticCastExprClass: - return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T, - RAngleLoc, LParenLoc, + return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T, + RAngleLoc, LParenLoc, move(SubExpr), RParenLoc); case Stmt::CXXDynamicCastExprClass: - return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T, - RAngleLoc, LParenLoc, + return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T, + RAngleLoc, LParenLoc, move(SubExpr), RParenLoc); - + case Stmt::CXXReinterpretCastExprClass: - return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T, - RAngleLoc, LParenLoc, - move(SubExpr), + return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T, + RAngleLoc, LParenLoc, + move(SubExpr), RParenLoc); - + case Stmt::CXXConstCastExprClass: - return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T, - RAngleLoc, LParenLoc, + return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T, + RAngleLoc, LParenLoc, move(SubExpr), RParenLoc); - + default: assert(false && "Invalid C++ named cast"); break; } - + return getSema().ExprError(); } - + /// \brief Build a new C++ static_cast expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1175,7 +1174,7 @@ public: ExprArg SubExpr, SourceLocation RParenLoc) { return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast, - LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, + LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, LParenLoc, move(SubExpr), RParenLoc); } @@ -1191,7 +1190,7 @@ public: ExprArg SubExpr, SourceLocation RParenLoc) { return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast, - LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, + LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, LParenLoc, move(SubExpr), RParenLoc); } @@ -1223,10 +1222,10 @@ public: ExprArg SubExpr, SourceLocation RParenLoc) { return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast, - LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, + LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, LParenLoc, move(SubExpr), RParenLoc); } - + /// \brief Build a new C++ functional-style cast expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1241,10 +1240,10 @@ public: T.getAsOpaquePtr(), LParenLoc, Sema::MultiExprArg(getSema(), &Sub, 1), - /*CommaLocs=*/0, + /*CommaLocs=*/0, RParenLoc); } - + /// \brief Build a new C++ typeid(type) expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1253,10 +1252,10 @@ public: SourceLocation LParenLoc, QualType T, SourceLocation RParenLoc) { - return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, + return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, T.getAsOpaquePtr(), RParenLoc); } - + /// \brief Build a new C++ typeid(expr) expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1265,22 +1264,22 @@ public: SourceLocation LParenLoc, ExprArg Operand, SourceLocation RParenLoc) { - OwningExprResult Result + OwningExprResult Result = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), RParenLoc); if (Result.isInvalid()) return getSema().ExprError(); - + Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership return move(Result); - } - + } + /// \brief Build a new C++ "this" expression. /// /// By default, builds a new "this" expression without performing any - /// semantic analysis. Subclasses may override this routine to provide + /// semantic analysis. Subclasses may override this routine to provide /// different behavior. - OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, + OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, QualType ThisType) { return getSema().Owned( new (getSema().Context) CXXThisExpr(ThisLoc, ThisType)); @@ -1307,38 +1306,38 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, + OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, SourceLocation LParenLoc, QualType T, SourceLocation RParenLoc) { - return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), - T.getAsOpaquePtr(), LParenLoc, - MultiExprArg(getSema(), 0, 0), + return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), + T.getAsOpaquePtr(), LParenLoc, + MultiExprArg(getSema(), 0, 0), 0, RParenLoc); } - + /// \brief Build a new C++ conditional declaration expression. /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc, + OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc, SourceLocation EqLoc, VarDecl *Var) { return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(StartLoc, EqLoc, Var)); } - + /// \brief Build a new C++ "new" expression. /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, + OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, - bool ParenTypeId, + bool ParenTypeId, QualType AllocType, SourceLocation TypeLoc, SourceRange TypeRange, @@ -1346,7 +1345,7 @@ public: SourceLocation ConstructorLParen, MultiExprArg ConstructorArgs, SourceLocation ConstructorRParen) { - return getSema().BuildCXXNew(StartLoc, UseGlobal, + return getSema().BuildCXXNew(StartLoc, UseGlobal, PlacementLParen, move(PlacementArgs), PlacementRParen, @@ -1359,7 +1358,7 @@ public: move(ConstructorArgs), ConstructorRParen); } - + /// \brief Build a new C++ "delete" expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1371,7 +1370,7 @@ public: return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, move(Operand)); } - + /// \brief Build a new unary type trait expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1381,7 +1380,7 @@ public: SourceLocation LParenLoc, QualType T, SourceLocation RParenLoc) { - return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, + return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, T.getAsOpaquePtr(), RParenLoc); } @@ -1397,7 +1396,7 @@ public: CXXScopeSpec SS; SS.setRange(QualifierRange); SS.setScopeRep(NNS); - return getSema().ActOnDeclarationNameExpr(/*Scope=*/0, + return getSema().ActOnDeclarationNameExpr(/*Scope=*/0, Location, ND->getDeclName(), /*Trailing lparen=*/false, @@ -1405,7 +1404,7 @@ public: IsAddressOfOperand); } - /// \brief Build a new (previously unresolved) declaration reference + /// \brief Build a new (previously unresolved) declaration reference /// expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1418,7 +1417,7 @@ public: CXXScopeSpec SS; SS.setRange(QualifierRange); SS.setScopeRep(NNS); - return getSema().ActOnDeclarationNameExpr(/*Scope=*/0, + return getSema().ActOnDeclarationNameExpr(/*Scope=*/0, Location, Name, /*Trailing lparen=*/false, @@ -1492,7 +1491,7 @@ public: Commas, RParenLoc); } - + /// \brief Build a new member reference expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1511,7 +1510,7 @@ public: CXXScopeSpec SS; SS.setRange(QualifierRange); SS.setScopeRep(Qualifier); - + return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OperatorLoc, OpKind, MemberLoc, @@ -1540,30 +1539,30 @@ public: SourceLocation RAngleLoc) { OwningExprResult Base = move(BaseE); tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period; - + CXXScopeSpec SS; SS.setRange(QualifierRange); SS.setScopeRep(Qualifier); - + // FIXME: We're going to end up looking up the template based on its name, // twice! Also, duplicates part of Sema::ActOnMemberTemplateIdReferenceExpr. DeclarationName Name; if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl()) Name = ActualTemplate->getDeclName(); - else if (OverloadedFunctionDecl *Ovl + else if (OverloadedFunctionDecl *Ovl = Template.getAsOverloadedFunctionDecl()) Name = Ovl->getDeclName(); else Name = Template.getAsDependentTemplateName()->getName(); - - return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base), + + return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OperatorLoc, OpKind, TemplateNameLoc, Name, true, LAngleLoc, TemplateArgs, NumTemplateArgs, RAngleLoc, Sema::DeclPtrTy(), &SS); } - + /// \brief Build a new Objective-C @encode expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1573,7 +1572,7 @@ public: SourceLocation RParenLoc) { return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, RParenLoc)); - } + } /// \brief Build a new Objective-C protocol expression. /// @@ -1589,9 +1588,9 @@ public: AtLoc, ProtoLoc, LParenLoc, - RParenLoc)); + RParenLoc)); } - + /// \brief Build a new shuffle vector expression. /// /// By default, performs semantic analysis to build the new expression. @@ -1600,20 +1599,20 @@ public: MultiExprArg SubExprs, SourceLocation RParenLoc) { // Find the declaration for __builtin_shufflevector - const IdentifierInfo &Name + const IdentifierInfo &Name = SemaRef.Context.Idents.get("__builtin_shufflevector"); TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); - + // Build a reference to the __builtin_shufflevector builtin FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); - Expr *Callee + Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), BuiltinLoc, false, false); SemaRef.UsualUnaryConversions(Callee); - - // Build the CallExpr + + // Build the CallExpr unsigned NumSubExprs = SubExprs.size(); Expr **Subs = (Expr **)SubExprs.release(); CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, @@ -1621,14 +1620,14 @@ public: Builtin->getResultType(), RParenLoc); OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); - + // Type-check the __builtin_shufflevector expression. OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); if (Result.isInvalid()) return SemaRef.ExprError(); - + OwnedCall.release(); - return move(Result); + return move(Result); } }; @@ -1636,16 +1635,16 @@ template<typename Derived> Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { if (!S) return SemaRef.Owned(S); - + switch (S->getStmtClass()) { case Stmt::NoStmtClass: break; - + // Transform individual statement nodes #define STMT(Node, Parent) \ case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); #define EXPR(Node, Parent) #include "clang/AST/StmtNodes.def" - + // Transform expressions by calling TransformExpr. #define STMT(Node, Parent) #define EXPR(Node, Parent) case Stmt::Node##Class: @@ -1654,15 +1653,15 @@ Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); if (E.isInvalid()) return getSema().StmtError(); - + return getSema().Owned(E.takeAs<Stmt>()); } - } - + } + return SemaRef.Owned(S->Retain()); } - - + + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E, bool isAddressOfOperand) { @@ -1675,8 +1674,8 @@ Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E, #define EXPR(Node, Parent) \ case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); #include "clang/AST/StmtNodes.def" - } - + } + return SemaRef.Owned(E->Retain()); } @@ -1688,75 +1687,75 @@ TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, NamedDecl *FirstQualifierInScope) { if (!NNS) return 0; - + // Transform the prefix of this nested name specifier. NestedNameSpecifier *Prefix = NNS->getPrefix(); if (Prefix) { - Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, + Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, ObjectType, FirstQualifierInScope); if (!Prefix) return 0; - - // Clear out the object type and the first qualifier in scope; they only + + // Clear out the object type and the first qualifier in scope; they only // apply to the first element in the nested-name-specifier. ObjectType = QualType(); FirstQualifierInScope = 0; } - + switch (NNS->getKind()) { case NestedNameSpecifier::Identifier: - assert((Prefix || !ObjectType.isNull()) && + assert((Prefix || !ObjectType.isNull()) && "Identifier nested-name-specifier with no prefix or object type"); if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && ObjectType.isNull()) return NNS; - - return getDerived().RebuildNestedNameSpecifier(Prefix, Range, + + return getDerived().RebuildNestedNameSpecifier(Prefix, Range, *NNS->getAsIdentifier(), ObjectType, FirstQualifierInScope); - + case NestedNameSpecifier::Namespace: { - NamespaceDecl *NS + NamespaceDecl *NS = cast_or_null<NamespaceDecl>( getDerived().TransformDecl(NNS->getAsNamespace())); - if (!getDerived().AlwaysRebuild() && + if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && NS == NNS->getAsNamespace()) return NNS; - + return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); } - + case NestedNameSpecifier::Global: // There is no meaningful transformation that one could perform on the // global scope. return NNS; - + case NestedNameSpecifier::TypeSpecWithTemplate: case NestedNameSpecifier::TypeSpec: { QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); if (T.isNull()) return 0; - + if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && T == QualType(NNS->getAsType(), 0)) return NNS; - - return getDerived().RebuildNestedNameSpecifier(Prefix, Range, - NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, + + return getDerived().RebuildNestedNameSpecifier(Prefix, Range, + NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, T); } } - + // Required to silence a GCC warning - return 0; + return 0; } template<typename Derived> -DeclarationName +DeclarationName TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, SourceLocation Loc) { if (!Name) @@ -1770,7 +1769,7 @@ TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, case DeclarationName::CXXOperatorName: case DeclarationName::CXXUsingDirective: return Name; - + case DeclarationName::CXXConstructorName: case DeclarationName::CXXDestructorName: case DeclarationName::CXXConversionFunctionName: { @@ -1778,151 +1777,151 @@ TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, QualType T = getDerived().TransformType(Name.getCXXNameType()); if (T.isNull()) return DeclarationName(); - + return SemaRef.Context.DeclarationNames.getCXXSpecialName( - Name.getNameKind(), + Name.getNameKind(), SemaRef.Context.getCanonicalType(T)); - } } - + } + return DeclarationName(); } template<typename Derived> -TemplateName +TemplateName TreeTransform<Derived>::TransformTemplateName(TemplateName Name, QualType ObjectType) { if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { - NestedNameSpecifier *NNS + NestedNameSpecifier *NNS = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), /*FIXME:*/SourceRange(getDerived().getBaseLocation())); if (!NNS) return TemplateName(); - + if (TemplateDecl *Template = QTN->getTemplateDecl()) { - TemplateDecl *TransTemplate + TemplateDecl *TransTemplate = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); if (!TransTemplate) return TemplateName(); - + if (!getDerived().AlwaysRebuild() && NNS == QTN->getQualifier() && TransTemplate == Template) return Name; - + return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), TransTemplate); } - + OverloadedFunctionDecl *Ovl = QTN->getOverloadedFunctionDecl(); assert(Ovl && "Not a template name or an overload set?"); - OverloadedFunctionDecl *TransOvl + OverloadedFunctionDecl *TransOvl = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl)); if (!TransOvl) return TemplateName(); - + if (!getDerived().AlwaysRebuild() && NNS == QTN->getQualifier() && TransOvl == Ovl) return Name; - + return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), TransOvl); } - + if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { - NestedNameSpecifier *NNS + NestedNameSpecifier *NNS = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), /*FIXME:*/SourceRange(getDerived().getBaseLocation())); if (!NNS && DTN->getQualifier()) return TemplateName(); - + if (!getDerived().AlwaysRebuild() && NNS == DTN->getQualifier()) return Name; - + return getDerived().RebuildTemplateName(NNS, *DTN->getName(), ObjectType); } - + if (TemplateDecl *Template = Name.getAsTemplateDecl()) { - TemplateDecl *TransTemplate + TemplateDecl *TransTemplate = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); if (!TransTemplate) return TemplateName(); - + if (!getDerived().AlwaysRebuild() && TransTemplate == Template) return Name; - + return TemplateName(TransTemplate); } - + OverloadedFunctionDecl *Ovl = Name.getAsOverloadedFunctionDecl(); assert(Ovl && "Not a template name or an overload set?"); - OverloadedFunctionDecl *TransOvl + OverloadedFunctionDecl *TransOvl = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl)); if (!TransOvl) return TemplateName(); - + if (!getDerived().AlwaysRebuild() && TransOvl == Ovl) return Name; - + return TemplateName(TransOvl); } template<typename Derived> -TemplateArgument +TemplateArgument TreeTransform<Derived>::TransformTemplateArgument(const TemplateArgument &Arg) { switch (Arg.getKind()) { case TemplateArgument::Null: case TemplateArgument::Integral: return Arg; - + case TemplateArgument::Type: { QualType T = getDerived().TransformType(Arg.getAsType()); if (T.isNull()) return TemplateArgument(); return TemplateArgument(Arg.getLocation(), T); } - + case TemplateArgument::Declaration: { Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); if (!D) return TemplateArgument(); return TemplateArgument(Arg.getLocation(), D); } - + case TemplateArgument::Expression: { // Template argument expressions are not potentially evaluated. - EnterExpressionEvaluationContext Unevaluated(getSema(), + EnterExpressionEvaluationContext Unevaluated(getSema(), Action::Unevaluated); - + Sema::OwningExprResult E = getDerived().TransformExpr(Arg.getAsExpr()); if (E.isInvalid()) return TemplateArgument(); return TemplateArgument(E.takeAs<Expr>()); } - + case TemplateArgument::Pack: { llvm::SmallVector<TemplateArgument, 4> TransformedArgs; TransformedArgs.reserve(Arg.pack_size()); - for (TemplateArgument::pack_iterator A = Arg.pack_begin(), + for (TemplateArgument::pack_iterator A = Arg.pack_begin(), AEnd = Arg.pack_end(); A != AEnd; ++A) { TemplateArgument TA = getDerived().TransformTemplateArgument(*A); if (TA.isNull()) return TA; - + TransformedArgs.push_back(TA); } TemplateArgument Result; - Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), + Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), true); return Result; } } - + // Work around bogus GCC warning return TemplateArgument(); } @@ -1935,126 +1934,126 @@ template<typename Derived> QualType TreeTransform<Derived>::TransformType(QualType T) { if (getDerived().AlreadyTransformed(T)) return T; - + QualType Result; switch (T->getTypeClass()) { -#define ABSTRACT_TYPE(CLASS, PARENT) +#define ABSTRACT_TYPE(CLASS, PARENT) #define TYPE(CLASS, PARENT) \ case Type::CLASS: \ Result = getDerived().Transform##CLASS##Type( \ static_cast<CLASS##Type*>(T.getTypePtr())); \ break; -#include "clang/AST/TypeNodes.def" +#include "clang/AST/TypeNodes.def" } - + if (Result.isNull() || T == Result) return Result; - + return getDerived().AddTypeQualifiers(Result, T.getCVRQualifiers()); } - + template<typename Derived> -QualType +QualType TreeTransform<Derived>::AddTypeQualifiers(QualType T, unsigned CVRQualifiers) { if (CVRQualifiers && !T->isFunctionType() && !T->isReferenceType()) return T.getWithAdditionalQualifiers(CVRQualifiers); - + return T; } -template<typename Derived> -QualType TreeTransform<Derived>::TransformExtQualType(const ExtQualType *T) { +template<typename Derived> +QualType TreeTransform<Derived>::TransformExtQualType(const ExtQualType *T) { // FIXME: Implement - return QualType(T, 0); + return QualType(T, 0); } - + template<typename Derived> -QualType TreeTransform<Derived>::TransformBuiltinType(const BuiltinType *T) { +QualType TreeTransform<Derived>::TransformBuiltinType(const BuiltinType *T) { // Nothing to do - return QualType(T, 0); + return QualType(T, 0); } - -template<typename Derived> + +template<typename Derived> QualType TreeTransform<Derived>::TransformFixedWidthIntType( - const FixedWidthIntType *T) { + const FixedWidthIntType *T) { // FIXME: Implement - return QualType(T, 0); + return QualType(T, 0); } - + template<typename Derived> -QualType TreeTransform<Derived>::TransformComplexType(const ComplexType *T) { +QualType TreeTransform<Derived>::TransformComplexType(const ComplexType *T) { // FIXME: Implement - return QualType(T, 0); + return QualType(T, 0); } - -template<typename Derived> + +template<typename Derived> QualType TreeTransform<Derived>::TransformPointerType(const PointerType *T) { QualType PointeeType = getDerived().TransformType(T->getPointeeType()); if (PointeeType.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && PointeeType == T->getPointeeType()) return QualType(T, 0); return getDerived().RebuildPointerType(PointeeType); } - -template<typename Derived> -QualType -TreeTransform<Derived>::TransformBlockPointerType(const BlockPointerType *T) { + +template<typename Derived> +QualType +TreeTransform<Derived>::TransformBlockPointerType(const BlockPointerType *T) { QualType PointeeType = getDerived().TransformType(T->getPointeeType()); if (PointeeType.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && PointeeType == T->getPointeeType()) return QualType(T, 0); - + return getDerived().RebuildBlockPointerType(PointeeType); } -template<typename Derived> -QualType +template<typename Derived> +QualType TreeTransform<Derived>::TransformLValueReferenceType( - const LValueReferenceType *T) { + const LValueReferenceType *T) { QualType PointeeType = getDerived().TransformType(T->getPointeeType()); if (PointeeType.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && PointeeType == T->getPointeeType()) return QualType(T, 0); - + return getDerived().RebuildLValueReferenceType(PointeeType); } -template<typename Derived> -QualType +template<typename Derived> +QualType TreeTransform<Derived>::TransformRValueReferenceType( - const RValueReferenceType *T) { + const RValueReferenceType *T) { QualType PointeeType = getDerived().TransformType(T->getPointeeType()); if (PointeeType.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && PointeeType == T->getPointeeType()) return QualType(T, 0); - + return getDerived().RebuildRValueReferenceType(PointeeType); } - + template<typename Derived> -QualType -TreeTransform<Derived>::TransformMemberPointerType(const MemberPointerType *T) { +QualType +TreeTransform<Derived>::TransformMemberPointerType(const MemberPointerType *T) { QualType PointeeType = getDerived().TransformType(T->getPointeeType()); if (PointeeType.isNull()) return QualType(); - + QualType ClassType = getDerived().TransformType(QualType(T->getClass(), 0)); if (ClassType.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && PointeeType == T->getPointeeType() && ClassType == QualType(T->getClass(), 0)) @@ -2063,76 +2062,76 @@ TreeTransform<Derived>::TransformMemberPointerType(const MemberPointerType *T) { return getDerived().RebuildMemberPointerType(PointeeType, ClassType); } -template<typename Derived> -QualType -TreeTransform<Derived>::TransformConstantArrayType(const ConstantArrayType *T) { +template<typename Derived> +QualType +TreeTransform<Derived>::TransformConstantArrayType(const ConstantArrayType *T) { QualType ElementType = getDerived().TransformType(T->getElementType()); if (ElementType.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && ElementType == T->getElementType()) return QualType(T, 0); - - return getDerived().RebuildConstantArrayType(ElementType, + + return getDerived().RebuildConstantArrayType(ElementType, T->getSizeModifier(), T->getSize(), T->getIndexTypeQualifier()); } - + template<typename Derived> -QualType +QualType TreeTransform<Derived>::TransformConstantArrayWithExprType( - const ConstantArrayWithExprType *T) { + const ConstantArrayWithExprType *T) { QualType ElementType = getDerived().TransformType(T->getElementType()); if (ElementType.isNull()) return QualType(); - + // Array bounds are not potentially evaluated contexts EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); - + Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); if (Size.isInvalid()) return QualType(); - + if (!getDerived().AlwaysRebuild() && ElementType == T->getElementType() && Size.get() == T->getSizeExpr()) return QualType(T, 0); - - return getDerived().RebuildConstantArrayWithExprType(ElementType, + + return getDerived().RebuildConstantArrayWithExprType(ElementType, T->getSizeModifier(), T->getSize(), Size.takeAs<Expr>(), T->getIndexTypeQualifier(), T->getBracketsRange()); } - -template<typename Derived> -QualType + +template<typename Derived> +QualType TreeTransform<Derived>::TransformConstantArrayWithoutExprType( - const ConstantArrayWithoutExprType *T) { + const ConstantArrayWithoutExprType *T) { QualType ElementType = getDerived().TransformType(T->getElementType()); if (ElementType.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && ElementType == T->getElementType()) return QualType(T, 0); - - return getDerived().RebuildConstantArrayWithoutExprType(ElementType, + + return getDerived().RebuildConstantArrayWithoutExprType(ElementType, T->getSizeModifier(), T->getSize(), T->getIndexTypeQualifier()); } -template<typename Derived> +template<typename Derived> QualType TreeTransform<Derived>::TransformIncompleteArrayType( - const IncompleteArrayType *T) { + const IncompleteArrayType *T) { QualType ElementType = getDerived().TransformType(T->getElementType()); if (ElementType.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && ElementType == T->getElementType()) return QualType(T, 0); @@ -2141,91 +2140,91 @@ QualType TreeTransform<Derived>::TransformIncompleteArrayType( T->getSizeModifier(), T->getIndexTypeQualifier()); } - + template<typename Derived> QualType TreeTransform<Derived>::TransformVariableArrayType( - const VariableArrayType *T) { + const VariableArrayType *T) { QualType ElementType = getDerived().TransformType(T->getElementType()); if (ElementType.isNull()) return QualType(); - + // Array bounds are not potentially evaluated contexts EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); if (Size.isInvalid()) return QualType(); - + if (!getDerived().AlwaysRebuild() && ElementType == T->getElementType() && Size.get() == T->getSizeExpr()) { Size.take(); return QualType(T, 0); } - - return getDerived().RebuildVariableArrayType(ElementType, + + return getDerived().RebuildVariableArrayType(ElementType, T->getSizeModifier(), move(Size), T->getIndexTypeQualifier(), T->getBracketsRange()); } - -template<typename Derived> + +template<typename Derived> QualType TreeTransform<Derived>::TransformDependentSizedArrayType( - const DependentSizedArrayType *T) { + const DependentSizedArrayType *T) { QualType ElementType = getDerived().TransformType(T->getElementType()); if (ElementType.isNull()) return QualType(); - + // Array bounds are not potentially evaluated contexts EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); - + Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); if (Size.isInvalid()) return QualType(); - + if (!getDerived().AlwaysRebuild() && ElementType == T->getElementType() && Size.get() == T->getSizeExpr()) { Size.take(); return QualType(T, 0); } - - return getDerived().RebuildDependentSizedArrayType(ElementType, + + return getDerived().RebuildDependentSizedArrayType(ElementType, T->getSizeModifier(), move(Size), T->getIndexTypeQualifier(), T->getBracketsRange()); } - -template<typename Derived> + +template<typename Derived> QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( - const DependentSizedExtVectorType *T) { + const DependentSizedExtVectorType *T) { QualType ElementType = getDerived().TransformType(T->getElementType()); if (ElementType.isNull()) return QualType(); - + // Vector sizes are not potentially evaluated contexts EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); if (Size.isInvalid()) return QualType(); - + if (!getDerived().AlwaysRebuild() && ElementType == T->getElementType() && Size.get() == T->getSizeExpr()) { Size.take(); return QualType(T, 0); } - - return getDerived().RebuildDependentSizedExtVectorType(ElementType, + + return getDerived().RebuildDependentSizedExtVectorType(ElementType, move(Size), T->getAttributeLoc()); } - -template<typename Derived> -QualType TreeTransform<Derived>::TransformVectorType(const VectorType *T) { + +template<typename Derived> +QualType TreeTransform<Derived>::TransformVectorType(const VectorType *T) { QualType ElementType = getDerived().TransformType(T->getElementType()); if (ElementType.isNull()) return QualType(); @@ -2233,80 +2232,80 @@ QualType TreeTransform<Derived>::TransformVectorType(const VectorType *T) { if (!getDerived().AlwaysRebuild() && ElementType == T->getElementType()) return QualType(T, 0); - + return getDerived().RebuildVectorType(ElementType, T->getNumElements()); } - -template<typename Derived> -QualType -TreeTransform<Derived>::TransformExtVectorType(const ExtVectorType *T) { + +template<typename Derived> +QualType +TreeTransform<Derived>::TransformExtVectorType(const ExtVectorType *T) { QualType ElementType = getDerived().TransformType(T->getElementType()); if (ElementType.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && ElementType == T->getElementType()) return QualType(T, 0); - + return getDerived().RebuildExtVectorType(ElementType, T->getNumElements(), /*FIXME*/SourceLocation()); } -template<typename Derived> +template<typename Derived> QualType TreeTransform<Derived>::TransformFunctionProtoType( - const FunctionProtoType *T) { + const FunctionProtoType *T) { QualType ResultType = getDerived().TransformType(T->getResultType()); if (ResultType.isNull()) return QualType(); - + llvm::SmallVector<QualType, 4> ParamTypes; for (FunctionProtoType::arg_type_iterator Param = T->arg_type_begin(), - ParamEnd = T->arg_type_end(); + ParamEnd = T->arg_type_end(); Param != ParamEnd; ++Param) { QualType P = getDerived().TransformType(*Param); if (P.isNull()) return QualType(); - + ParamTypes.push_back(P); } - + if (!getDerived().AlwaysRebuild() && ResultType == T->getResultType() && std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) return QualType(T, 0); - - return getDerived().RebuildFunctionProtoType(ResultType, ParamTypes.data(), + + return getDerived().RebuildFunctionProtoType(ResultType, ParamTypes.data(), ParamTypes.size(), T->isVariadic(), T->getTypeQuals()); } - + template<typename Derived> QualType TreeTransform<Derived>::TransformFunctionNoProtoType( - const FunctionNoProtoType *T) { + const FunctionNoProtoType *T) { // FIXME: Implement - return QualType(T, 0); + return QualType(T, 0); } - + template<typename Derived> -QualType TreeTransform<Derived>::TransformTypedefType(const TypedefType *T) { +QualType TreeTransform<Derived>::TransformTypedefType(const TypedefType *T) { TypedefDecl *Typedef = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); if (!Typedef) return QualType(); - + if (!getDerived().AlwaysRebuild() && Typedef == T->getDecl()) return QualType(T, 0); - + return getDerived().RebuildTypedefType(Typedef); } - + template<typename Derived> QualType TreeTransform<Derived>::TransformTypeOfExprType( - const TypeOfExprType *T) { + const TypeOfExprType *T) { // typeof expressions are not potentially evaluated contexts EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); - + Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); if (E.isInvalid()) return QualType(); @@ -2316,66 +2315,66 @@ QualType TreeTransform<Derived>::TransformTypeOfExprType( E.take(); return QualType(T, 0); } - + return getDerived().RebuildTypeOfExprType(move(E)); } - -template<typename Derived> -QualType TreeTransform<Derived>::TransformTypeOfType(const TypeOfType *T) { + +template<typename Derived> +QualType TreeTransform<Derived>::TransformTypeOfType(const TypeOfType *T) { QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); if (Underlying.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && Underlying == T->getUnderlyingType()) return QualType(T, 0); - + return getDerived().RebuildTypeOfType(Underlying); } - -template<typename Derived> -QualType TreeTransform<Derived>::TransformDecltypeType(const DecltypeType *T) { + +template<typename Derived> +QualType TreeTransform<Derived>::TransformDecltypeType(const DecltypeType *T) { // decltype expressions are not potentially evaluated contexts EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); - + Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); if (E.isInvalid()) return QualType(); - + if (!getDerived().AlwaysRebuild() && E.get() == T->getUnderlyingExpr()) { E.take(); return QualType(T, 0); } - + return getDerived().RebuildDecltypeType(move(E)); } template<typename Derived> -QualType TreeTransform<Derived>::TransformRecordType(const RecordType *T) { +QualType TreeTransform<Derived>::TransformRecordType(const RecordType *T) { RecordDecl *Record = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); if (!Record) return QualType(); - + if (!getDerived().AlwaysRebuild() && Record == T->getDecl()) return QualType(T, 0); - + return getDerived().RebuildRecordType(Record); } - -template<typename Derived> -QualType TreeTransform<Derived>::TransformEnumType(const EnumType *T) { + +template<typename Derived> +QualType TreeTransform<Derived>::TransformEnumType(const EnumType *T) { EnumDecl *Enum = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); if (!Enum) return QualType(); - + if (!getDerived().AlwaysRebuild() && Enum == T->getDecl()) return QualType(T, 0); - + return getDerived().RebuildEnumType(Enum); } @@ -2385,30 +2384,30 @@ QualType TreeTransform<Derived>::TransformElaboratedType( QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); if (Underlying.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && Underlying == T->getUnderlyingType()) return QualType(T, 0); - + return getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); } - - + + template<typename Derived> QualType TreeTransform<Derived>::TransformTemplateTypeParmType( - const TemplateTypeParmType *T) { + const TemplateTypeParmType *T) { // Nothing to do - return QualType(T, 0); + return QualType(T, 0); } -template<typename Derived> +template<typename Derived> QualType TreeTransform<Derived>::TransformTemplateSpecializationType( - const TemplateSpecializationType *T) { - TemplateName Template + const TemplateSpecializationType *T) { + TemplateName Template = getDerived().TransformTemplateName(T->getTemplateName()); if (Template.isNull()) return QualType(); - + llvm::SmallVector<TemplateArgument, 4> NewTemplateArgs; NewTemplateArgs.reserve(T->getNumArgs()); for (TemplateSpecializationType::iterator Arg = T->begin(), ArgEnd = T->end(); @@ -2416,20 +2415,20 @@ QualType TreeTransform<Derived>::TransformTemplateSpecializationType( TemplateArgument NewArg = getDerived().TransformTemplateArgument(*Arg); if (NewArg.isNull()) return QualType(); - + NewTemplateArgs.push_back(NewArg); } - + // FIXME: early abort if all of the template arguments and such are the // same. - + // FIXME: We're missing the locations of the template name, '<', and '>'. return getDerived().RebuildTemplateSpecializationType(Template, NewTemplateArgs.data(), NewTemplateArgs.size()); } - -template<typename Derived> + +template<typename Derived> QualType TreeTransform<Derived>::TransformQualifiedNameType( const QualifiedNameType *T) { NestedNameSpecifier *NNS @@ -2437,11 +2436,11 @@ QualType TreeTransform<Derived>::TransformQualifiedNameType( SourceRange()); if (!NNS) return QualType(); - + QualType Named = getDerived().TransformType(T->getNamedType()); if (Named.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && NNS == T->getQualifier() && Named == T->getNamedType()) @@ -2449,44 +2448,44 @@ QualType TreeTransform<Derived>::TransformQualifiedNameType( return getDerived().RebuildQualifiedNameType(NNS, Named); } - -template<typename Derived> + +template<typename Derived> QualType TreeTransform<Derived>::TransformTypenameType(const TypenameType *T) { NestedNameSpecifier *NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SourceRange(/*FIXME:*/getDerived().getBaseLocation())); if (!NNS) return QualType(); - + if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { - QualType NewTemplateId + QualType NewTemplateId = getDerived().TransformType(QualType(TemplateId, 0)); if (NewTemplateId.isNull()) return QualType(); - + if (!getDerived().AlwaysRebuild() && NNS == T->getQualifier() && NewTemplateId == QualType(TemplateId, 0)) return QualType(T, 0); - + return getDerived().RebuildTypenameType(NNS, NewTemplateId); } return getDerived().RebuildTypenameType(NNS, T->getIdentifier()); } - + template<typename Derived> QualType TreeTransform<Derived>::TransformObjCInterfaceType( - const ObjCInterfaceType *T) { + const ObjCInterfaceType *T) { // FIXME: Implement - return QualType(T, 0); + return QualType(T, 0); } - -template<typename Derived> + +template<typename Derived> QualType TreeTransform<Derived>::TransformObjCObjectPointerType( - const ObjCObjectPointerType *T) { + const ObjCObjectPointerType *T) { // FIXME: Implement - return QualType(T, 0); + return QualType(T, 0); } //===----------------------------------------------------------------------===// @@ -2494,8 +2493,8 @@ QualType TreeTransform<Derived>::TransformObjCObjectPointerType( //===----------------------------------------------------------------------===// template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { - return SemaRef.Owned(S->Retain()); +TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { + return SemaRef.Owned(S->Retain()); } template<typename Derived> @@ -2506,7 +2505,7 @@ TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, +TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr) { bool SubStmtChanged = false; ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); @@ -2515,37 +2514,37 @@ TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, OwningStmtResult Result = getDerived().TransformStmt(*B); if (Result.isInvalid()) return getSema().StmtError(); - + SubStmtChanged = SubStmtChanged || Result.get() != *B; Statements.push_back(Result.takeAs<Stmt>()); } - + if (!getDerived().AlwaysRebuild() && !SubStmtChanged) - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); return getDerived().RebuildCompoundStmt(S->getLBracLoc(), move_arg(Statements), S->getRBracLoc(), IsStmtExpr); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { +TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { // The case value expressions are not potentially evaluated. EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); - + // Transform the left-hand case value. OwningExprResult LHS = getDerived().TransformExpr(S->getLHS()); if (LHS.isInvalid()) return SemaRef.StmtError(); - + // Transform the right-hand case value (for the GNU case-range extension). OwningExprResult RHS = getDerived().TransformExpr(S->getRHS()); if (RHS.isInvalid()) return SemaRef.StmtError(); - + // Build the case statement. // Case statements are always rebuilt so that they will attached to their // transformed switch statement. @@ -2556,118 +2555,118 @@ TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { S->getColonLoc()); if (Case.isInvalid()) return SemaRef.StmtError(); - + // Transform the statement following the case OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); if (SubStmt.isInvalid()) return SemaRef.StmtError(); - + // Attach the body to the case statement return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); } template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { +TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { // Transform the statement following the default case OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); if (SubStmt.isInvalid()) return SemaRef.StmtError(); - + // Default statements are always rebuilt return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), move(SubStmt)); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { +TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); if (SubStmt.isInvalid()) return SemaRef.StmtError(); - + // FIXME: Pass the real colon location in. SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, move(SubStmt)); } - + template<typename Derived> -Sema::OwningStmtResult -TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { +Sema::OwningStmtResult +TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { // Transform the condition OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); if (Cond.isInvalid()) return SemaRef.StmtError(); - + Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); - + // Transform the "then" branch. OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); if (Then.isInvalid()) return SemaRef.StmtError(); - + // Transform the "else" branch. OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); if (Else.isInvalid()) return SemaRef.StmtError(); - + if (!getDerived().AlwaysRebuild() && FullCond->get() == S->getCond() && Then.get() == S->getThen() && Else.get() == S->getElse()) - return SemaRef.Owned(S->Retain()); - + return SemaRef.Owned(S->Retain()); + return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then), - S->getElseLoc(), move(Else)); + S->getElseLoc(), move(Else)); } template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { +TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { // Transform the condition. OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); if (Cond.isInvalid()) return SemaRef.StmtError(); - + // Rebuild the switch statement. OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond)); if (Switch.isInvalid()) return SemaRef.StmtError(); - + // Transform the body of the switch statement. OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); if (Body.isInvalid()) return SemaRef.StmtError(); - + // Complete the switch statement. return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), move(Body)); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { +TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { // Transform the condition OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); if (Cond.isInvalid()) return SemaRef.StmtError(); - + Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); - + // Transform the body OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); if (Body.isInvalid()) return SemaRef.StmtError(); - + if (!getDerived().AlwaysRebuild() && FullCond->get() == S->getCond() && Body.get() == S->getBody()) - return SemaRef.Owned(S->Retain()); - + return SemaRef.Owned(S->Retain()); + return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body)); } - + template<typename Derived> Sema::OwningStmtResult TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { @@ -2675,75 +2674,75 @@ TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); if (Cond.isInvalid()) return SemaRef.StmtError(); - + // Transform the body OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); if (Body.isInvalid()) return SemaRef.StmtError(); - + if (!getDerived().AlwaysRebuild() && Cond.get() == S->getCond() && Body.get() == S->getBody()) - return SemaRef.Owned(S->Retain()); - + return SemaRef.Owned(S->Retain()); + return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), /*FIXME:*/S->getWhileLoc(), move(Cond), S->getRParenLoc()); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformForStmt(ForStmt *S) { +TreeTransform<Derived>::TransformForStmt(ForStmt *S) { // Transform the initialization statement OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); if (Init.isInvalid()) return SemaRef.StmtError(); - + // Transform the condition OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); if (Cond.isInvalid()) return SemaRef.StmtError(); - + // Transform the increment OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); if (Inc.isInvalid()) return SemaRef.StmtError(); - + // Transform the body OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); if (Body.isInvalid()) return SemaRef.StmtError(); - + if (!getDerived().AlwaysRebuild() && Init.get() == S->getInit() && Cond.get() == S->getCond() && Inc.get() == S->getInc() && Body.get() == S->getBody()) - return SemaRef.Owned(S->Retain()); - + return SemaRef.Owned(S->Retain()); + return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), move(Init), move(Cond), move(Inc), S->getRParenLoc(), move(Body)); } template<typename Derived> -Sema::OwningStmtResult -TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { +Sema::OwningStmtResult +TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { // Goto statements must always be rebuilt, to resolve the label. - return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), + return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), S->getLabel()); } template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { +TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); if (Target.isInvalid()) return SemaRef.StmtError(); - + if (!getDerived().AlwaysRebuild() && Target.get() == S->getTarget()) - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), move(Target)); @@ -2751,31 +2750,31 @@ TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { - return SemaRef.Owned(S->Retain()); +TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { + return SemaRef.Owned(S->Retain()); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { - return SemaRef.Owned(S->Retain()); +TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { + return SemaRef.Owned(S->Retain()); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { +TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); if (Result.isInvalid()) return SemaRef.StmtError(); - // FIXME: We always rebuild the return statement because there is no way + // FIXME: We always rebuild the return statement because there is no way // to tell whether the return type of the function has changed. return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { +TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { bool DeclChanged = false; llvm::SmallVector<Decl *, 4> Decls; for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); @@ -2783,25 +2782,25 @@ TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { Decl *Transformed = getDerived().TransformDefinition(*D); if (!Transformed) return SemaRef.StmtError(); - + if (Transformed != *D) DeclChanged = true; - + Decls.push_back(Transformed); } - + if (!getDerived().AlwaysRebuild() && !DeclChanged) - return SemaRef.Owned(S->Retain()); - - return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), + return SemaRef.Owned(S->Retain()); + + return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), S->getStartLoc(), S->getEndLoc()); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { +TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { assert(false && "SwitchCase is abstract and cannot be transformed"); - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); } template<typename Derived> @@ -2809,58 +2808,58 @@ Sema::OwningStmtResult TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { // FIXME: Implement! assert(false && "Inline assembly cannot be transformed"); - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); } template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { +TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { // FIXME: Implement this assert(false && "Cannot transform an Objective-C @try statement"); - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { +TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { // FIXME: Implement this assert(false && "Cannot transform an Objective-C @catch statement"); return SemaRef.Owned(S->Retain()); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { +TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { // FIXME: Implement this assert(false && "Cannot transform an Objective-C @finally statement"); - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); } - + template<typename Derived> Sema::OwningStmtResult -TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { +TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { // FIXME: Implement this assert(false && "Cannot transform an Objective-C @throw statement"); - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); } - + template<typename Derived> Sema::OwningStmtResult TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( - ObjCAtSynchronizedStmt *S) { + ObjCAtSynchronizedStmt *S) { // FIXME: Implement this assert(false && "Cannot transform an Objective-C @synchronized statement"); - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); } template<typename Derived> Sema::OwningStmtResult TreeTransform<Derived>::TransformObjCForCollectionStmt( - ObjCForCollectionStmt *S) { + ObjCForCollectionStmt *S) { // FIXME: Implement this assert(false && "Cannot transform an Objective-C for-each statement"); - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); } @@ -2877,7 +2876,7 @@ TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { QualType T = getDerived().TransformType(ExceptionDecl->getType()); if (T.isNull()) return SemaRef.StmtError(); - + Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, ExceptionDecl->getDeclaratorInfo(), @@ -2891,7 +2890,7 @@ TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { return SemaRef.StmtError(); } } - + // Transform the actual exception handler. OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); if (Handler.isInvalid()) { @@ -2899,191 +2898,191 @@ TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { Var->Destroy(SemaRef.Context); return SemaRef.StmtError(); } - + if (!getDerived().AlwaysRebuild() && !Var && Handler.get() == S->getHandlerBlock()) - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, move(Handler)); } - + template<typename Derived> Sema::OwningStmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { // Transform the try block itself. - OwningStmtResult TryBlock + OwningStmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); if (TryBlock.isInvalid()) return SemaRef.StmtError(); - + // Transform the handlers. bool HandlerChanged = false; ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { - OwningStmtResult Handler + OwningStmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); if (Handler.isInvalid()) return SemaRef.StmtError(); - + HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); Handlers.push_back(Handler.takeAs<Stmt>()); } - + if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && !HandlerChanged) - return SemaRef.Owned(S->Retain()); + return SemaRef.Owned(S->Retain()); return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), - move_arg(Handlers)); + move_arg(Handlers)); } - + //===----------------------------------------------------------------------===// // Expression transformation //===----------------------------------------------------------------------===// -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { - return SemaRef.Owned(E->Retain()); -} - -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { - NamedDecl *ND +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { + return SemaRef.Owned(E->Retain()); +} + +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { + NamedDecl *ND = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl())); if (!ND) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && ND == E->getDecl()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildDeclRefExpr(ND, E->getLocation()); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { - return SemaRef.Owned(E->Retain()); +Sema::OwningExprResult +TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { + return SemaRef.Owned(E->Retain()); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { - return SemaRef.Owned(E->Retain()); +Sema::OwningExprResult +TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { + return SemaRef.Owned(E->Retain()); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { - return SemaRef.Owned(E->Retain()); +Sema::OwningExprResult +TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { + return SemaRef.Owned(E->Retain()); } - -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { - return SemaRef.Owned(E->Retain()); + +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { + return SemaRef.Owned(E->Retain()); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { - return SemaRef.Owned(E->Retain()); +Sema::OwningExprResult +TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { + return SemaRef.Owned(E->Retain()); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { +Sema::OwningExprResult +TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) - return SemaRef.Owned(E->Retain()); - - return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), + return SemaRef.Owned(E->Retain()); + + return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), E->getRParen()); } -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), E->getOpcode(), move(SubExpr)); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { +Sema::OwningExprResult +TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { if (E->isArgumentType()) { QualType T = getDerived().TransformType(E->getArgumentType()); if (T.isNull()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && T == E->getArgumentType()) return SemaRef.Owned(E->Retain()); - - return getDerived().RebuildSizeOfAlignOf(T, E->getOperatorLoc(), - E->isSizeOf(), + + return getDerived().RebuildSizeOfAlignOf(T, E->getOperatorLoc(), + E->isSizeOf(), E->getSourceRange()); } - + Sema::OwningExprResult SubExpr(SemaRef); - { + { // C++0x [expr.sizeof]p1: // The operand is either an expression, which is an unevaluated operand // [...] EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); - + SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) return SemaRef.Owned(E->Retain()); } - + return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), E->isSizeOf(), E->getSourceRange()); } - + template<typename Derived> -Sema::OwningExprResult +Sema::OwningExprResult TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); if (LHS.isInvalid()) return SemaRef.ExprError(); - + OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); if (RHS.isInvalid()) return SemaRef.ExprError(); - - + + if (!getDerived().AlwaysRebuild() && LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) return SemaRef.Owned(E->Retain()); - + return getDerived().RebuildArraySubscriptExpr(move(LHS), /*FIXME:*/E->getLHS()->getLocStart(), move(RHS), E->getRBracketLoc()); } - -template<typename Derived> -Sema::OwningExprResult + +template<typename Derived> +Sema::OwningExprResult TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { // Transform the callee. OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); @@ -3098,55 +3097,55 @@ TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); if (Arg.isInvalid()) return SemaRef.ExprError(); - + // FIXME: Wrong source location information for the ','. FakeCommaLocs.push_back( SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); - - ArgChanged = ArgChanged || Arg.get() != E->getArg(I); + + ArgChanged = ArgChanged || Arg.get() != E->getArg(I); Args.push_back(Arg.takeAs<Expr>()); } - + if (!getDerived().AlwaysRebuild() && Callee.get() == E->getCallee() && !ArgChanged) return SemaRef.Owned(E->Retain()); - + // FIXME: Wrong source location information for the '('. - SourceLocation FakeLParenLoc + SourceLocation FakeLParenLoc = ((Expr *)Callee.get())->getSourceRange().getBegin(); return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, move_arg(Args), FakeCommaLocs.data(), E->getRParenLoc()); } - -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { + +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { OwningExprResult Base = getDerived().TransformExpr(E->getBase()); if (Base.isInvalid()) return SemaRef.ExprError(); - + NestedNameSpecifier *Qualifier = 0; if (E->hasQualifier()) { - Qualifier + Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), E->getQualifierRange()); if (Qualifier == 0) return SemaRef.ExprError(); } - - NamedDecl *Member + + NamedDecl *Member = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl())); if (!Member) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && Qualifier == E->getQualifier() && Member == E->getMemberDecl()) - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); // FIXME: Bogus source location for the operator SourceLocation FakeOperatorLoc @@ -3157,208 +3156,208 @@ TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { Qualifier, E->getQualifierRange(), E->getMemberLoc(), - Member); + Member); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformCastExpr(CastExpr *E) { +Sema::OwningExprResult +TreeTransform<Derived>::TransformCastExpr(CastExpr *E) { assert(false && "Cannot transform abstract class"); - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } - -template<typename Derived> + +template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { +TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); if (LHS.isInvalid()) return SemaRef.ExprError(); - + OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); if (RHS.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), move(LHS), move(RHS)); } -template<typename Derived> +template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCompoundAssignOperator( CompoundAssignOperator *E) { return getDerived().TransformBinaryOperator(E); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { +Sema::OwningExprResult +TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); if (Cond.isInvalid()) return SemaRef.ExprError(); - + OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); if (LHS.isInvalid()) return SemaRef.ExprError(); - + OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); if (RHS.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && Cond.get() == E->getCond() && LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) return SemaRef.Owned(E->Retain()); - - return getDerived().RebuildConditionalOperator(move(Cond), + + return getDerived().RebuildConditionalOperator(move(Cond), E->getQuestionLoc(), - move(LHS), + move(LHS), E->getColonLoc(), move(RHS)); } - -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { + +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { QualType T = getDerived().TransformType(E->getType()); if (T.isNull()) return SemaRef.ExprError(); - + OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && T == E->getType() && SubExpr.get() == E->getSubExpr()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(), - move(SubExpr), + move(SubExpr), E->isLvalueCast()); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) { +Sema::OwningExprResult +TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) { assert(false && "Cannot transform abstract class"); - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { +TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { QualType T; { // FIXME: Source location isn't quite accurate. - SourceLocation TypeStartLoc + SourceLocation TypeStartLoc = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); - + T = getDerived().TransformType(E->getTypeAsWritten()); if (T.isNull()) return SemaRef.ExprError(); } - + OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && T == E->getTypeAsWritten() && SubExpr.get() == E->getSubExpr()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T, E->getRParenLoc(), move(SubExpr)); } - + template<typename Derived> -Sema::OwningExprResult +Sema::OwningExprResult TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { QualType T; { // FIXME: Source location isn't quite accurate. - SourceLocation FakeTypeLoc + SourceLocation FakeTypeLoc = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); - + T = getDerived().TransformType(E->getType()); if (T.isNull()) return SemaRef.ExprError(); } - + OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); if (Init.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && T == E->getType() && Init.get() == E->getInitializer()) - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, /*FIXME:*/E->getInitializer()->getLocEnd(), move(Init)); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { +TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { OwningExprResult Base = getDerived().TransformExpr(E->getBase()); if (Base.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + // FIXME: Bad source location - SourceLocation FakeOperatorLoc + SourceLocation FakeOperatorLoc = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, E->getAccessorLoc(), E->getAccessor()); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { +Sema::OwningExprResult +TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { bool InitChanged = false; - + ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); if (Init.isInvalid()) return SemaRef.ExprError(); - + InitChanged = InitChanged || Init.get() != E->getInit(I); Inits.push_back(Init.takeAs<Expr>()); } - + if (!getDerived().AlwaysRebuild() && !InitChanged) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), E->getRBraceLoc()); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { +TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { Designation Desig; - + // transform the initializer value OwningExprResult Init = getDerived().TransformExpr(E->getInit()); if (Init.isInvalid()) return SemaRef.ExprError(); - + // transform the designators. ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); bool ExprChanged = false; @@ -3371,73 +3370,73 @@ TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { D->getFieldLoc())); continue; } - + if (D->isArrayDesignator()) { OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); if (Index.isInvalid()) return SemaRef.ExprError(); - - Desig.AddDesignator(Designator::getArray(Index.get(), + + Desig.AddDesignator(Designator::getArray(Index.get(), D->getLBracketLoc())); - + ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); ArrayExprs.push_back(Index.release()); continue; } - + assert(D->isArrayRangeDesignator() && "New kind of designator?"); - OwningExprResult Start + OwningExprResult Start = getDerived().TransformExpr(E->getArrayRangeStart(*D)); if (Start.isInvalid()) return SemaRef.ExprError(); - + OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); if (End.isInvalid()) return SemaRef.ExprError(); - - Desig.AddDesignator(Designator::getArrayRange(Start.get(), + + Desig.AddDesignator(Designator::getArrayRange(Start.get(), End.get(), D->getLBracketLoc(), D->getEllipsisLoc())); - + ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || End.get() != E->getArrayRangeEnd(*D); - + ArrayExprs.push_back(Start.release()); ArrayExprs.push_back(End.release()); } - + if (!getDerived().AlwaysRebuild() && Init.get() == E->getInit() && !ExprChanged) return SemaRef.Owned(E->Retain()); - + return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), E->getEqualOrColonLoc(), E->usesGNUSyntax(), move(Init)); } - + template<typename Derived> -Sema::OwningExprResult +Sema::OwningExprResult TreeTransform<Derived>::TransformImplicitValueInitExpr( - ImplicitValueInitExpr *E) { + ImplicitValueInitExpr *E) { QualType T = getDerived().TransformType(E->getType()); if (T.isNull()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && T == E->getType()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildImplicitValueInitExpr(T); } - + template<typename Derived> -Sema::OwningExprResult +Sema::OwningExprResult TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { // FIXME: Do we want the type as written? QualType T; - + { // FIXME: Source location isn't quite accurate. TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); @@ -3445,22 +3444,22 @@ TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { if (T.isNull()) return SemaRef.ExprError(); } - + OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && T == E->getType() && SubExpr.get() == E->getSubExpr()) return SemaRef.Owned(E->Retain()); - + return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), T, E->getRParenLoc()); } template<typename Derived> -Sema::OwningExprResult +Sema::OwningExprResult TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { bool ArgumentChanged = false; ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); @@ -3468,16 +3467,16 @@ TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); if (Init.isInvalid()) return SemaRef.ExprError(); - + ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); Inits.push_back(Init.takeAs<Expr>()); } - + return getDerived().RebuildParenListExpr(E->getLParenLoc(), move_arg(Inits), E->getRParenLoc()); } - + /// \brief Transform an address-of-label expression. /// /// By default, the transformation of an address-of-label expression always @@ -3485,39 +3484,39 @@ TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { /// the corresponding label statement by semantic analysis. template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { +TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel()); } - -template<typename Derived> + +template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { - OwningStmtResult SubStmt + OwningStmtResult SubStmt = getDerived().TransformCompoundStmt(E->getSubStmt(), true); if (SubStmt.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && SubStmt.get() == E->getSubStmt()) return SemaRef.Owned(E->Retain()); - - return getDerived().RebuildStmtExpr(E->getLParenLoc(), + + return getDerived().RebuildStmtExpr(E->getLParenLoc(), move(SubStmt), E->getRParenLoc()); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { +TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { QualType T1, T2; { // FIXME: Source location isn't quite accurate. TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); - + T1 = getDerived().TransformType(E->getArgType1()); if (T1.isNull()) return SemaRef.ExprError(); - + T2 = getDerived().TransformType(E->getArgType2()); if (T2.isNull()) return SemaRef.ExprError(); @@ -3526,42 +3525,42 @@ TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { if (!getDerived().AlwaysRebuild() && T1 == E->getArgType1() && T2 == E->getArgType2()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), T1, T2, E->getRParenLoc()); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { +TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); if (Cond.isInvalid()) return SemaRef.ExprError(); - + OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); if (LHS.isInvalid()) return SemaRef.ExprError(); - + OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); if (RHS.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && Cond.get() == E->getCond() && LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), move(Cond), move(LHS), move(RHS), E->getRParenLoc()); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { - return SemaRef.Owned(E->Retain()); +Sema::OwningExprResult +TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { + return SemaRef.Owned(E->Retain()); } template<typename Derived> @@ -3570,7 +3569,7 @@ TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); if (Callee.isInvalid()) return SemaRef.ExprError(); - + OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); if (First.isInvalid()) return SemaRef.ExprError(); @@ -3581,59 +3580,59 @@ TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { if (Second.isInvalid()) return SemaRef.ExprError(); } - + if (!getDerived().AlwaysRebuild() && Callee.get() == E->getCallee() && First.get() == E->getArg(0) && - (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) - return SemaRef.Owned(E->Retain()); - + (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), E->getOperatorLoc(), - move(Callee), + move(Callee), move(First), move(Second)); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { +TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { return getDerived().TransformCallExpr(E); } - + template<typename Derived> -Sema::OwningExprResult +Sema::OwningExprResult TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { QualType ExplicitTy; { // FIXME: Source location isn't quite accurate. - SourceLocation TypeStartLoc + SourceLocation TypeStartLoc = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); - + ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); if (ExplicitTy.isNull()) return SemaRef.ExprError(); } - + OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && ExplicitTy == E->getTypeAsWritten() && SubExpr.get() == E->getSubExpr()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + // FIXME: Poor source location information here. - SourceLocation FakeLAngleLoc + SourceLocation FakeLAngleLoc = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); SourceLocation FakeRParenLoc = SemaRef.PP.getLocForEndOfToken( E->getSubExpr()->getSourceRange().getEnd()); return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), - E->getStmtClass(), + E->getStmtClass(), FakeLAngleLoc, ExplicitTy, FakeRAngleLoc, @@ -3641,54 +3640,54 @@ TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { move(SubExpr), FakeRParenLoc); } - + template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { +Sema::OwningExprResult +TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { return getDerived().TransformCXXNamedCastExpr(E); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { +TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { return getDerived().TransformCXXNamedCastExpr(E); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXReinterpretCastExpr( - CXXReinterpretCastExpr *E) { + CXXReinterpretCastExpr *E) { return getDerived().TransformCXXNamedCastExpr(E); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { +TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { return getDerived().TransformCXXNamedCastExpr(E); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXFunctionalCastExpr( - CXXFunctionalCastExpr *E) { + CXXFunctionalCastExpr *E) { QualType ExplicitTy; { TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); - + ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); if (ExplicitTy.isNull()) return SemaRef.ExprError(); } - + OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && ExplicitTy == E->getTypeAsWritten() && SubExpr.get() == E->getSubExpr()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + // FIXME: The end of the type's source range is wrong return getDerived().RebuildCXXFunctionalCastExpr( /*FIXME:*/SourceRange(E->getTypeBeginLoc()), @@ -3697,41 +3696,41 @@ TreeTransform<Derived>::TransformCXXFunctionalCastExpr( move(SubExpr), E->getRParenLoc()); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { +TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { if (E->isTypeOperand()) { TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); - + QualType T = getDerived().TransformType(E->getTypeOperand()); if (T.isNull()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && T == E->getTypeOperand()) return SemaRef.Owned(E->Retain()); - + return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), /*FIXME:*/E->getLocStart(), T, E->getLocEnd()); } - + // We don't know whether the expression is potentially evaluated until // after we perform semantic analysis, so the expression is potentially // potentially evaluated. - EnterExpressionEvaluationContext Unevaluated(SemaRef, + EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::PotentiallyPotentiallyEvaluated); - + OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getExprOperand()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), /*FIXME:*/E->getLocStart(), move(SubExpr), @@ -3739,63 +3738,63 @@ TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { } template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { - return SemaRef.Owned(E->Retain()); +Sema::OwningExprResult +TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { + return SemaRef.Owned(E->Retain()); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( - CXXNullPtrLiteralExpr *E) { - return SemaRef.Owned(E->Retain()); + CXXNullPtrLiteralExpr *E) { + return SemaRef.Owned(E->Retain()); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); - + QualType T = getDerived().TransformType(E->getType()); if (T.isNull()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && T == E->getType()) return SemaRef.Owned(E->Retain()); - + return getDerived().RebuildCXXThisExpr(E->getLocStart(), T); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { +TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { - ParmVarDecl *Param +TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { + ParmVarDecl *Param = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); if (!Param) return SemaRef.ExprError(); - + if (getDerived().AlwaysRebuild() && Param == E->getParam()) return SemaRef.Owned(E->Retain()); - + return getDerived().RebuildCXXDefaultArgExpr(Param); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { @@ -3804,48 +3803,48 @@ TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { QualType T = getDerived().TransformType(E->getType()); if (T.isNull()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && T == E->getType()) - return SemaRef.Owned(E->Retain()); - - return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), + return SemaRef.Owned(E->Retain()); + + return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), /*FIXME:*/E->getTypeBeginLoc(), T, E->getRParenLoc()); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E) { - VarDecl *Var + VarDecl *Var = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl())); if (!Var) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && - Var == E->getVarDecl()) + Var == E->getVarDecl()) return SemaRef.Owned(E->Retain()); - - return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(), + + return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(), /*FIXME:*/E->getStartLoc(), Var); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { +TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { // Transform the type that we're allocating TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); QualType AllocType = getDerived().TransformType(E->getAllocatedType()); if (AllocType.isNull()) return SemaRef.ExprError(); - + // Transform the size of the array we're allocating (if any). OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); if (ArraySize.isInvalid()) return SemaRef.ExprError(); - + // Transform the placement arguments (if any). bool ArgumentChanged = false; ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); @@ -3853,28 +3852,28 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); if (Arg.isInvalid()) return SemaRef.ExprError(); - + ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); PlacementArgs.push_back(Arg.take()); } - + // transform the constructor arguments (if any). ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); if (Arg.isInvalid()) return SemaRef.ExprError(); - + ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); ConstructorArgs.push_back(Arg.take()); } - + if (!getDerived().AlwaysRebuild() && AllocType == E->getAllocatedType() && ArraySize.get() == E->getArraySize() && !ArgumentChanged) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildCXXNewExpr(E->getLocStart(), E->isGlobalNew(), /*FIXME:*/E->getLocStart(), @@ -3887,26 +3886,26 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { move(ArraySize), /*FIXME:*/E->getLocStart(), move_arg(ConstructorArgs), - E->getLocEnd()); + E->getLocEnd()); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { +TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); if (Operand.isInvalid()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && - Operand.get() == E->getArgument()) - return SemaRef.Owned(E->Retain()); - + Operand.get() == E->getArgument()) + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), E->isGlobalDelete(), E->isArrayForm(), move(Operand)); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( @@ -3914,13 +3913,13 @@ TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( OwningExprResult Base = getDerived().TransformExpr(E->getBase()); if (Base.isInvalid()) return SemaRef.ExprError(); - + NestedNameSpecifier *Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), E->getQualifierRange()); if (E->getQualifier() && !Qualifier) return SemaRef.ExprError(); - + QualType DestroyedType; { TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); @@ -3928,13 +3927,13 @@ TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( if (DestroyedType.isNull()) return SemaRef.ExprError(); } - + if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && Qualifier == E->getQualifier() && DestroyedType == E->getDestroyedType()) return SemaRef.Owned(E->Retain()); - + return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), E->getOperatorLoc(), E->isArrow(), @@ -3943,39 +3942,39 @@ TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( Qualifier, E->getQualifierRange()); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformUnresolvedFunctionNameExpr( - UnresolvedFunctionNameExpr *E) { + UnresolvedFunctionNameExpr *E) { // There is no transformation we can apply to an unresolved function name. - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { +TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); - + QualType T = getDerived().TransformType(E->getQueriedType()); if (T.isNull()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && T == E->getQueriedType()) return SemaRef.Owned(E->Retain()); - + // FIXME: Bad location information SourceLocation FakeLParenLoc = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); - - return getDerived().RebuildUnaryTypeTrait(E->getTrait(), + + return getDerived().RebuildUnaryTypeTrait(E->getTrait(), E->getLocStart(), /*FIXME:*/FakeLParenLoc, T, E->getLocEnd()); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformQualifiedDeclRefExpr(QualifiedDeclRefExpr *E) { @@ -3984,45 +3983,45 @@ TreeTransform<Derived>::TransformQualifiedDeclRefExpr(QualifiedDeclRefExpr *E) { E->getQualifierRange()); if (!NNS) return SemaRef.ExprError(); - - NamedDecl *ND + + NamedDecl *ND = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl())); if (!ND) return SemaRef.ExprError(); - - if (!getDerived().AlwaysRebuild() && + + if (!getDerived().AlwaysRebuild() && NNS == E->getQualifier() && ND == E->getDecl()) - return SemaRef.Owned(E->Retain()); - - return getDerived().RebuildQualifiedDeclRefExpr(NNS, + return SemaRef.Owned(E->Retain()); + + return getDerived().RebuildQualifiedDeclRefExpr(NNS, E->getQualifierRange(), ND, E->getLocation(), /*FIXME:*/false); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformUnresolvedDeclRefExpr( - UnresolvedDeclRefExpr *E) { + UnresolvedDeclRefExpr *E) { NestedNameSpecifier *NNS = getDerived().TransformNestedNameSpecifier(E->getQualifier(), E->getQualifierRange()); if (!NNS) return SemaRef.ExprError(); - - DeclarationName Name + + DeclarationName Name = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); if (!Name) return SemaRef.ExprError(); - - if (!getDerived().AlwaysRebuild() && + + if (!getDerived().AlwaysRebuild() && NNS == E->getQualifier() && Name == E->getDeclName()) - return SemaRef.Owned(E->Retain()); - - return getDerived().RebuildUnresolvedDeclRefExpr(NNS, + return SemaRef.Owned(E->Retain()); + + return getDerived().RebuildUnresolvedDeclRefExpr(NNS, E->getQualifierRange(), Name, E->getLocation(), @@ -4031,15 +4030,15 @@ TreeTransform<Derived>::TransformUnresolvedDeclRefExpr( template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E) { - TemplateName Template +TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E) { + TemplateName Template = getDerived().TransformTemplateName(E->getTemplateName()); if (Template.isNull()) return SemaRef.ExprError(); - + llvm::SmallVector<TemplateArgument, 4> TransArgs; for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { - TemplateArgument TransArg + TemplateArgument TransArg = getDerived().TransformTemplateArgument(E->getTemplateArgs()[I]); if (TransArg.isNull()) return SemaRef.ExprError(); @@ -4049,8 +4048,8 @@ TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E) { // FIXME: Would like to avoid rebuilding if nothing changed, but we can't // compare template arguments (yet). - - // FIXME: It's possible that we'll find out now that the template name + + // FIXME: It's possible that we'll find out now that the template name // actually refers to a type, in which case the caller is actually dealing // with a functional cast. Give a reasonable error message! return getDerived().RebuildTemplateIdExpr(Template, E->getTemplateNameLoc(), @@ -4062,7 +4061,7 @@ TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E) { template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { +TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); QualType T = getDerived().TransformType(E->getType()); @@ -4074,16 +4073,16 @@ TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { getDerived().TransformDecl(E->getConstructor())); if (!Constructor) return SemaRef.ExprError(); - + bool ArgumentChanged = false; ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); - for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), + for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); Arg != ArgEnd; ++Arg) { OwningExprResult TransArg = getDerived().TransformExpr(*Arg); if (TransArg.isInvalid()) return SemaRef.ExprError(); - + ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; Args.push_back(TransArg.takeAs<Expr>()); } @@ -4093,15 +4092,15 @@ TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { Constructor == E->getConstructor() && !ArgumentChanged) return SemaRef.Owned(E->Retain()); - + return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(), move_arg(Args)); } - + /// \brief Transform a C++ temporary-binding expression. /// -/// The transformation of a temporary-binding expression always attempts to -/// bind a new temporary variable to its subexpression, even if the +/// The transformation of a temporary-binding expression always attempts to +/// bind a new temporary variable to its subexpression, even if the /// subexpression itself did not change, because the temporary variable itself /// must be unique. template<typename Derived> @@ -4110,70 +4109,70 @@ TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>()); } - -/// \brief Transform a C++ expression that contains temporaries that should + +/// \brief Transform a C++ expression that contains temporaries that should /// be destroyed after the expression is evaluated. /// -/// The transformation of a full expression always attempts to build a new -/// CXXExprWithTemporaries expression, even if the +/// The transformation of a full expression always attempts to build a new +/// CXXExprWithTemporaries expression, even if the /// subexpression itself did not change, because it will need to capture the /// the new temporary variables introduced in the subexpression. template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXExprWithTemporaries( - CXXExprWithTemporaries *E) { + CXXExprWithTemporaries *E) { OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + return SemaRef.Owned( SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(), E->shouldDestroyTemporaries())); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( - CXXTemporaryObjectExpr *E) { + CXXTemporaryObjectExpr *E) { TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); QualType T = getDerived().TransformType(E->getType()); if (T.isNull()) return SemaRef.ExprError(); - + CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( getDerived().TransformDecl(E->getConstructor())); if (!Constructor) return SemaRef.ExprError(); - + bool ArgumentChanged = false; ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); Args.reserve(E->getNumArgs()); - for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), + for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); Arg != ArgEnd; ++Arg) { OwningExprResult TransArg = getDerived().TransformExpr(*Arg); if (TransArg.isInvalid()) return SemaRef.ExprError(); - + ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; Args.push_back((Expr *)TransArg.release()); } - + if (!getDerived().AlwaysRebuild() && T == E->getType() && Constructor == E->getConstructor() && !ArgumentChanged) return SemaRef.Owned(E->Retain()); - + // FIXME: Bogus location information SourceLocation CommaLoc; if (Args.size() > 1) { Expr *First = (Expr *)Args[0]; - CommaLoc + CommaLoc = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); } return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), @@ -4183,16 +4182,16 @@ TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( &CommaLoc, E->getLocEnd()); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( - CXXUnresolvedConstructExpr *E) { + CXXUnresolvedConstructExpr *E) { TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); QualType T = getDerived().TransformType(E->getTypeAsWritten()); if (T.isNull()) return SemaRef.ExprError(); - + bool ArgumentChanged = false; ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; @@ -4202,18 +4201,18 @@ TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( OwningExprResult TransArg = getDerived().TransformExpr(*Arg); if (TransArg.isInvalid()) return SemaRef.ExprError(); - + ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; FakeCommaLocs.push_back( SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); Args.push_back(TransArg.takeAs<Expr>()); } - + if (!getDerived().AlwaysRebuild() && T == E->getTypeAsWritten() && !ArgumentChanged) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + // FIXME: we're faking the locations of the commas return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), T, @@ -4222,31 +4221,31 @@ TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( FakeCommaLocs.data(), E->getRParenLoc()); } - + template<typename Derived> Sema::OwningExprResult TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr( - CXXUnresolvedMemberExpr *E) { + CXXUnresolvedMemberExpr *E) { // Transform the base of the expression. OwningExprResult Base = getDerived().TransformExpr(E->getBase()); if (Base.isInvalid()) return SemaRef.ExprError(); - + Sema::TypeTy *ObjectType = 0; - Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), + Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), E->getOperatorLoc(), E->isArrow()? tok::arrow : tok::period, ObjectType); if (Base.isInvalid()) return SemaRef.ExprError(); - + // FIXME: The first qualifier found might be a template type parameter, // in which case there is no transformed declaration to refer to (it might // refer to a built-in type!). NamedDecl *FirstQualifierInScope = cast_or_null<NamedDecl>( getDerived().TransformDecl(E->getFirstQualifierFoundInScope())); - + NestedNameSpecifier *Qualifier = 0; if (E->getQualifier()) { Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), @@ -4256,12 +4255,12 @@ TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr( if (!Qualifier) return SemaRef.ExprError(); } - - DeclarationName Name + + DeclarationName Name = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc()); if (!Name) return SemaRef.ExprError(); - + if (!E->hasExplicitTemplateArgumentList()) { // This is a reference to a member without an explicitly-specified // template argument list. Optimize for this common case. @@ -4270,8 +4269,8 @@ TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr( Qualifier == E->getQualifier() && Name == E->getMember() && FirstQualifierInScope == E->getFirstQualifierFoundInScope()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base), E->isArrow(), E->getOperatorLoc(), @@ -4287,23 +4286,23 @@ TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr( // FIXME: This also won't work for, e.g., x->template operator+<int> TemplateName OrigTemplateName = SemaRef.Context.getDependentTemplateName(0, Name.getAsIdentifierInfo()); - - TemplateName Template - = getDerived().TransformTemplateName(OrigTemplateName, + + TemplateName Template + = getDerived().TransformTemplateName(OrigTemplateName, QualType::getFromOpaquePtr(ObjectType)); if (Template.isNull()) return SemaRef.ExprError(); - + llvm::SmallVector<TemplateArgument, 4> TransArgs; for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { - TemplateArgument TransArg + TemplateArgument TransArg = getDerived().TransformTemplateArgument(E->getTemplateArgs()[I]); if (TransArg.isNull()) return SemaRef.ExprError(); - + TransArgs.push_back(TransArg); } - + return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base), E->isArrow(), E->getOperatorLoc(), @@ -4320,46 +4319,46 @@ TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr( template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { - return SemaRef.Owned(E->Retain()); +TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { + return SemaRef.Owned(E->Retain()); } -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { // FIXME: poor source location TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); QualType EncodedType = getDerived().TransformType(E->getEncodedType()); if (EncodedType.isNull()) return SemaRef.ExprError(); - + if (!getDerived().AlwaysRebuild() && EncodedType == E->getEncodedType()) - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), EncodedType, E->getRParenLoc()); } - + template<typename Derived> Sema::OwningExprResult -TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { +TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { // FIXME: Implement this! assert(false && "Cannot transform Objective-C expressions yet"); - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { - return SemaRef.Owned(E->Retain()); +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { + return SemaRef.Owned(E->Retain()); } -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { - ObjCProtocolDecl *Protocol +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { + ObjCProtocolDecl *Protocol = cast_or_null<ObjCProtocolDecl>( getDerived().TransformDecl(E->getProtocol())); if (!Protocol) @@ -4367,140 +4366,140 @@ TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { if (!getDerived().AlwaysRebuild() && Protocol == E->getProtocol()) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildObjCProtocolExpr(Protocol, E->getAtLoc(), /*FIXME:*/E->getAtLoc(), /*FIXME:*/E->getAtLoc(), E->getRParenLoc()); - + } -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { // FIXME: Implement this! assert(false && "Cannot transform Objective-C expressions yet"); - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } -template<typename Derived> -Sema::OwningExprResult +template<typename Derived> +Sema::OwningExprResult TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { // FIXME: Implement this! assert(false && "Cannot transform Objective-C expressions yet"); - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } -template<typename Derived> -Sema::OwningExprResult +template<typename Derived> +Sema::OwningExprResult TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( - ObjCImplicitSetterGetterRefExpr *E) { + ObjCImplicitSetterGetterRefExpr *E) { // FIXME: Implement this! assert(false && "Cannot transform Objective-C expressions yet"); - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { // FIXME: Implement this! assert(false && "Cannot transform Objective-C expressions yet"); - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { // FIXME: Implement this! assert(false && "Cannot transform Objective-C expressions yet"); - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { bool ArgumentChanged = false; ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); if (SubExpr.isInvalid()) return SemaRef.ExprError(); - + ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); SubExprs.push_back(SubExpr.takeAs<Expr>()); } - + if (!getDerived().AlwaysRebuild() && !ArgumentChanged) - return SemaRef.Owned(E->Retain()); - + return SemaRef.Owned(E->Retain()); + return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), move_arg(SubExprs), E->getRParenLoc()); } -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { // FIXME: Implement this! assert(false && "Cannot transform block expressions yet"); - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } -template<typename Derived> -Sema::OwningExprResult -TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { +template<typename Derived> +Sema::OwningExprResult +TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { // FIXME: Implement this! assert(false && "Cannot transform block-related expressions yet"); - return SemaRef.Owned(E->Retain()); + return SemaRef.Owned(E->Retain()); } - + //===----------------------------------------------------------------------===// // Type reconstruction //===----------------------------------------------------------------------===// -template<typename Derived> +template<typename Derived> QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType) { - return SemaRef.BuildPointerType(PointeeType, 0, + return SemaRef.BuildPointerType(PointeeType, 0, getDerived().getBaseLocation(), getDerived().getBaseEntity()); } -template<typename Derived> +template<typename Derived> QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType) { - return SemaRef.BuildBlockPointerType(PointeeType, 0, + return SemaRef.BuildBlockPointerType(PointeeType, 0, getDerived().getBaseLocation(), getDerived().getBaseEntity()); } -template<typename Derived> -QualType +template<typename Derived> +QualType TreeTransform<Derived>::RebuildLValueReferenceType(QualType ReferentType) { - return SemaRef.BuildReferenceType(ReferentType, true, 0, + return SemaRef.BuildReferenceType(ReferentType, true, 0, getDerived().getBaseLocation(), getDerived().getBaseEntity()); } -template<typename Derived> -QualType +template<typename Derived> +QualType TreeTransform<Derived>::RebuildRValueReferenceType(QualType ReferentType) { - return SemaRef.BuildReferenceType(ReferentType, false, 0, + return SemaRef.BuildReferenceType(ReferentType, false, 0, getDerived().getBaseLocation(), getDerived().getBaseEntity()); } template<typename Derived> -QualType TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, +QualType TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, QualType ClassType) { - return SemaRef.BuildMemberPointerType(PointeeType, ClassType, 0, + return SemaRef.BuildMemberPointerType(PointeeType, ClassType, 0, getDerived().getBaseLocation(), getDerived().getBaseEntity()); } template<typename Derived> -QualType +QualType TreeTransform<Derived>::RebuildArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt *Size, @@ -4511,11 +4510,11 @@ TreeTransform<Derived>::RebuildArrayType(QualType ElementType, return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, IndexTypeQuals, BracketsRange, getDerived().getBaseEntity()); - - QualType Types[] = { - SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, - SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, - SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty + + QualType Types[] = { + SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, + SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, + SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty }; const unsigned NumTypes = sizeof(Types) / sizeof(QualType); QualType SizeType; @@ -4524,78 +4523,78 @@ TreeTransform<Derived>::RebuildArrayType(QualType ElementType, SizeType = Types[I]; break; } - + if (SizeType.isNull()) SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false); - + IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); - return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, + return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, IndexTypeQuals, BracketsRange, - getDerived().getBaseEntity()); + getDerived().getBaseEntity()); } - + template<typename Derived> -QualType -TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, +QualType +TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt &Size, unsigned IndexTypeQuals) { - return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, + return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, IndexTypeQuals, SourceRange()); } template<typename Derived> -QualType -TreeTransform<Derived>::RebuildConstantArrayWithExprType(QualType ElementType, +QualType +TreeTransform<Derived>::RebuildConstantArrayWithExprType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt &Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) { - return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr, + return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr, IndexTypeQuals, BracketsRange); } template<typename Derived> -QualType +QualType TreeTransform<Derived>::RebuildConstantArrayWithoutExprType( - QualType ElementType, + QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt &Size, unsigned IndexTypeQuals) { - return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, + return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, IndexTypeQuals, SourceRange()); } template<typename Derived> -QualType -TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, +QualType +TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, unsigned IndexTypeQuals) { - return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, + return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, IndexTypeQuals, SourceRange()); } - + template<typename Derived> -QualType -TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, +QualType +TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, ExprArg SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) { - return getDerived().RebuildArrayType(ElementType, SizeMod, 0, + return getDerived().RebuildArrayType(ElementType, SizeMod, 0, SizeExpr.takeAs<Expr>(), IndexTypeQuals, BracketsRange); } template<typename Derived> -QualType -TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, +QualType +TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, ExprArg SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) { - return getDerived().RebuildArrayType(ElementType, SizeMod, 0, + return getDerived().RebuildArrayType(ElementType, SizeMod, 0, SizeExpr.takeAs<Expr>(), IndexTypeQuals, BracketsRange); } @@ -4606,7 +4605,7 @@ QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, // FIXME: semantic checking! return SemaRef.Context.getVectorType(ElementType, NumElements); } - + template<typename Derived> QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, unsigned NumElements, @@ -4614,32 +4613,32 @@ QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), NumElements, true); IntegerLiteral *VectorSize - = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, + = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, AttributeLoc); return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), AttributeLoc); } - + template<typename Derived> -QualType -TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, +QualType +TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, ExprArg SizeExpr, SourceLocation AttributeLoc) { return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); } - + template<typename Derived> QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, - QualType *ParamTypes, + QualType *ParamTypes, unsigned NumParamTypes, - bool Variadic, + bool Variadic, unsigned Quals) { - return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, + return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, Quals, getDerived().getBaseLocation(), getDerived().getBaseEntity()); } - + template<typename Derived> QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); @@ -4662,10 +4661,10 @@ QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( unsigned NumArgs) { // FIXME: Missing source locations for the template name, <, >. return SemaRef.CheckTemplateIdType(Template, getDerived().getBaseLocation(), - SourceLocation(), Args, NumArgs, - SourceLocation()); + SourceLocation(), Args, NumArgs, + SourceLocation()); } - + template<typename Derived> NestedNameSpecifier * TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, @@ -4678,7 +4677,7 @@ TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, SS.setRange(Range); SS.setScopeRep(Prefix); return static_cast<NestedNameSpecifier *>( - SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), + SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), Range.getEnd(), II, ObjectType, FirstQualifierInScope, @@ -4705,22 +4704,22 @@ TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, T.getTypePtr()); } - + SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; return 0; } - + template<typename Derived> -TemplateName +TemplateName TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, bool TemplateKW, TemplateDecl *Template) { - return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, + return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Template); } template<typename Derived> -TemplateName +TemplateName TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, bool TemplateKW, OverloadedFunctionDecl *Ovl) { @@ -4728,13 +4727,13 @@ TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, } template<typename Derived> -TemplateName +TemplateName TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, const IdentifierInfo &II, QualType ObjectType) { CXXScopeSpec SS; SS.setRange(SourceRange(getDerived().getBaseLocation())); - SS.setScopeRep(Qualifier); + SS.setScopeRep(Qualifier); return getSema().ActOnDependentTemplateName( /*FIXME:*/getDerived().getBaseLocation(), II, @@ -4743,9 +4742,9 @@ TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, ObjectType.getAsOpaquePtr()) .template getAsVal<TemplateName>(); } - + template<typename Derived> -Sema::OwningExprResult +Sema::OwningExprResult TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, SourceLocation OpLoc, ExprArg Callee, @@ -4754,73 +4753,73 @@ TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, Expr *FirstExpr = (Expr *)First.get(); Expr *SecondExpr = (Expr *)Second.get(); bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); - + // Determine whether this should be a builtin operation. if (SecondExpr == 0 || isPostIncDec) { if (!FirstExpr->getType()->isOverloadableType()) { // The argument is not of overloadable type, so try to create a // built-in unary operation. - UnaryOperator::Opcode Opc + UnaryOperator::Opcode Opc = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); - + return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); } } else { - if (!FirstExpr->getType()->isOverloadableType() && + if (!FirstExpr->getType()->isOverloadableType() && !SecondExpr->getType()->isOverloadableType()) { // Neither of the arguments is an overloadable type, so try to // create a built-in binary operation. BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); - OwningExprResult Result + OwningExprResult Result = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); if (Result.isInvalid()) return SemaRef.ExprError(); - + First.release(); Second.release(); return move(Result); } } - - // Compute the transformed set of functions (and function templates) to be + + // Compute the transformed set of functions (and function templates) to be // used during overload resolution. Sema::FunctionSet Functions; - - DeclRefExpr *DRE + + DeclRefExpr *DRE = cast<DeclRefExpr>(((Expr *)Callee.get())->IgnoreParenCasts()); - + // FIXME: Do we have to check // IsAcceptableNonMemberOperatorCandidate for each of these? for (OverloadIterator F(DRE->getDecl()), FEnd; F != FEnd; ++F) Functions.insert(*F); - + // Add any functions found via argument-dependent lookup. Expr *Args[2] = { FirstExpr, SecondExpr }; unsigned NumArgs = 1 + (SecondExpr != 0); - DeclarationName OpName + DeclarationName OpName = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); SemaRef.ArgumentDependentLookup(OpName, Args, NumArgs, Functions); - + // Create the overloaded operator invocation for unary operators. if (NumArgs == 1 || isPostIncDec) { - UnaryOperator::Opcode Opc + UnaryOperator::Opcode Opc = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); } - + // Create the overloaded operator invocation for binary operators. - BinaryOperator::Opcode Opc = + BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); - OwningExprResult Result + OwningExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); if (Result.isInvalid()) return SemaRef.ExprError(); - + First.release(); Second.release(); - return move(Result); + return move(Result); } - + } // end namespace clang #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |