From ac5fc7c6bcb494b60fee7ce615ac931c5db6135e Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Tue, 4 Aug 2009 21:02:39 +0000 Subject: [PATCH] Canonicalize else. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78102 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 11 +-- lib/Sema/SemaDecl.cpp | 20 ++-- lib/Sema/SemaDeclAttr.cpp | 3 +- lib/Sema/SemaDeclCXX.cpp | 15 +-- lib/Sema/SemaDeclObjC.cpp | 43 ++++----- lib/Sema/SemaExpr.cpp | 32 +++---- lib/Sema/SemaExprCXX.cpp | 5 +- lib/Sema/SemaInherit.cpp | 14 +-- lib/Sema/SemaInit.cpp | 7 +- lib/Sema/SemaOverload.cpp | 113 ++++++++++------------- lib/Sema/SemaTemplate.cpp | 11 +-- lib/Sema/SemaTemplateInstantiateDecl.cpp | 9 +- 12 files changed, 114 insertions(+), 169 deletions(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index e217299451..d6095fc2ae 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -751,8 +751,7 @@ 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()) { + } else if (const PointerType *PT = T->getAs()) { isConstant = T.isConstant(Context) && PT->getPointeeType().isConstant(Context); } @@ -1205,9 +1204,8 @@ Sema::CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, if (C->hasBlockDeclRefExprs()) Diag(C->getLocStart(), diag::err_ret_local_block) << C->getSourceRange(); - } - // Perform checking for stack values returned by reference. - else if (lhsType->isReferenceType()) { + } else if (lhsType->isReferenceType()) { + // Perform checking for stack values returned by reference. // Check for a reference to the stack if (DeclRefExpr *DR = EvalVal(RetValExp)) Diag(DR->getLocStart(), diag::warn_ret_stack_ref) @@ -1444,8 +1442,7 @@ void Sema::CheckFloatComparison(SourceLocation loc, Expr* lex, Expr *rex) { if (FloatingLiteral* FLL = dyn_cast(LeftExprSansParen)) { if (FLL->isExact()) EmitWarning = false; - } - else + } else if (FloatingLiteral* FLR = dyn_cast(RightExprSansParen)){ if (FLR->isExact()) EmitWarning = false; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 503cd1e17b..afc1de7898 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3281,8 +3281,7 @@ Sema::DeclGroupPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, ArrayT->getElementType(), diag::err_illegal_decl_array_incomplete_type)) IDecl->setInvalidDecl(); - } - else if (IDecl->getStorageClass() == VarDecl::Static) { + } else if (IDecl->getStorageClass() == VarDecl::Static) { // C99 6.9.2p3: If the declaration of an identifier for an object is // a tentative definition and has internal linkage (C99 6.2.2p3), the // declared type shall not be an incomplete type. @@ -3947,8 +3946,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, Name = 0; PrevDecl = 0; Invalid = true; - } - else + } else PrevDecl = R; if (!getLangOptions().CPlusPlus && TUK != TUK_Reference) { @@ -4717,8 +4715,7 @@ Sema::DeclPtrTy Sema::ActOnIvar(Scope *S, ObjCInterfaceDecl* IDecl = IMPDecl->getClassInterface(); assert(IDecl && "No class- ActOnIvar"); EnclosingContext = cast_or_null(IDecl); - } - else + } else EnclosingContext = dyn_cast(EnclosingDecl); assert(EnclosingContext && "null DeclContext for ivar - ActOnIvar"); @@ -4857,12 +4854,11 @@ void Sema::ActOnFields(Scope* S, FD->setInvalidDecl(); EnclosingDecl->setInvalidDecl(); continue; - } - else if (getLangOptions().ObjC1 && - getLangOptions().getGCMode() != LangOptions::NonGC && - Record && - (FD->getType()->isObjCObjectPointerType() || - FD->getType().isObjCGCStrong())) + } else if (getLangOptions().ObjC1 && + getLangOptions().getGCMode() != LangOptions::NonGC && + Record && + (FD->getType()->isObjCObjectPointerType() || + FD->getType().isObjCGCStrong())) Record->setHasObjectMember(true); // Keep track of the number of named members. if (FD->getIdentifier()) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 08b4910a4f..239f9951c5 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -756,8 +756,7 @@ static void HandleSentinelAttr(Decl *d, const AttributeList &Attr, Sema &S) { S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m; return; } - } - else { + } else { S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) << Attr.getName() << 6 /*function, method or block */; return; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 974dfcc071..a550e662c4 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -986,8 +986,7 @@ void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl, Diag(PrevMember->getSourceLocation(), diag::warn_base_initialized) << BaseClass->getDesugaredType(true); - } - else { + } else { FieldDecl *Field = PrevMember->getMember(); Diag(PrevMember->getSourceLocation(), diag::warn_field_initialized) @@ -2165,14 +2164,12 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, err = true; } } - } - else if (FieldType->isReferenceType()) { + } else if (FieldType->isReferenceType()) { 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()) { + } else if (FieldType.isConstQualified()) { Diag(CurrentLocation, diag::err_unintialized_member) << Context.getTagDeclType(ClassDecl) << 1 << Field->getDeclName(); Diag((*Field)->getLocation(), diag::note_declared_at); @@ -2269,15 +2266,13 @@ void Sema::DefineImplicitOverloadedAssign(SourceLocation CurrentLocation, if (CXXMethodDecl *FieldAssignOpMethod = getAssignOperatorMethod(MethodDecl->getParamDecl(0), FieldClassDecl)) MarkDeclarationReferenced(CurrentLocation, FieldAssignOpMethod); - } - else if (FieldType->isReferenceType()) { + } else if (FieldType->isReferenceType()) { 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()) { + } else if (FieldType.isConstQualified()) { Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign) << Context.getTagDeclType(ClassDecl) << 1 << Field->getDeclName(); Diag(Field->getLocation(), diag::note_declared_at); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 809f3ee2a2..001190513f 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -128,8 +128,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, Diag(SuperLoc, diag::err_recursive_superclass) << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc); IDecl->setLocEnd(ClassLoc); - } - else { + } else { ObjCInterfaceDecl *SuperClassDecl = dyn_cast_or_null(PrevDecl); @@ -862,9 +861,8 @@ bool Sema::isPropertyReadonly(ObjCPropertyDecl *PDecl, dyn_cast(OMD->getDeclContext())) { if (IMD->getInstanceMethod(PDecl->getSetterName())) return false; - } - else if (ObjCCategoryImplDecl *CIMD = - dyn_cast(OMD->getDeclContext())) { + } else if (ObjCCategoryImplDecl *CIMD = + dyn_cast(OMD->getDeclContext())) { if (CIMD->getInstanceMethod(PDecl->getSetterName())) return false; } @@ -974,8 +972,7 @@ void Sema::MatchAllMethodDeclarations(const llvm::DenseSet &InsMap, if (ImmediateClass) WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl); continue; - } - else { + } else { ObjCMethodDecl *ImpMethodDecl = IMPDecl->getInstanceMethod((*I)->getSelector()); ObjCMethodDecl *IntfMethodDecl = @@ -998,8 +995,7 @@ void Sema::MatchAllMethodDeclarations(const llvm::DenseSet &InsMap, if (!ClsMap.count((*I)->getSelector())) { if (ImmediateClass) WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl); - } - else { + } else { ObjCMethodDecl *ImpMethodDecl = IMPDecl->getClassMethod((*I)->getSelector()); ObjCMethodDecl *IntfMethodDecl = @@ -1136,10 +1132,9 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, if (!TDD || !isa(TDD->getUnderlyingType())) { Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i]; Diag(PrevDecl->getLocation(), diag::note_previous_definition); - } - else if (TDD) { - // a forward class declaration matching a typedef name of a class - // refers to the underlying class. + } else if (TDD) { + // a forward class declaration matching a typedef name of a class refers + // to the underlying class. if (ObjCInterfaceType * OI = dyn_cast(TDD->getUnderlyingType())) PrevDecl = OI->getDecl(); @@ -1550,8 +1545,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, // parent methods if it shadows one. CompareMethodParamsInBaseAndSuper(ClassDecl, Method, true); } - } - else { + } else { /// Check for class method of the same name with incompatible types const ObjCMethodDecl *&PrevMethod = ClsMap[Method->getSelector()]; bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) @@ -1758,9 +1752,8 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( } if (AttrList) Diag(EndLoc, diag::warn_attribute_method_def); - } - else if (ObjCCategoryImplDecl *CatImpDecl = - dyn_cast(ClassDecl)) { + } else if (ObjCCategoryImplDecl *CatImpDecl = + dyn_cast(ClassDecl)) { if (MethodType == tok::minus) { PrevMethod = CatImpDecl->getInstanceMethod(Sel); CatImpDecl->addInstanceMethod(ObjCMethod); @@ -1913,8 +1906,7 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, if (Attributes & ObjCDeclSpec::DQ_PR_copy) PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy); PIDecl->setSetterName(SetterSel); - } - else + } else Diag(AtLoc, diag::err_use_continuation_class) << CCPrimary->getDeclName(); *isOverridingProperty = true; @@ -2024,8 +2016,7 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, Diag(PropertyLoc, diag::error_bad_property_decl) << IDecl->getDeclName(); return DeclPtrTy(); } - } - else if ((CatImplClass = dyn_cast(ClassImpDecl))) { + } else if ((CatImplClass = dyn_cast(ClassImpDecl))) { if (Synthesize) { Diag(AtLoc, diag::error_synthesize_category_decl); return DeclPtrTy(); @@ -2078,9 +2069,8 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId; // 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) { + } else if (getLangOptions().ObjCNonFragileABI && + ClassDeclared != IDecl) { Diag(PropertyLoc, diag::error_ivar_in_superclass_use) << property->getDeclName() << Ivar->getDeclName() << ClassDeclared->getDeclName(); @@ -2153,8 +2143,7 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, return DeclPtrTy(); } IC->addPropertyImplementation(PIDecl); - } - else { + } else { if (Synthesize) if (ObjCPropertyImplDecl *PPIDecl = CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) { diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 9c91eb11cb..ffc6d13bb4 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -116,8 +116,7 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, } warnNotEnoughArgs = (P != E || i >= NumArgs); isMethod = 1; - } - else if (FunctionDecl *FD = dyn_cast(D)) { + } else if (FunctionDecl *FD = dyn_cast(D)) { // skip over named parameters. ObjCMethodDecl::param_iterator P, E = FD->param_end(); for (P = FD->param_begin(); (P != E && i < NumArgs); ++P) { @@ -127,8 +126,7 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, ++i; } warnNotEnoughArgs = (P != E || i >= NumArgs); - } - else if (VarDecl *V = dyn_cast(D)) { + } else if (VarDecl *V = dyn_cast(D)) { // block or function pointer call. QualType Ty = V->getType(); if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) { @@ -148,11 +146,9 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, } if (Ty->isBlockPointerType()) isMethod = 2; - } - else + } else return; - } - else + } else return; if (warnNotEnoughArgs) { @@ -913,8 +909,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, SelfExpr.takeAs(), true, true)); } } - } - else if (getCurMethodDecl()->isInstanceMethod()) { + } else if (getCurMethodDecl()->isInstanceMethod()) { // We should warn if a local variable hides an ivar. ObjCInterfaceDecl *IFace = getCurMethodDecl()->getClassInterface(); ObjCInterfaceDecl *ClassDeclared; @@ -2355,9 +2350,8 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, ClassOfMethodDecl != ClassDeclared) Diag(MemberLoc, diag::error_private_ivar_access) << IV->getDeclName(); - } - // @protected - else if (!IDecl->isSuperClassOf(ClassOfMethodDecl)) + } else if (!IDecl->isSuperClassOf(ClassOfMethodDecl)) + // @protected Diag(MemberLoc, diag::error_protected_ivar_access) << IV->getDeclName(); } @@ -4154,10 +4148,9 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, !RHSStripped->isNullPointerConstant(Context)) { literalString = lex; literalStringStripped = LHSStripped; - } - else if ((isa(RHSStripped) || - isa(RHSStripped)) && - !LHSStripped->isNullPointerConstant(Context)) { + } else if ((isa(RHSStripped) || + isa(RHSStripped)) && + !LHSStripped->isNullPointerConstant(Context)) { literalString = rex; literalStringStripped = RHSStripped; } @@ -5804,9 +5797,8 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { if (Constructor->isImplicit() && Constructor->isDefaultConstructor()) { if (!Constructor->isUsed()) DefineImplicitDefaultConstructor(Loc, Constructor); - } - else if (Constructor->isImplicit() && - Constructor->isCopyConstructor(Context, TypeQuals)) { + } else if (Constructor->isImplicit() && + Constructor->isCopyConstructor(Context, TypeQuals)) { if (!Constructor->isUsed()) DefineImplicitCopyConstructor(Loc, Constructor, TypeQuals); } diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index dc45b01169..e31f9edb61 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -414,9 +414,8 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, unsigned NumConsArgs = ConstructorArgs.size(); if (AllocType->isDependentType()) { // Skip all the checks. - } - else if ((RT = AllocType->getAs()) && - !AllocType->isAggregateType()) { + } else if ((RT = AllocType->getAs()) && + !AllocType->isAggregateType()) { Constructor = PerformInitializationByConstructor( AllocType, ConsArgs, NumConsArgs, TypeLoc, diff --git a/lib/Sema/SemaInherit.cpp b/lib/Sema/SemaInherit.cpp index be235e9271..c48e3bc79e 100644 --- a/lib/Sema/SemaInherit.cpp +++ b/lib/Sema/SemaInherit.cpp @@ -227,13 +227,13 @@ bool Sema::LookupInBases(CXXRecordDecl *Class, // return immediately. return FoundPath; } - } - // C++ [class.member.lookup]p2: - // A member name f in one sub-object B hides a member name f in - // a sub-object A if A is a base class sub-object of B. Any - // declarations that are so hidden are eliminated from - // consideration. - else if (VisitBase && LookupInBases(BaseRecord, Criteria, Paths)) { + } else if (VisitBase && LookupInBases(BaseRecord, Criteria, Paths)) { + // C++ [class.member.lookup]p2: + // A member name f in one sub-object B hides a member name f in + // a sub-object A if A is a base class sub-object of B. Any + // declarations that are so hidden are eliminated from + // consideration. + // There is a path to a base class that meets the criteria. If we're not // collecting paths or finding ambiguities, we're done. FoundPath = true; diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index d92f37fb25..c976c115c3 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -414,8 +414,8 @@ void InitListChecker::FillInValueInitializations(InitListExpr *ILE) { if (Init < NumInits && !hadError) ILE->setInit(Init, new (SemaRef.Context) ImplicitValueInitExpr(ElementType)); - } - else if (InitListExpr *InnerILE =dyn_cast(ILE->getInit(Init))) + } else if (InitListExpr *InnerILE + = dyn_cast(ILE->getInit(Init))) FillInValueInitializations(InnerILE); } } @@ -595,8 +595,7 @@ void InitListChecker::CheckListElementTypes(InitListExpr *IList, false); CheckArrayType(IList, DeclType, Zero, SubobjectIsDesignatorContext, Index, StructuredList, StructuredIndex); - } - else + } else assert(0 && "Aggregate that isn't a structure or array?!"); } else if (DeclType->isVoidType() || DeclType->isFunctionType()) { // This type is invalid, issue a diagnostic. diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 75ca531cbc..1e0c057b35 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -509,9 +509,8 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, // FIXME: Doesn't see through to qualifiers behind a typedef! FromType = FromType.getUnqualifiedType(); - } - // Array-to-pointer conversion (C++ 4.2) - else if (FromType->isArrayType()) { + } else if (FromType->isArrayType()) { + // Array-to-pointer conversion (C++ 4.2) SCS.First = ICK_Array_To_Pointer; // An lvalue or rvalue of type "array of N T" or "array of unknown @@ -532,19 +531,17 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, SCS.ToTypePtr = ToType.getAsOpaquePtr(); return true; } - } - // Function-to-pointer conversion (C++ 4.3). - else if (FromType->isFunctionType() && argIsLvalue == Expr::LV_Valid) { + } else if (FromType->isFunctionType() && argIsLvalue == Expr::LV_Valid) { + // Function-to-pointer conversion (C++ 4.3). SCS.First = ICK_Function_To_Pointer; // An lvalue of function type T can be converted to an rvalue of // type "pointer to T." The result is a pointer to the // function. (C++ 4.3p1). FromType = Context.getPointerType(FromType); - } - // Address of overloaded function (C++ [over.over]). - 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; // We were able to resolve the address of the overloaded function, @@ -566,9 +563,8 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, Context.getTypeDeclType(M->getParent()).getTypePtr()); } else FromType = Context.getPointerType(FromType); - } - // We don't require any conversions for the first step. - else { + } else { + // We don't require any conversions for the first step. SCS.First = ICK_Identity; } @@ -583,79 +579,67 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, // The unqualified versions of the types are the same: there's no // conversion to do. SCS.Second = ICK_Identity; - } - // Integral promotion (C++ 4.5). - else if (IsIntegralPromotion(From, FromType, ToType)) { + } else if (IsIntegralPromotion(From, FromType, ToType)) { + // Integral promotion (C++ 4.5). SCS.Second = ICK_Integral_Promotion; FromType = ToType.getUnqualifiedType(); - } - // Floating point promotion (C++ 4.6). - else if (IsFloatingPointPromotion(FromType, ToType)) { + } else if (IsFloatingPointPromotion(FromType, ToType)) { + // Floating point promotion (C++ 4.6). SCS.Second = ICK_Floating_Promotion; FromType = ToType.getUnqualifiedType(); - } - // Complex promotion (Clang extension) - else if (IsComplexPromotion(FromType, ToType)) { + } else if (IsComplexPromotion(FromType, ToType)) { + // Complex promotion (Clang extension) SCS.Second = ICK_Complex_Promotion; FromType = ToType.getUnqualifiedType(); - } - // Integral conversions (C++ 4.7). - // FIXME: isIntegralType shouldn't be true for enums in C++. - else if ((FromType->isIntegralType() || FromType->isEnumeralType()) && + } else if ((FromType->isIntegralType() || FromType->isEnumeralType()) && (ToType->isIntegralType() && !ToType->isEnumeralType())) { + // Integral conversions (C++ 4.7). + // FIXME: isIntegralType shouldn't be true for enums in C++. SCS.Second = ICK_Integral_Conversion; FromType = ToType.getUnqualifiedType(); - } - // Floating point conversions (C++ 4.8). - else if (FromType->isFloatingType() && ToType->isFloatingType()) { + } else if (FromType->isFloatingType() && ToType->isFloatingType()) { + // Floating point conversions (C++ 4.8). SCS.Second = ICK_Floating_Conversion; FromType = ToType.getUnqualifiedType(); - } - // Complex conversions (C99 6.3.1.6) - else if (FromType->isComplexType() && ToType->isComplexType()) { + } else if (FromType->isComplexType() && ToType->isComplexType()) { + // Complex conversions (C99 6.3.1.6) SCS.Second = ICK_Complex_Conversion; FromType = ToType.getUnqualifiedType(); - } - // Floating-integral conversions (C++ 4.9). - // FIXME: isIntegralType shouldn't be true for enums in C++. - else if ((FromType->isFloatingType() && - ToType->isIntegralType() && !ToType->isBooleanType() && - !ToType->isEnumeralType()) || - ((FromType->isIntegralType() || FromType->isEnumeralType()) && - ToType->isFloatingType())) { + } else if ((FromType->isFloatingType() && + ToType->isIntegralType() && (!ToType->isBooleanType() && + !ToType->isEnumeralType())) || + ((FromType->isIntegralType() || FromType->isEnumeralType()) && + ToType->isFloatingType())) { + // Floating-integral conversions (C++ 4.9). + // FIXME: isIntegralType shouldn't be true for enums in C++. SCS.Second = ICK_Floating_Integral; FromType = ToType.getUnqualifiedType(); - } - // Complex-real conversions (C99 6.3.1.7) - else if ((FromType->isComplexType() && ToType->isArithmeticType()) || - (ToType->isComplexType() && FromType->isArithmeticType())) { + } else if ((FromType->isComplexType() && ToType->isArithmeticType()) || + (ToType->isComplexType() && FromType->isArithmeticType())) { + // Complex-real conversions (C99 6.3.1.7) SCS.Second = ICK_Complex_Real; FromType = ToType.getUnqualifiedType(); - } - // Pointer conversions (C++ 4.10). - else if (IsPointerConversion(From, FromType, ToType, FromType, - IncompatibleObjC)) { + } else if (IsPointerConversion(From, FromType, ToType, FromType, + IncompatibleObjC)) { + // Pointer conversions (C++ 4.10). SCS.Second = ICK_Pointer_Conversion; SCS.IncompatibleObjC = IncompatibleObjC; - } - // Pointer to member conversions (4.11). - else if (IsMemberPointerConversion(From, FromType, ToType, FromType)) { + } else if (IsMemberPointerConversion(From, FromType, ToType, FromType)) { + // Pointer to member conversions (4.11). SCS.Second = ICK_Pointer_Member; - } - // Boolean conversions (C++ 4.12). - else if (ToType->isBooleanType() && - (FromType->isArithmeticType() || - FromType->isEnumeralType() || - FromType->isPointerType() || - FromType->isBlockPointerType() || - FromType->isMemberPointerType() || - FromType->isNullPtrType())) { + } else if (ToType->isBooleanType() && + (FromType->isArithmeticType() || + FromType->isEnumeralType() || + FromType->isPointerType() || + FromType->isBlockPointerType() || + FromType->isMemberPointerType() || + FromType->isNullPtrType())) { + // Boolean conversions (C++ 4.12). SCS.Second = ICK_Boolean_Conversion; FromType = Context.BoolTy; - } - // Compatible conversions (Clang extension for C function overloading) - else if (!getLangOptions().CPlusPlus && - Context.typesAreCompatible(ToType, FromType)) { + } else if (!getLangOptions().CPlusPlus && + Context.typesAreCompatible(ToType, FromType)) { + // Compatible conversions (Clang extension for C function overloading) SCS.Second = ICK_Compatible_Conversion; } else { // No second conversion required. @@ -4660,8 +4644,7 @@ void Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *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(UnOp->getSubExpr())) { // We have taken the address of a pointer to member // function. Perform the computation here so that we get the diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 32d6069d8d..8dfb7d3881 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -681,10 +681,9 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, PreviousDefaultArgLoc = NewTypeParm->getDefaultArgumentLoc(); } else if (SawDefaultArgument) MissingDefaultArg = true; - } - // Merge default arguments for non-type template parameters - else if (NonTypeTemplateParmDecl *NewNonTypeParm + } else if (NonTypeTemplateParmDecl *NewNonTypeParm = dyn_cast(*NewParam)) { + // Merge default arguments for non-type template parameters NonTypeTemplateParmDecl *OldNonTypeParm = OldParams? cast(*OldParam) : 0; if (OldNonTypeParm && OldNonTypeParm->hasDefaultArgument() && @@ -709,9 +708,8 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, PreviousDefaultArgLoc = NewNonTypeParm->getDefaultArgumentLoc(); } else if (SawDefaultArgument) MissingDefaultArg = true; - } + } else { // Merge default arguments for template template parameters - else { TemplateTemplateParmDecl *NewTemplateParm = cast(*NewParam); TemplateTemplateParmDecl *OldTemplateParm @@ -2487,8 +2485,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, Converted.getFlatArguments(), Converted.flatSize(), Context); - } - else + } else ClassTemplateSpecializationDecl::Profile(ID, Converted.getFlatArguments(), Converted.flatSize(), diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 6506cde2af..abe1fffe88 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -612,11 +612,10 @@ TemplateDeclInstantiator::InstantiateFunctionType(FunctionDecl *D, if (PInst->getType()->isVoidType()) { SemaRef.Diag(PInst->getLocation(), diag::err_param_with_void_type); PInst->setInvalidDecl(); - } - else if (SemaRef.RequireNonAbstractType(PInst->getLocation(), - PInst->getType(), - diag::err_abstract_type_in_decl, - Sema::AbstractParamType)) + } else if (SemaRef.RequireNonAbstractType(PInst->getLocation(), + PInst->getType(), + diag::err_abstract_type_in_decl, + Sema::AbstractParamType)) PInst->setInvalidDecl(); Params.push_back(PInst); -- 2.40.0