clang: lib/Sema/SemaExprCXX.cpp File Reference (original) (raw)

Implements semantic analysis for C++ expressions. More...

Go to the source code of this file.

Enumerations
enum class ResolveMode { Typed, Untyped }
enum class DeallocLookupMode { Untyped, OptionallyTyped }
Functions
static void getUuidAttrOfType (Sema &SemaRef, QualType QT, llvm::SmallSetVector< const UuidAttr *, 1 > &UuidAttrs)
Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to a single GUID.
static void collectPublicBases (CXXRecordDecl *RD, llvm::DenseMap< CXXRecordDecl *, unsigned > &SubobjectsSeen, llvm::SmallPtrSetImpl< CXXRecordDecl * > &VBases, llvm::SetVector< CXXRecordDecl * > &PublicSubobjectsSeen, bool ParentIsPublic)
static void getUnambiguousPublicSubobjects (CXXRecordDecl *RD, llvm::SmallVectorImpl< CXXRecordDecl * > &Objects)
static QualType adjustCVQualifiersForCXXThisWithinLambda (ArrayRef< FunctionScopeInfo * > FunctionScopes, QualType ThisTy, DeclContext *CurSemaContext, ASTContext &ASTCtx)
static void buildLambdaThisCaptureFixit (Sema &Sema, LambdaScopeInfo *LSI)
static bool isNonPlacementDeallocationFunction (Sema &S, FunctionDecl *FD)
Determine whether the given function is a non-placement deallocation function.
static bool hasNewExtendedAlignment (Sema &S, QualType AllocType)
Determine whether a type has new-extended alignment.
static bool CheckDeleteOperator (Sema &S, SourceLocation StartLoc, SourceRange Range, bool Diagnose, CXXRecordDecl *NamingClass, DeclAccessPair Decl, FunctionDecl *Operator)
static UsualDeallocFnInfo resolveDeallocationOverload (Sema &S, LookupResult &R, const ImplicitDeallocationParameters &IDP, SourceLocation Loc, llvm::SmallVectorImpl< UsualDeallocFnInfo > *BestFns=nullptr)
Select the correct "usual" deallocation function to use from a selection of deallocation functions (either global or class-scope).
static bool doesUsualArrayDeleteWantSize (Sema &S, SourceLocation loc, TypeAwareAllocationMode PassType, QualType allocType)
Determine whether a given type is a class for which 'delete[]' would call a member 'operator delete[]' with a 'size_t' parameter.
static bool isLegalArrayNewInitializer (CXXNewInitializationStyle Style, Expr *Init, bool IsCPlusPlus20)
static bool resolveAllocationOverloadInterior (Sema &S, LookupResult &R, SourceRange Range, ResolveMode Mode, SmallVectorImpl< Expr * > &Args, AlignedAllocationMode &PassAlignment, FunctionDecl *&Operator, OverloadCandidateSet *AlignedCandidates, Expr *AlignArg, bool Diagnose)
static void LookupGlobalDeallocationFunctions (Sema &S, SourceLocation Loc, LookupResult &FoundDelete, DeallocLookupMode Mode, DeclarationName Name)
static bool resolveAllocationOverload (Sema &S, LookupResult &R, SourceRange Range, SmallVectorImpl< Expr * > &Args, ImplicitAllocationParameters &IAP, FunctionDecl *&Operator, OverloadCandidateSet *AlignedCandidates, Expr *AlignArg, bool Diagnose)
static void DiagnoseMismatchedNewDelete (Sema &SemaRef, SourceLocation DeleteLoc, const MismatchingNewDeleteDetector &Detector)
static bool resolveBuiltinNewDeleteOverload (Sema &S, CallExpr *TheCall, bool IsDelete, FunctionDecl *&Operator)
static ExprResult BuildCXXCastArgument (Sema &S, SourceLocation CastLoc, QualType Ty, CastKind Kind, CXXMethodDecl *Method, DeclAccessPair FoundDecl, bool HadMultipleCandidates, Expr *From)
static QualType adjustVectorType (ASTContext &Context, QualType FromTy, QualType ToType, QualType *ElTy=nullptr)
static bool TryClassUnification (Sema &Self, Expr *From, Expr *To, SourceLocation QuestionLoc, bool &HaveConversion, QualType &ToType)
Try to convert a type to another according to C++11 5.16p3.
static bool FindConditionalOverload (Sema &Self, ExprResult &LHS, ExprResult &RHS, SourceLocation QuestionLoc)
Try to find a common type for two according to C++0x 5.16p5.
static bool ConvertForConditional (Sema &Self, ExprResult &E, QualType T)
Perform an "extended" implicit conversion as returned by TryClassUnification.
static bool isValidVectorForConditionalCondition (ASTContext &Ctx, QualType CondTy)
static void noteOperatorArrows (Sema &S, ArrayRef< FunctionDecl * > OperatorArrows)
Note a set of 'operator->' functions that were used for a member access.
static bool CheckArrow (Sema &S, QualType &ObjectType, Expr *&Base, tok::TokenKind &OpKind, SourceLocation OpLoc)
static bool canRecoverDotPseudoDestructorCallsOnPointerObjects (Sema &SemaRef, QualType DestructedType)
Check if it's ok to try and recover dot pseudo destructor calls on pointer objects.
static void MaybeDecrementCount (Expr *E, llvm::DenseMap< const VarDecl *, int > &RefsMinusAssignments)
static bool VariableCanNeverBeAConstantExpression (VarDecl *Var, ASTContext &Context)
static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures (Expr *const FE, LambdaScopeInfo *const CurrentLSI, Sema &S)
Check if the current lambda has any potential captures that must be captured by any of its enclosing lambdas that are ready to capture.

Implements semantic analysis for C++ expressions.

Definition in file SemaExprCXX.cpp.

DeallocLookupMode

enum class DeallocLookupMode strong

ResolveMode

adjustCVQualifiersForCXXThisWithinLambda()

Definition at line 1101 of file SemaExprCXX.cpp.

References clang::QualType::addConst(), clang::C, clang::sema::LambdaScopeInfo::CallOperator, clang::CXXRecordDecl::captures(), clang::cast(), clang::sema::CapturingScopeInfo::getCXXThisCapture(), clang::Decl::getDeclContext(), clang::getLambdaAwareParentOfDeclContext(), clang::CXXRecordDecl::getLambdaCallOperator(), clang::DeclContext::getParent(), clang::Type::getPointeeType(), clang::ASTContext::getPointerType(), clang::isa(), clang::CXXMethodDecl::isConst(), clang::sema::CapturingScopeInfo::isCXXThisCaptured(), clang::isGenericLambdaCallOperatorSpecialization(), clang::isLambdaCallOperator(), clang::sema::LambdaScopeInfo::Lambda, clang::sema::LambdaScopeInfo::lambdaCaptureShouldBeConst(), and clang::LCK_StarThis.

Referenced by clang::Sema::getCurrentThisType().

adjustVectorType()

BuildCXXCastArgument()

Definition at line 4524 of file SemaExprCXX.cpp.

References clang::Sema::BuildCXXConstructExpr(), clang::Sema::BuildCXXMemberCallExpr(), clang::cast(), clang::Sema::CheckConstructorAccess(), clang::Sema::CheckMemberOperatorAccess(), clang::Complete, clang::Sema::CompleteConstructorCall(), clang::Constructor, clang::Sema::Context, clang::ImplicitCastExpr::Create(), clang::Sema::CurFPFeatureOverrides(), clang::Sema::DiagnoseUseOfDecl(), clang::ExprError(), clang::Expr::getType(), clang::InitializedEntity::InitializeTemporary(), clang::Type::isPointerType(), clang::Sema::MaybeBindToTemporary(), and clang::Sema::RequireNonAbstractType().

Referenced by clang::Sema::PerformImplicitConversion().

buildLambdaThisCaptureFixit()

canRecoverDotPseudoDestructorCallsOnPointerObjects()

bool canRecoverDotPseudoDestructorCallsOnPointerObjects ( Sema & SemaRef, QualType DestructedType ) static

CheckArrow()

Definition at line 6997 of file SemaExprCXX.cpp.

References clang::Sema::CheckPlaceholderExpr(), clang::FixItHint::CreateReplacement(), clang::Sema::DefaultFunctionArrayLvalueConversion(), clang::SemaBase::Diag(), clang::ActionResult< PtrTy, Compress >::get(), clang::Type::getAs(), clang::Type::getPointeeType(), clang::Type::isArrayType(), clang::Type::isFunctionType(), clang::ActionResult< PtrTy, Compress >::isInvalid(), clang::Type::isPointerType(), and clang::Sema::isSFINAEContext().

Referenced by clang::Sema::ActOnPseudoDestructorExpr(), clang::Sema::ActOnPseudoDestructorExpr(), and clang::Sema::BuildPseudoDestructorExpr().

CheckDeleteOperator()

Definition at line 1908 of file SemaExprCXX.cpp.

References clang::Sema::AR_inaccessible, clang::Sema::CheckAllocationAccess(), clang::SemaBase::Diag(), clang::Sema::Diagnose, clang::FunctionDecl::getDeletedMessage(), clang::FunctionDecl::getParamDecl(), clang::StringLiteral::getString(), clang::ValueDecl::getType(), clang::FunctionDecl::isDeleted(), clang::FunctionDecl::isTypeAwareOperatorNewOrDelete(), clang::Sema::NoteDeletedFunction(), and clang::Sema::RequireCompleteType().

Referenced by clang::Sema::FindAllocationFunctions(), clang::Sema::FindDeallocationFunction(), and clang::Sema::FindUsualDeallocationFunction().

CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures()

void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures ( Expr *const FE, LambdaScopeInfo *const CurrentLSI, Sema & S ) static

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.

Definition at line 7565 of file SemaExprCXX.cpp.

References clang::sema::LambdaScopeInfo::AfterParameterList, clang::sema::LambdaScopeInfo::CallOperator, clang::Sema::CheckCXXThisCapture(), clang::sema::LambdaScopeInfo::clearPotentialCaptures(), clang::Sema::Context, clang::Sema::CurContext, clang::Sema::FunctionScopes, clang::Expr::getExprLoc(), clang::DeclContext::getParent(), clang::ValueDecl::getPotentiallyDecomposedVarDecl(), clang::getStackIndexOfNearestEnclosingCaptureCapableLambda(), clang::sema::LambdaScopeInfo::hasPotentialThisCapture(), clang::Implicit, clang::DeclContext::isDependentContext(), clang::Expr::isInstantiationDependent(), clang::Sema::isUnevaluatedContext(), clang::sema::LambdaScopeInfo::isVariableExprMarkedAsNonODRUsed(), clang::Sema::MarkCaptureUsedInEnclosingContext(), clang::sema::LambdaScopeInfo::PotentialThisCaptureLocation, clang::Sema::tryCaptureVariable(), VariableCanNeverBeAConstantExpression(), and clang::sema::LambdaScopeInfo::visitPotentialCaptures().

Referenced by clang::Sema::ActOnFinishFullExpr().

collectPublicBases()

ConvertForConditional()

DiagnoseMismatchedNewDelete()

void DiagnoseMismatchedNewDelete ( Sema & SemaRef, SourceLocation DeleteLoc, const MismatchingNewDeleteDetector & Detector ) static

doesUsualArrayDeleteWantSize()

Determine whether a given type is a class for which 'delete[]' would call a member 'operator delete[]' with a 'size_t' parameter.

This implies that we need to store the array size (even if the type is trivially-destructible).

Definition at line 1979 of file SemaExprCXX.cpp.

References clang::alignedAllocationModeFromBool(), clang::Sema::Context, clang::ASTContext::DeclarationNames, clang::LookupResult::empty(), clang::Type::getAsCanonical(), clang::Type::getBaseElementTypeUnsafe(), clang::DeclarationNameTable::getCXXOperatorName(), hasNewExtendedAlignment(), clang::LookupResult::isAmbiguous(), clang::isSizedDeallocation(), clang::Sema::LookupOrdinaryName, clang::Sema::LookupQualifiedName(), clang::No, resolveDeallocationOverload(), and clang::LookupResult::suppressDiagnostics().

Referenced by clang::Sema::ActOnCXXDelete(), and clang::Sema::BuildCXXNew().

FindConditionalOverload()

Try to find a common type for two according to C++0x 5.16p5.

This is part of the parameter validation for the ? operator. If either value operand is a class type, overload resolution is used to find a conversion to a common type.

Definition at line 5618 of file SemaExprCXX.cpp.

References clang::OverloadCandidateSet::BestViableFunction(), clang::Converting, clang::OverloadCandidateSet::CSK_Operator, clang::ActionResult< PtrTy, Compress >::get(), clang::Stmt::getSourceRange(), clang::Expr::getType(), clang::ActionResult< PtrTy, Compress >::isInvalid(), clang::OR_Ambiguous, clang::OR_Deleted, clang::OR_No_Viable_Function, clang::OR_Success, and clang::Self.

Referenced by clang::Sema::CXXCheckConditionalOperands().

getUnambiguousPublicSubobjects()

getUuidAttrOfType()

Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to a single GUID.

Definition at line 701 of file SemaExprCXX.cpp.

References clang::TemplateArgumentList::asArray(), clang::TemplateArgument::Declaration, clang::Type::getAsTagDecl(), clang::Type::getBaseElementTypeUnsafe(), clang::Type::getPointeeType(), clang::QualType::getTypePtr(), getUuidAttrOfType(), clang::Type::isArrayType(), clang::Type::isPointerOrReferenceType(), and clang::TemplateArgument::Type.

Referenced by clang::Sema::BuildCXXUuidof(), clang::Sema::BuildCXXUuidof(), and getUuidAttrOfType().

hasNewExtendedAlignment()

isLegalArrayNewInitializer()

isNonPlacementDeallocationFunction()

Determine whether the given function is a non-placement deallocation function.

Definition at line 1725 of file SemaExprCXX.cpp.

References clang::Sema::Context, clang::ASTContext::getCanonicalTagType(), clang::NamedDecl::getDeclName(), clang::Sema::getLangOpts(), clang::FunctionDecl::getNumParams(), clang::FunctionDecl::getParamDecl(), clang::ASTContext::getSizeType(), clang::Sema::getStdAlignValT(), clang::ValueDecl::getType(), clang::ASTContext::hasSameUnqualifiedType(), clang::DeclarationName::isAnyOperatorDelete(), clang::FunctionDecl::isTypeAwareOperatorNewOrDelete(), clang::Sema::isUsualDeallocationFunction(), and clang::FunctionDecl::RequiredTypeAwareDeleteParameterCount.

Referenced by clang::Sema::FindAllocationFunctions(), and resolveDeallocationOverload().

isValidVectorForConditionalCondition()

LookupGlobalDeallocationFunctions()

MaybeDecrementCount()

void MaybeDecrementCount ( Expr * E, llvm::DenseMap< const VarDecl *, int > & RefsMinusAssignments ) static

noteOperatorArrows()

resolveAllocationOverload()

Definition at line 2884 of file SemaExprCXX.cpp.

References clang::Sema::Diagnose, clang::isAlignedAllocation(), clang::Sema::isStdTypeIdentity(), clang::isTypeAwareAllocation(), clang::No, clang::ImplicitAllocationParameters::PassAlignment, clang::ImplicitAllocationParameters::PassTypeIdentity, resolveAllocationOverloadInterior(), Typed, Untyped, and clang::Yes.

Referenced by clang::Sema::FindAllocationFunctions().

resolveAllocationOverloadInterior()

Definition at line 2692 of file SemaExprCXX.cpp.

References clang::Sema::AddOverloadCandidate(), clang::Sema::AddTemplateOverloadCandidate(), clang::Sema::AR_inaccessible, clang::LookupResult::begin(), clang::OverloadCandidateSet::BestViableFunction(), clang::C, clang::cast(), clang::Sema::CheckAllocationAccess(), clang::LookupResult::clear(), clang::OverloadCandidateSet::CompleteCandidates(), clang::Sema::Context, clang::OverloadCandidateSet::CSK_Normal, clang::ASTContext::DeclarationNames, clang::SemaBase::Diag(), clang::Sema::Diagnose, clang::Sema::DiagnoseUseOfDeletedFunction(), clang::LookupResult::end(), clang::Decl::getAsFunction(), clang::ASTContext::getBaseElementType(), clang::DeclarationNameTable::getCXXOperatorName(), clang::DeclarationName::getCXXOverloadedOperator(), clang::ASTContext::getLangOpts(), clang::LookupResult::getLookupName(), clang::LookupResult::getNameLoc(), clang::LookupResult::getNamingClass(), clang::Type::getPointeeType(), clang::ASTContext::getTranslationUnitDecl(), clang::NamedDecl::getUnderlyingDecl(), clang::isAlignedAllocation(), clang::LookupResult::isClassLookup(), clang::QualType::isConstQualified(), clang::Type::isPointerType(), clang::FunctionDecl::isTypeAwareOperatorNewOrDelete(), clang::Sema::LookupQualifiedName(), clang::No, clang::OverloadCandidateSet::NoteCandidates(), clang::OCD_AllCandidates, clang::OCD_AmbiguousCandidates, clang::OR_Ambiguous, clang::OR_Deleted, clang::OR_No_Viable_Function, clang::OR_Success, clang::SemaBase::PDiag(), resolveAllocationOverloadInterior(), clang::LookupResult::setLookupName(), and Typed.

Referenced by resolveAllocationOverload(), and resolveAllocationOverloadInterior().

resolveBuiltinNewDeleteOverload()

Definition at line 4232 of file SemaExprCXX.cpp.

References clang::Sema::AddOverloadCandidate(), clang::Sema::AddTemplateOverloadCandidate(), clang::CallExpr::arguments(), clang::LookupResult::begin(), clang::OverloadCandidateSet::BestViableFunction(), clang::cast(), clang::Sema::Context, clang::OverloadCandidateSet::CSK_Normal, clang::ASTContext::DeclarationNames, clang::SemaBase::Diag(), clang::Sema::DiagnoseUseOfDeletedFunction(), clang::LookupResult::empty(), clang::LookupResult::end(), clang::CallExpr::getBeginLoc(), clang::DeclarationNameTable::getCXXOperatorName(), clang::Decl::getLocation(), clang::LookupResult::getLookupName(), clang::LookupResult::getNameLoc(), clang::LookupResult::getNamingClass(), clang::FunctionDecl::getSourceRange(), clang::Stmt::getSourceRange(), clang::ASTContext::getTranslationUnitDecl(), clang::LookupResult::isAmbiguous(), clang::FunctionDecl::isReplaceableGlobalAllocationFunction(), clang::Sema::LookupOrdinaryName, clang::Sema::LookupQualifiedName(), clang::OverloadCandidateSet::NoteCandidates(), clang::OCD_AllCandidates, clang::OCD_AmbiguousCandidates, clang::OR_Ambiguous, clang::OR_Deleted, clang::OR_No_Viable_Function, clang::OR_Success, clang::SemaBase::PDiag(), and clang::LookupResult::suppressDiagnostics().

resolveDeallocationOverload()

TryClassUnification()

Try to convert a type to another according to C++11 5.16p3.

This is part of the parameter validation for the ? operator. If either value operand is a class type, the two operands are attempted to be converted to each other. This function does the conversion in one direction. It returns true if the program is ill-formed and has already been diagnosed as such.

Definition at line 5528 of file SemaExprCXX.cpp.

References clang::InitializationKind::CreateCopy(), clang::InitializationSequence::Diagnose(), clang::InitializationSequence::Failed(), clang::Type::getAsCanonical(), clang::Stmt::getBeginLoc(), clang::QualType::getNonLValueExprType(), clang::Expr::getType(), clang::InitializedEntity::InitializeTemporary(), clang::InitializationSequence::isAmbiguous(), clang::QualType::isAtLeastAsQualifiedAs(), clang::InitializationSequence::isDirectReferenceBinding(), clang::Expr::isGLValue(), clang::Self, and clang::T.

Referenced by clang::Sema::CXXCheckConditionalOperands().

VariableCanNeverBeAConstantExpression()