Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -292,7 +292,7 @@ if (isDependent) { // We didn't find our type, but that's okay: it's dependent // anyway. - + // FIXME: What if we have no nested-name-specifier? QualType T = CheckTypenameType(ETK_None, SourceLocation(), SS.getWithLocInContext(Context), @@ -326,14 +326,14 @@ ParsedType Sema::getDestructorType(const DeclSpec& DS, ParsedType ObjectType) { if (DS.getTypeSpecType() == DeclSpec::TST_error || !ObjectType) return nullptr; - assert(DS.getTypeSpecType() == DeclSpec::TST_decltype + assert(DS.getTypeSpecType() == DeclSpec::TST_decltype && "only get destructor types from declspecs"); QualType T = BuildDecltypeType(DS.getRepAsExpr(), DS.getTypeSpecTypeLoc()); QualType SearchType = GetTypeFromParser(ObjectType); if (SearchType->isDependentType() || Context.hasSameUnqualifiedType(SearchType, T)) { return ParsedType::make(T); } - + Diag(DS.getTypeSpecTypeLoc(), diag::err_destructor_expr_type_mismatch) << T << SearchType; return nullptr; @@ -662,7 +662,7 @@ IsThrownVarInScope = true; break; } - + if (S->getFlags() & (Scope::FnScope | Scope::ClassScope | Scope::BlockScope | Scope::FunctionPrototypeScope | Scope::ObjCMethodScope | @@ -672,11 +672,11 @@ } } } - + return BuildCXXThrow(OpLoc, Ex, IsThrownVarInScope); } -ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, +ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, bool IsThrownVarInScope) { // Don't report an error if 'throw' is used in system headers. if (!getLangOpts().CXXExceptions && @@ -903,10 +903,10 @@ I-- && isa(FunctionScopes[I]); CurDC = getLambdaAwareParentOfDeclContext(CurDC)) { CurLSI = cast(FunctionScopes[I]); - - if (!CurLSI->isCXXThisCaptured()) + + if (!CurLSI->isCXXThisCaptured()) continue; - + auto C = CurLSI->getCXXThisCapture(); if (C.isCopyCapture()) { @@ -922,7 +922,7 @@ assert(CurLSI); assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator)); assert(CurDC == getLambdaAwareParentOfDeclContext(CurLSI->CallOperator)); - + auto IsThisCaptured = [](CXXRecordDecl *Closure, bool &IsByCopy, bool &IsConst) { IsConst = false; @@ -992,10 +992,10 @@ return ThisTy; } -Sema::CXXThisScopeRAII::CXXThisScopeRAII(Sema &S, +Sema::CXXThisScopeRAII::CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals, - bool Enabled) + bool Enabled) : S(S), OldCXXThisTypeOverride(S.CXXThisTypeOverride), Enabled(false) { if (!Enabled || !ContextDecl) @@ -1006,13 +1006,13 @@ Record = Template->getTemplatedDecl(); else Record = cast(ContextDecl); - + // We care only for CVR qualifiers here, so cut everything else. CXXThisTypeQuals &= Qualifiers::FastMask; S.CXXThisTypeOverride = S.Context.getPointerType( S.Context.getRecordType(Record).withCVRQualifiers(CXXThisTypeQuals)); - + this->Enabled = true; } @@ -1026,7 +1026,7 @@ static Expr *captureThis(Sema &S, ASTContext &Context, RecordDecl *RD, QualType ThisTy, SourceLocation Loc, const bool ByCopy) { - + QualType AdjustedThisTy = ThisTy; // The type of the corresponding data member (not a 'this' pointer if 'by // copy'). @@ -1039,7 +1039,7 @@ CaptureThisFieldTy.removeLocalCVRQualifiers(Qualifiers::CVRMask); AdjustedThisTy = Context.getPointerType(CaptureThisFieldTy); } - + FieldDecl *Field = FieldDecl::Create( Context, RD, Loc, Loc, nullptr, CaptureThisFieldTy, Context.getTrivialTypeSourceInfo(CaptureThisFieldTy, Loc), nullptr, false, @@ -1065,24 +1065,24 @@ return This; } -bool Sema::CheckCXXThisCapture(SourceLocation Loc, const bool Explicit, +bool Sema::CheckCXXThisCapture(SourceLocation Loc, const bool Explicit, bool BuildAndDiagnose, const unsigned *const FunctionScopeIndexToStopAt, const bool ByCopy) { // We don't need to capture this in an unevaluated context. if (isUnevaluatedContext() && !Explicit) return true; - + assert((!ByCopy || Explicit) && "cannot implicitly capture *this by value"); const unsigned MaxFunctionScopesIndex = FunctionScopeIndexToStopAt ? *FunctionScopeIndexToStopAt : FunctionScopes.size() - 1; - + // Check that we can capture the *enclosing object* (referred to by '*this') - // by the capturing-entity/closure (lambda/block/etc) at - // MaxFunctionScopesIndex-deep on the FunctionScopes stack. + // by the capturing-entity/closure (lambda/block/etc) at + // MaxFunctionScopesIndex-deep on the FunctionScopes stack. - // Note: The *enclosing object* can only be captured by-value by a - // closure that is a lambda, using the explicit notation: + // Note: The *enclosing object* can only be captured by-value by a + // closure that is a lambda, using the explicit notation: // [*this] { ... }. // Every other capture of the *enclosing object* results in its by-reference // capture. @@ -1091,15 +1091,15 @@ // stack), we can capture the *enclosing object* only if: // - 'L' has an explicit byref or byval capture of the *enclosing object* // - or, 'L' has an implicit capture. - // AND + // AND // -- there is no enclosing closure - // -- or, there is some enclosing closure 'E' that has already captured the - // *enclosing object*, and every intervening closure (if any) between 'E' + // -- or, there is some enclosing closure 'E' that has already captured the + // *enclosing object*, and every intervening closure (if any) between 'E' // and 'L' can implicitly capture the *enclosing object*. - // -- or, every enclosing closure can implicitly capture the + // -- or, every enclosing closure can implicitly capture the // *enclosing object* - - + + unsigned NumCapturingClosures = 0; for (unsigned idx = MaxFunctionScopesIndex; idx != 0; idx--) { if (CapturingScopeInfo *CSI = @@ -1155,18 +1155,18 @@ // FIXME: We need to delay this marking in PotentiallyPotentiallyEvaluated // contexts. QualType ThisTy = getCurrentThisType(); - for (unsigned idx = MaxFunctionScopesIndex; NumCapturingClosures; + for (unsigned idx = MaxFunctionScopesIndex; NumCapturingClosures; --idx, --NumCapturingClosures) { CapturingScopeInfo *CSI = cast(FunctionScopes[idx]); Expr *ThisExpr = nullptr; - + if (LambdaScopeInfo *LSI = dyn_cast(CSI)) { // For lambda expressions, build a field and an initializing expression, // and capture the *enclosing object* by copy only if this is the first // iteration. ThisExpr = captureThis(*this, Context, LSI->Lambda, ThisTy, Loc, ByCopy && idx == MaxFunctionScopesIndex); - + } else if (CapturedRegionScopeInfo *RSI = dyn_cast(FunctionScopes[idx])) ThisExpr = @@ -1196,7 +1196,7 @@ // type for 'this'. if (CXXThisTypeOverride.isNull()) return false; - + // Determine whether we're looking into a class that's currently being // defined. CXXRecordDecl *Class = BaseType->getAsCXXRecordDecl(); @@ -1574,7 +1574,7 @@ << /*at end of FE*/0 << Inits[0]->getSourceRange(); } - // In ARC, infer 'retaining' for the allocated + // In ARC, infer 'retaining' for the allocated if (getLangOpts().ObjCAutoRefCount && AllocType.getObjCLifetime() == Qualifiers::OCL_None && AllocType->isObjCLifetimeType()) { @@ -1583,7 +1583,7 @@ } QualType ResultType = Context.getPointerType(AllocType); - + if (ArraySize && ArraySize->getType()->isNonOverloadPlaceholderType()) { ExprResult result = CheckPlaceholderExpr(ArraySize); if (result.isInvalid()) return ExprError(); @@ -1604,7 +1604,7 @@ ConvertedSize = PerformImplicitConversion(ArraySize, Context.getSizeType(), AA_Converting); - if (!ConvertedSize.isInvalid() && + if (!ConvertedSize.isInvalid() && ArraySize->getType()->getAs()) // Diagnose the compatibility of this conversion. Diag(StartLoc, diag::warn_cxx98_compat_array_size_conversion) @@ -1613,7 +1613,7 @@ class SizeConvertDiagnoser : public ICEConvertDiagnoser { protected: Expr *ArraySize; - + public: SizeConvertDiagnoser(Expr *ArraySize) : ICEConvertDiagnoser(/*AllowScopedEnumerations*/false, false, false), @@ -1872,7 +1872,7 @@ if (CXXDestructorDecl *dtor = LookupDestructor( cast(BaseRecordType->getDecl()))) { MarkFunctionReferenced(StartLoc, dtor); - CheckDestructorAccess(StartLoc, dtor, + CheckDestructorAccess(StartLoc, dtor, PDiag(diag::err_access_dtor) << BaseAllocType); if (DiagnoseUseOfDecl(dtor, StartLoc)) @@ -1921,7 +1921,7 @@ << BaseAllocType; } } - + return false; } @@ -2257,7 +2257,7 @@ if (Diagnose) { Diag(StartLoc, diag::err_ovl_deleted_call) << Best->Function->isDeleted() - << Name + << Name << getDeletedOrUnavailableSuffix(Best->Function) << Range; Candidates.NoteCandidates(*this, OCD_AllCandidates, Args); @@ -2428,7 +2428,7 @@ SourceLocation(), Name, FnType, /*TInfo=*/nullptr, SC_None, false, true); Alloc->setImplicit(); - + // Implicit sized deallocation functions always have default visibility. Alloc->addAttr(VisibilityAttr::CreateImplicit(Context, VisibilityAttr::Default)); @@ -2921,7 +2921,7 @@ QualType PointeeElem = Context.getBaseElementType(Pointee); if (unsigned AddressSpace = Pointee.getAddressSpace()) - return Diag(Ex.get()->getLocStart(), + return Diag(Ex.get()->getLocStart(), diag::err_address_space_qualified_delete) << Pointee.getUnqualifiedType() << AddressSpace; @@ -3003,7 +3003,7 @@ // Check access and ambiguity of operator delete and destructor. if (PointeeRD) { if (CXXDestructorDecl *Dtor = LookupDestructor(PointeeRD)) { - CheckDestructorAccess(Ex.get()->getExprLoc(), Dtor, + CheckDestructorAccess(Ex.get()->getExprLoc(), Dtor, PDiag(diag::err_access_dtor) << PointeeElem); } } @@ -3234,7 +3234,7 @@ ExprResult Sema::PerformImplicitConversion(Expr *From, QualType ToType, const ImplicitConversionSequence &ICS, - AssignmentAction Action, + AssignmentAction Action, CheckedConversionKind CCK) { switch (ICS.getKind()) { case ImplicitConversionSequence::StandardConversion: { @@ -3324,16 +3324,16 @@ ExprResult Sema::PerformImplicitConversion(Expr *From, QualType ToType, const StandardConversionSequence& SCS, - AssignmentAction Action, + AssignmentAction Action, CheckedConversionKind CCK) { bool CStyle = (CCK == CCK_CStyleCast || CCK == CCK_FunctionalCast); - + // Overall FIXME: we are recomputing too many types here and doing far too // much extra work. What this means is that we need to keep track of more // information that is computed when we try the implicit conversion initially, // so that we don't need to recompute anything here. QualType FromType = From->getType(); - + if (SCS.CopyConstructor) { // FIXME: When can ToType be a reference type? assert(!ToType->isReferenceType()); @@ -3403,13 +3403,13 @@ case ICK_Array_To_Pointer: FromType = Context.getArrayDecayedType(FromType); - From = ImpCastExprToType(From, FromType, CK_ArrayToPointerDecay, + From = ImpCastExprToType(From, FromType, CK_ArrayToPointerDecay, VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; case ICK_Function_To_Pointer: FromType = Context.getPointerType(FromType); - From = ImpCastExprToType(From, FromType, CK_FunctionToPointerDecay, + From = ImpCastExprToType(From, FromType, CK_FunctionToPointerDecay, VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; @@ -3452,7 +3452,7 @@ if (CheckExceptionSpecCompatibility(From, ToType)) return ExprError(); - From = ImpCastExprToType(From, ToType, CK_NoOp, + From = ImpCastExprToType(From, ToType, CK_NoOp, VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; @@ -3472,7 +3472,7 @@ case ICK_Floating_Promotion: case ICK_Floating_Conversion: - From = ImpCastExprToType(From, ToType, CK_FloatingCast, + From = ImpCastExprToType(From, ToType, CK_FloatingCast, VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; @@ -3491,22 +3491,22 @@ } else { CK = CK_IntegralComplexCast; } - From = ImpCastExprToType(From, ToType, CK, + From = ImpCastExprToType(From, ToType, CK, VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; } case ICK_Floating_Integral: if (ToType->isRealFloatingType()) - From = ImpCastExprToType(From, ToType, CK_IntegralToFloating, + From = ImpCastExprToType(From, ToType, CK_IntegralToFloating, VK_RValue, /*BasePath=*/nullptr, CCK).get(); else - From = ImpCastExprToType(From, ToType, CK_FloatingToIntegral, + From = ImpCastExprToType(From, ToType, CK_FloatingToIntegral, VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; case ICK_Compatible_Conversion: - From = ImpCastExprToType(From, ToType, CK_NoOp, + From = ImpCastExprToType(From, ToType, CK_NoOp, VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; @@ -3528,20 +3528,20 @@ if (From->getType()->isObjCObjectPointerType() && ToType->isObjCObjectPointerType()) EmitRelatedResultTypeNote(From); - } + } else if (getLangOpts().ObjCAutoRefCount && - !CheckObjCARCUnavailableWeakConversion(ToType, + !CheckObjCARCUnavailableWeakConversion(ToType, From->getType())) { if (Action == AA_Initializing) - Diag(From->getLocStart(), + Diag(From->getLocStart(), diag::err_arc_weak_unavailable_assign); else Diag(From->getLocStart(), - diag::err_arc_convesion_of_weak_unavailable) - << (Action == AA_Casting) << From->getType() << ToType + diag::err_arc_convesion_of_weak_unavailable) + << (Action == AA_Casting) << From->getType() << ToType << From->getSourceRange(); } - + CastKind Kind = CK_Invalid; CXXCastPath BasePath; if (CheckPointerConversion(From, ToType, Kind, BasePath, CStyle)) @@ -3589,7 +3589,7 @@ } From = ImpCastExprToType(From, Context.BoolTy, - ScalarTypeToBooleanCastKind(FromType), + ScalarTypeToBooleanCastKind(FromType), VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; @@ -3610,7 +3610,7 @@ } case ICK_Vector_Conversion: - From = ImpCastExprToType(From, ToType, CK_BitCast, + From = ImpCastExprToType(From, ToType, CK_BitCast, VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; @@ -3655,7 +3655,7 @@ // _Complex x -> x From = ImpCastExprToType(From, ElType, isFloatingComplex ? CK_FloatingComplexToReal - : CK_IntegralComplexToReal, + : CK_IntegralComplexToReal, VK_RValue, /*BasePath=*/nullptr, CCK).get(); // x -> y @@ -3663,23 +3663,23 @@ // do nothing } else if (ToType->isRealFloatingType()) { From = ImpCastExprToType(From, ToType, - isFloatingComplex ? CK_FloatingCast : CK_IntegralToFloating, + isFloatingComplex ? CK_FloatingCast : CK_IntegralToFloating, VK_RValue, /*BasePath=*/nullptr, CCK).get(); } else { assert(ToType->isIntegerType()); From = ImpCastExprToType(From, ToType, - isFloatingComplex ? CK_FloatingToIntegral : CK_IntegralCast, + isFloatingComplex ? CK_FloatingToIntegral : CK_IntegralCast, VK_RValue, /*BasePath=*/nullptr, CCK).get(); } } break; - + case ICK_Block_Pointer_Conversion: { From = ImpCastExprToType(From, ToType.getUnqualifiedType(), CK_BitCast, VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; } - + case ICK_TransparentUnionConversion: { ExprResult FromRes = From; Sema::AssignConvertType ConvTy = @@ -3883,8 +3883,8 @@ static bool HasNoThrowOperator(const RecordType *RT, OverloadedOperatorKind Op, Sema &Self, SourceLocation KeyLoc, ASTContext &C, - bool (CXXRecordDecl::*HasTrivial)() const, - bool (CXXRecordDecl::*HasNonTrivial)() const, + bool (CXXRecordDecl::*HasTrivial)() const, + bool (CXXRecordDecl::*HasNonTrivial)() const, bool (CXXMethodDecl::*IsDesiredOp)() const) { CXXRecordDecl *RD = cast(RT->getDecl()); @@ -3980,7 +3980,7 @@ return false; } } - + return T->isScalarType(); case UTT_IsCompound: return T->isCompoundType(); @@ -4159,12 +4159,12 @@ // false. if (T.isPODType(C) || T->isReferenceType()) return true; - + // Objective-C++ ARC: autorelease types don't require destruction. - if (T->isObjCLifetimeType() && + if (T->isObjCLifetimeType() && T.getObjCLifetime() == Qualifiers::OCL_Autoreleasing) return true; - + if (CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl()) return RD->hasTrivialDestructor(); return false; @@ -4224,6 +4224,9 @@ // resolution point. if (isa(ND)) continue; + // Using(Shadow)Decl itself is not a constructor + if (isa(ND) || isa(ND)) + continue; const CXXConstructorDecl *Constructor = cast(ND); if (Constructor->isCopyConstructor(FoundTQs)) { FoundConstructor = true; @@ -4260,6 +4263,9 @@ // FIXME: In C++0x, a constructor template can be a default constructor. if (isa(ND)) continue; + // Using(Shadow)Decl itself is not a constructor + if (isa(ND) || isa(ND)) + continue; const CXXConstructorDecl *Constructor = cast(ND); if (Constructor->isDefaultConstructor()) { FoundConstructor = true; @@ -4340,9 +4346,9 @@ // definition for is_constructible, as defined below, is known to call // no operation that is not trivial. // - // The predicate condition for a template specialization - // is_constructible shall be satisfied if and only if the - // following variable definition would be well-formed for some invented + // The predicate condition for a template specialization + // is_constructible shall be satisfied if and only if the + // following variable definition would be well-formed for some invented // variable t: // // T t(create()...); @@ -4356,7 +4362,7 @@ if (ArgTy->isVoidType() || ArgTy->isIncompleteArrayType()) continue; - if (S.RequireCompleteType(KWLoc, ArgTy, + if (S.RequireCompleteType(KWLoc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr)) return false; } @@ -4386,7 +4392,7 @@ for (Expr &E : OpaqueArgExprs) ArgExprs.push_back(&E); - // Perform the initialization in an unevaluated context within a SFINAE + // Perform the initialization in an unevaluated context within a SFINAE // trap at translation unit scope. EnterExpressionEvaluationContext Unevaluated(S, Sema::Unevaluated); Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/true); @@ -4425,12 +4431,12 @@ } default: llvm_unreachable("not a TT"); } - + return false; } -ExprResult Sema::BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, - ArrayRef Args, +ExprResult Sema::BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, + ArrayRef Args, SourceLocation RParenLoc) { QualType ResultType = Context.getLogicalOperationType(); @@ -4459,14 +4465,14 @@ SourceLocation RParenLoc) { SmallVector ConvertedArgs; ConvertedArgs.reserve(Args.size()); - + for (unsigned I = 0, N = Args.size(); I != N; ++I) { TypeSourceInfo *TInfo; QualType T = GetTypeFromParser(Args[I], &TInfo); if (!TInfo) TInfo = Context.getTrivialTypeSourceInfo(T, KWLoc); - - ConvertedArgs.push_back(TInfo); + + ConvertedArgs.push_back(TInfo); } return BuildTypeTrait(Kind, KWLoc, ConvertedArgs, RParenLoc); @@ -4500,7 +4506,7 @@ // If Base and Derived are class types and are different types // (ignoring possible cv-qualifiers) then Derived shall be a // complete type. - if (Self.RequireCompleteType(KeyLoc, RhsT, + if (Self.RequireCompleteType(KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr)) return false; @@ -4517,21 +4523,21 @@ // C++0x [meta.rel]p4: // Given the following function prototype: // - // template + // template // typename add_rvalue_reference::type create(); // - // the predicate condition for a template specialization - // is_convertible shall be satisfied if and only if - // the return expression in the following code would be + // the predicate condition for a template specialization + // is_convertible shall be satisfied if and only if + // the return expression in the following code would be // well-formed, including any implicit conversions to the return // type of the function: // - // To test() { + // To test() { // return create(); // } // - // Access checking is performed as if in a context unrelated to To and - // From. Only the validity of the immediate context of the expression + // Access checking is performed as if in a context unrelated to To and + // From. Only the validity of the immediate context of the expression // of the return-statement (including conversions to the return type) // is considered. // @@ -4560,10 +4566,10 @@ OpaqueValueExpr From(KeyLoc, LhsT.getNonLValueExprType(Self.Context), Expr::getValueKindForType(LhsT)); Expr *FromPtr = &From; - InitializationKind Kind(InitializationKind::CreateCopy(KeyLoc, + InitializationKind Kind(InitializationKind::CreateCopy(KeyLoc, SourceLocation())); - - // Perform the initialization in an unevaluated context within a SFINAE + + // Perform the initialization in an unevaluated context within a SFINAE // trap at translation unit scope. EnterExpressionEvaluationContext Unevaluated(Self, Sema::Unevaluated); Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true); @@ -4585,17 +4591,17 @@ // is_assignable, is known to call no operation that is not trivial // // is_assignable is defined as: - // The expression declval() = declval() is well-formed when + // The expression declval() = declval() is well-formed when // treated as an unevaluated operand (Clause 5). // - // For both, T and U shall be complete types, (possibly cv-qualified) + // For both, T and U shall be complete types, (possibly cv-qualified) // void, or arrays of unknown bound. if (!LhsT->isVoidType() && !LhsT->isIncompleteArrayType() && - Self.RequireCompleteType(KeyLoc, LhsT, + Self.RequireCompleteType(KeyLoc, LhsT, diag::err_incomplete_type_used_in_type_trait_expr)) return false; if (!RhsT->isVoidType() && !RhsT->isIncompleteArrayType() && - Self.RequireCompleteType(KeyLoc, RhsT, + Self.RequireCompleteType(KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr)) return false; @@ -4603,7 +4609,7 @@ if (LhsT->isVoidType() || RhsT->isVoidType()) return false; - // Build expressions that emulate the effect of declval() and + // Build expressions that emulate the effect of declval() and // declval(). if (LhsT->isObjectType() || LhsT->isFunctionType()) LhsT = Self.Context.getRValueReferenceType(LhsT); @@ -4613,8 +4619,8 @@ Expr::getValueKindForType(LhsT)); OpaqueValueExpr Rhs(KeyLoc, RhsT.getNonLValueExprType(Self.Context), Expr::getValueKindForType(RhsT)); - - // Attempt the assignment in an unevaluated context within a SFINAE + + // Attempt the assignment in an unevaluated context within a SFINAE // trap at translation unit scope. EnterExpressionEvaluationContext Unevaluated(Self, Sema::Unevaluated); Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true); @@ -5047,7 +5053,7 @@ Self.MarkFunctionReferenced(QuestionLoc, Best->Function); return false; } - + case OR_No_Viable_Function: // Emit a better diagnostic if one of the expressions is a null pointer @@ -5613,14 +5619,14 @@ else if (MemberExpr *Mem = dyn_cast(Callee)) T = Mem->getMemberDecl()->getType(); } - + if (const PointerType *Ptr = T->getAs()) T = Ptr->getPointeeType(); else if (const BlockPointerType *Ptr = T->getAs()) T = Ptr->getPointeeType(); else if (const MemberPointerType *MemPtr = T->getAs()) T = MemPtr->getPointeeType(); - + const FunctionType *FTy = T->getAs(); assert(FTy && "call to value not of function type?"); ReturnsRetained = FTy->getExtInfo().getProducesResult(); @@ -6007,7 +6013,7 @@ // so adjust the base type to the object type itself. if (BaseType->isObjCObjectPointerType()) BaseType = BaseType->getPointeeType(); - + // C++ [basic.lookup.classref]p2: // [...] If the type of the object expression is of pointer to scalar // type, the unqualified-id is looked up in the context of the complete @@ -6032,7 +6038,7 @@ // The object type must be complete (or dependent), or // C++11 [expr.prim.general]p3: // Unlike the object expression in other contexts, *this is not required to - // be of complete type for purposes of class member access (5.2.5) outside + // be of complete type for purposes of class member access (5.2.5) outside // the member function body. if (!BaseType->isDependentType() && !isThisOutsideMemberFunctionBody(BaseType) && @@ -6048,7 +6054,7 @@ return Base; } -static bool CheckArrow(Sema& S, QualType& ObjectType, Expr *&Base, +static bool CheckArrow(Sema& S, QualType& ObjectType, Expr *&Base, tok::TokenKind& OpKind, SourceLocation OpLoc) { if (Base->hasPlaceholderType()) { ExprResult result = S.CheckPlaceholderExpr(Base); @@ -6124,9 +6130,9 @@ DestructedTypeInfo = Context.getTrivialTypeSourceInfo(ObjectType, DestructedTypeStart); Destructed = PseudoDestructorTypeStorage(DestructedTypeInfo); - } else if (DestructedType.getObjCLifetime() != + } else if (DestructedType.getObjCLifetime() != ObjectType.getObjCLifetime()) { - + if (DestructedType.getObjCLifetime() == Qualifiers::OCL_None) { // Okay: just pretend that the user provided the correctly-qualified // type. @@ -6135,7 +6141,7 @@ << ObjectType << DestructedType << Base->getSourceRange() << DestructedTypeInfo->getTypeLoc().getLocalSourceRange(); } - + // Recover by setting the destructed type to the object type. DestructedType = ObjectType; DestructedTypeInfo = Context.getTrivialTypeSourceInfo(ObjectType, @@ -6319,7 +6325,7 @@ ExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, - SourceLocation TildeLoc, + SourceLocation TildeLoc, const DeclSpec& DS) { QualType ObjectType; if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc)) @@ -6514,7 +6520,7 @@ if (Res.isInvalid()) return E; E = Res.get(); - } + } return E; } @@ -6544,13 +6550,13 @@ // we can unambiguously check if the variable is a constant expression. // - if the initializer is not value dependent - we can determine whether // it can be used to initialize a constant expression. If Init can not -// be used to initialize a constant expression we conclude that Var can +// be used to initialize a constant expression we conclude that Var can // never be a constant expression. // - FXIME: if the initializer is dependent, we can still do some analysis and // identify certain cases unambiguously as non-const by using a Visitor: // - such as those that involve odr-use of a ParmVarDecl, involve a new // delete, lambda-expr, dynamic-cast, reinterpret-cast etc... -static inline bool VariableCanNeverBeAConstantExpression(VarDecl *Var, +static inline bool VariableCanNeverBeAConstantExpression(VarDecl *Var, ASTContext &Context) { if (isa(Var)) return true; const VarDecl *DefVD = nullptr; @@ -6570,29 +6576,29 @@ return false; } - return !IsVariableAConstantExpression(Var, Context); + return !IsVariableAConstantExpression(Var, Context); } -/// \brief Check if the current lambda has any potential captures -/// that must be captured by any of its enclosing lambdas that are ready to -/// capture. If there is a lambda that can capture a nested -/// potential-capture, go ahead and do so. Also, check to see if any -/// variables are uncaptureable or do not involve an odr-use so do not +/// \brief Check if the current lambda has any potential captures +/// that must be captured by any of its enclosing lambdas that are ready to +/// capture. If there is a lambda that can capture a nested +/// potential-capture, go ahead and do so. Also, check to see if any +/// variables are uncaptureable or do not involve an odr-use so do not /// need to be captured. static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures( Expr *const FE, LambdaScopeInfo *const CurrentLSI, Sema &S) { - assert(!S.isUnevaluatedContext()); - assert(S.CurContext->isDependentContext()); - assert(CurrentLSI->CallOperator == S.CurContext && + assert(!S.isUnevaluatedContext()); + assert(S.CurContext->isDependentContext()); + assert(CurrentLSI->CallOperator == S.CurContext && "The current call operator must be synchronized with Sema's CurContext"); const bool IsFullExprInstantiationDependent = FE->isInstantiationDependent(); ArrayRef FunctionScopesArrayRef( S.FunctionScopes.data(), S.FunctionScopes.size()); - + // All the potentially captureable variables in the current nested // lambda (within a generic outer lambda), must be captured by an // outer lambda that is enclosed within a non-dependent context. @@ -6603,7 +6609,7 @@ VarDecl *Var = nullptr; CurrentLSI->getPotentialVariableCapture(I, Var, VarExpr); // If the variable is clearly identified as non-odr-used and the full - // expression is not instantiation dependent, only then do we not + // expression is not instantiation dependent, only then do we not // need to check enclosing lambda's for speculative captures. // For e.g.: // Even though 'x' is not odr-used, it should be captured. @@ -6625,27 +6631,27 @@ const unsigned FunctionScopeIndexOfCapturableLambda = Index.getValue(); MarkVarDeclODRUsed(Var, VarExpr->getExprLoc(), S, &FunctionScopeIndexOfCapturableLambda); - } - const bool IsVarNeverAConstantExpression = + } + const bool IsVarNeverAConstantExpression = VariableCanNeverBeAConstantExpression(Var, S.Context); if (!IsFullExprInstantiationDependent || IsVarNeverAConstantExpression) { // This full expression is not instantiation dependent or the variable - // can not be used in a constant expression - which means - // this variable must be odr-used here, so diagnose a + // can not be used in a constant expression - which means + // this variable must be odr-used here, so diagnose a // capture violation early, if the variable is un-captureable. // This is purely for diagnosing errors early. Otherwise, this // error would get diagnosed when the lambda becomes capture ready. QualType CaptureType, DeclRefType; SourceLocation ExprLoc = VarExpr->getExprLoc(); if (S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit, - /*EllipsisLoc*/ SourceLocation(), - /*BuildAndDiagnose*/false, CaptureType, + /*EllipsisLoc*/ SourceLocation(), + /*BuildAndDiagnose*/false, CaptureType, DeclRefType, nullptr)) { // We will never be able to capture this variable, and we need // to be able to in any and all instantiations, so diagnose it. S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit, - /*EllipsisLoc*/ SourceLocation(), - /*BuildAndDiagnose*/true, CaptureType, + /*EllipsisLoc*/ SourceLocation(), + /*BuildAndDiagnose*/true, CaptureType, DeclRefType, nullptr); } } @@ -6972,15 +6978,15 @@ ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC, bool DiscardedValue, - bool IsConstexpr, + bool IsConstexpr, bool IsLambdaInitCaptureInitializer) { ExprResult FullExpr = FE; if (!FullExpr.get()) return ExprError(); - - // If we are an init-expression in a lambdas init-capture, we should not - // diagnose an unexpanded pack now (will be diagnosed once lambda-expr + + // If we are an init-expression in a lambdas init-capture, we should not + // diagnose an unexpanded pack now (will be diagnosed once lambda-expr // containing full-expression is done). // template void test(Ts ... t) { // test([&a(t)]() { <-- (t) is an init-expr that shouldn't be diagnosed now. @@ -6994,7 +7000,7 @@ // lambda where we've entered the introducer but not the body, or represent a // lambda where we've entered the body, depending on where the // parser/instantiation has got to). - if (!IsLambdaInitCaptureInitializer && + if (!IsLambdaInitCaptureInitializer && DiagnoseUnexpandedParameterPack(FullExpr.get())) return ExprError(); @@ -7022,13 +7028,13 @@ CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr); - // At the end of this full expression (which could be a deeply nested - // lambda), if there is a potential capture within the nested lambda, + // At the end of this full expression (which could be a deeply nested + // lambda), if there is a potential capture within the nested lambda, // have the outer capture-able lambda try and capture it. // Consider the following code: // void f(int, int); // void f(const int&, double); - // void foo() { + // void foo() { // const int x = 10, y = 20; // auto L = [=](auto a) { // auto M = [=](auto b) { @@ -7038,34 +7044,34 @@ // }; // } - // FIXME: Also consider what happens for something like this that involves - // the gnu-extension statement-expressions or even lambda-init-captures: + // FIXME: Also consider what happens for something like this that involves + // the gnu-extension statement-expressions or even lambda-init-captures: // void f() { // const int n = 0; // auto L = [&](auto a) { // +n + ({ 0; a; }); // }; // } - // - // Here, we see +n, and then the full-expression 0; ends, so we don't - // capture n (and instead remove it from our list of potential captures), - // and then the full-expression +n + ({ 0; }); ends, but it's too late + // + // Here, we see +n, and then the full-expression 0; ends, so we don't + // capture n (and instead remove it from our list of potential captures), + // and then the full-expression +n + ({ 0; }); ends, but it's too late // for us to see that we need to capture n after all. LambdaScopeInfo *const CurrentLSI = getCurLambda(); - // FIXME: PR 17877 showed that getCurLambda() can return a valid pointer + // FIXME: PR 17877 showed that getCurLambda() can return a valid pointer // even if CurContext is not a lambda call operator. Refer to that Bug Report - // for an example of the code that might cause this asynchrony. + // for an example of the code that might cause this asynchrony. // By ensuring we are in the context of a lambda's call operator // we can fix the bug (we only need to check whether we need to capture - // if we are within a lambda's body); but per the comments in that + // if we are within a lambda's body); but per the comments in that // PR, a proper fix would entail : // "Alternative suggestion: - // - Add to Sema an integer holding the smallest (outermost) scope - // index that we are *lexically* within, and save/restore/set to - // FunctionScopes.size() in InstantiatingTemplate's + // - Add to Sema an integer holding the smallest (outermost) scope + // index that we are *lexically* within, and save/restore/set to + // FunctionScopes.size() in InstantiatingTemplate's // constructor/destructor. - // - Teach the handful of places that iterate over FunctionScopes to + // - Teach the handful of places that iterate over FunctionScopes to // stop at the outermost enclosing lexical scope." const bool IsInLambdaDeclContext = isLambdaCallOperator(CurContext); if (IsInLambdaDeclContext && CurrentLSI && @@ -7081,34 +7087,34 @@ return MaybeCreateStmtWithCleanups(FullStmt); } -Sema::IfExistsResult +Sema::IfExistsResult Sema::CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, const DeclarationNameInfo &TargetNameInfo) { DeclarationName TargetName = TargetNameInfo.getName(); if (!TargetName) return IER_DoesNotExist; - + // If the name itself is dependent, then the result is dependent. if (TargetName.isDependentName()) return IER_Dependent; - + // Do the redeclaration lookup in the current scope. LookupResult R(*this, TargetNameInfo, Sema::LookupAnyName, Sema::NotForRedeclaration); LookupParsedName(R, S, &SS); R.suppressDiagnostics(); - + switch (R.getResultKind()) { case LookupResult::Found: case LookupResult::FoundOverloaded: case LookupResult::FoundUnresolvedValue: case LookupResult::Ambiguous: return IER_Exists; - + case LookupResult::NotFound: return IER_DoesNotExist; - + case LookupResult::NotFoundInCurrentInstantiation: return IER_Dependent; } @@ -7116,23 +7122,23 @@ llvm_unreachable("Invalid LookupResult Kind!"); } -Sema::IfExistsResult +Sema::IfExistsResult Sema::CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, bool IsIfExists, CXXScopeSpec &SS, UnqualifiedId &Name) { DeclarationNameInfo TargetNameInfo = GetNameFromUnqualifiedId(Name); - + // Check for unexpanded parameter packs. SmallVector Unexpanded; collectUnexpandedParameterPacks(SS, Unexpanded); collectUnexpandedParameterPacks(TargetNameInfo, Unexpanded); if (!Unexpanded.empty()) { DiagnoseUnexpandedParameterPacks(KeywordLoc, - IsIfExists? UPPC_IfExists - : UPPC_IfNotExists, + IsIfExists? UPPC_IfExists + : UPPC_IfNotExists, Unexpanded); return IER_Error; } - + return CheckMicrosoftIfExistsSymbol(S, SS, TargetNameInfo); } Index: test/SemaCXX/crash-has-nothrow-constructor.cpp =================================================================== --- test/SemaCXX/crash-has-nothrow-constructor.cpp +++ test/SemaCXX/crash-has-nothrow-constructor.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s + +#define assert(x) if (x) {} + +struct X { + X() {} +}; + +struct Y : public X { +public: + using X::X; +}; + +int main() { + assert(__has_nothrow_constructor(Y)); +} Index: test/SemaCXX/crash-has-nothrow-copy.cpp =================================================================== --- test/SemaCXX/crash-has-nothrow-copy.cpp +++ test/SemaCXX/crash-has-nothrow-copy.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s + +#define assert(x) if (x) {} + +struct X { + X(const X &x) {} +}; + +struct Y : public X { +public: + using X::X; +}; + +int main() { + assert(__has_nothrow_copy(Y)); +}