clang 19.0.0git
Enumerations | Functions
SemaExprCXX.cpp File Reference

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

#include "TreeTransform.h"
#include "TypeLocBuilder.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTLambda.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprConcepts.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/AlignedAllocation.h"
#include "clang/Basic/DiagnosticSema.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Basic/TypeTraits.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaCUDA.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/SemaLambda.h"
#include "clang/Sema/Template.h"
#include "clang/Sema/TemplateDeduction.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TypeSize.h"
#include <optional>

Go to the source code of this file.

Enumerations

enum class  TypeTraitReturnType { Bool }
 

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 UsualDeallocFnInfo resolveDeallocationOverload (Sema &S, LookupResult &R, bool WantSize, bool WantAlign, 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, 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 resolveAllocationOverload (Sema &S, LookupResult &R, SourceRange Range, SmallVectorImpl< Expr * > &Args, bool &PassAlignment, 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 bool DiagnoseVLAInCXXTypeTrait (Sema &S, const TypeSourceInfo *T, clang::tok::TokenKind TypeTraitID)
 Checks that type T is not a VLA.
 
static bool CheckUnaryTypeTraitTypeCompleteness (Sema &S, TypeTrait UTT, SourceLocation Loc, QualType ArgTy)
 Check the completeness of a type in a unary type trait.
 
static bool HasNoThrowOperator (const RecordType *RT, OverloadedOperatorKind Op, Sema &Self, SourceLocation KeyLoc, ASTContext &C, bool(CXXRecordDecl::*HasTrivial)() const, bool(CXXRecordDecl::*HasNonTrivial)() const, bool(CXXMethodDecl::*IsDesiredOp)() const)
 
static bool EvaluateUnaryTypeTrait (Sema &Self, TypeTrait UTT, SourceLocation KeyLoc, TypeSourceInfo *TInfo)
 
static bool EvaluateBinaryTypeTrait (Sema &Self, TypeTrait BTT, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs, SourceLocation KeyLoc)
 
static bool EvaluateBooleanTypeTrait (Sema &S, TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc, bool IsDependent)
 
static TypeTraitReturnType GetReturnType (TypeTrait Kind)
 
static uint64_t EvaluateArrayTypeTrait (Sema &Self, ArrayTypeTrait ATT, QualType T, Expr *DimExpr, SourceLocation KeyLoc)
 
static bool EvaluateExpressionTrait (ExpressionTrait ET, Expr *E)
 
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 bool isValidSizelessVectorForConditionalCondition (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.
 
static ExprResult attemptRecovery (Sema &SemaRef, const TypoCorrectionConsumer &Consumer, const TypoCorrection &TC)
 

Detailed Description

Implements semantic analysis for C++ expressions.

Definition in file SemaExprCXX.cpp.

Enumeration Type Documentation

◆ TypeTraitReturnType

enum class TypeTraitReturnType
strong
Enumerator
Bool 

Definition at line 5818 of file SemaExprCXX.cpp.

Function Documentation

◆ adjustCVQualifiersForCXXThisWithinLambda()

static QualType adjustCVQualifiersForCXXThisWithinLambda ( ArrayRef< FunctionScopeInfo * >  FunctionScopes,
QualType  ThisTy,
DeclContext CurSemaContext,
ASTContext ASTCtx 
)
static

◆ attemptRecovery()

static ExprResult attemptRecovery ( Sema SemaRef,
const TypoCorrectionConsumer Consumer,
const TypoCorrection TC 
)
static

◆ BuildCXXCastArgument()

static ExprResult BuildCXXCastArgument ( Sema S,
SourceLocation  CastLoc,
QualType  Ty,
CastKind  Kind,
CXXMethodDecl Method,
DeclAccessPair  FoundDecl,
bool  HadMultipleCandidates,
Expr From 
)
static

◆ buildLambdaThisCaptureFixit()

static void buildLambdaThisCaptureFixit ( Sema Sema,
LambdaScopeInfo LSI 
)
static

◆ canRecoverDotPseudoDestructorCallsOnPointerObjects()

static bool canRecoverDotPseudoDestructorCallsOnPointerObjects ( Sema SemaRef,
QualType  DestructedType 
)
static

◆ CheckArrow()

static bool CheckArrow ( Sema S,
QualType ObjectType,
Expr *&  Base,
tok::TokenKind OpKind,
SourceLocation  OpLoc 
)
static

◆ CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures()

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

◆ CheckUnaryTypeTraitTypeCompleteness()

static bool CheckUnaryTypeTraitTypeCompleteness ( Sema S,
TypeTrait  UTT,
SourceLocation  Loc,
QualType  ArgTy 
)
static

Check the completeness of a type in a unary type trait.

If the particular type trait requires a complete type, tries to complete it. If completing the type fails, a diagnostic is emitted and false returned. If completing the type succeeds or no completion was required, returns true.

Definition at line 5032 of file SemaExprCXX.cpp.

References clang::Type::getAsCXXRecordDecl(), clang::Type::getBaseElementTypeUnsafe(), clang::Type::isArrayType(), clang::Type::isIncompleteArrayType(), clang::TagDecl::isUnion(), clang::Type::isVoidType(), and clang::Sema::RequireCompleteType().

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

◆ collectPublicBases()

static void collectPublicBases ( CXXRecordDecl RD,
llvm::DenseMap< CXXRecordDecl *, unsigned > &  SubobjectsSeen,
llvm::SmallPtrSetImpl< CXXRecordDecl * > &  VBases,
llvm::SetVector< CXXRecordDecl * > &  PublicSubobjectsSeen,
bool  ParentIsPublic 
)
static

◆ ConvertForConditional()

static bool ConvertForConditional ( Sema Self,
ExprResult E,
QualType  T 
)
static

◆ DiagnoseMismatchedNewDelete()

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

◆ DiagnoseVLAInCXXTypeTrait()

static bool DiagnoseVLAInCXXTypeTrait ( Sema S,
const TypeSourceInfo T,
clang::tok::TokenKind  TypeTraitID 
)
static

Checks that type T is not a VLA.

Returns
true if T is VLA and a diagnostic was emitted, false otherwise.

Definition at line 5016 of file SemaExprCXX.cpp.

References clang::SemaBase::Diag(), clang::Type::isVariableArrayType(), and clang::T.

Referenced by EvaluateBinaryTypeTrait(), and EvaluateUnaryTypeTrait().

◆ doesUsualArrayDeleteWantSize()

static bool doesUsualArrayDeleteWantSize ( Sema S,
SourceLocation  loc,
QualType  allocType 
)
static

◆ EvaluateArrayTypeTrait()

static uint64_t EvaluateArrayTypeTrait ( Sema Self,
ArrayTypeTrait  ATT,
QualType  T,
Expr DimExpr,
SourceLocation  KeyLoc 
)
static

◆ EvaluateBinaryTypeTrait()

static bool EvaluateBinaryTypeTrait ( Sema Self,
TypeTrait  BTT,
const TypeSourceInfo Lhs,
const TypeSourceInfo Rhs,
SourceLocation  KeyLoc 
)
static

◆ EvaluateBooleanTypeTrait()

static bool EvaluateBooleanTypeTrait ( Sema S,
TypeTrait  Kind,
SourceLocation  KWLoc,
ArrayRef< TypeSourceInfo * >  Args,
SourceLocation  RParenLoc,
bool  IsDependent 
)
static

◆ EvaluateExpressionTrait()

static bool EvaluateExpressionTrait ( ExpressionTrait  ET,
Expr E 
)
static

◆ EvaluateUnaryTypeTrait()

static bool EvaluateUnaryTypeTrait ( Sema Self,
TypeTrait  UTT,
SourceLocation  KeyLoc,
TypeSourceInfo TInfo 
)
static

Definition at line 5201 of file SemaExprCXX.cpp.

References clang::AS_public, clang::C, clang::RecordDecl::canPassInRegisters(), clang::Destructor, DiagnoseVLAInCXXTypeTrait(), clang::Type::getAs(), clang::Type::getAsCXXRecordDecl(), clang::FunctionProtoType::getNumParams(), clang::TypeSourceInfo::getType(), clang::Decl::hasAttr(), clang::CXXRecordDecl::hasNonTrivialCopyAssignment(), clang::CXXRecordDecl::hasNonTrivialCopyConstructor(), clang::CXXRecordDecl::hasNonTrivialDefaultConstructor(), clang::CXXRecordDecl::hasNonTrivialMoveAssignment(), clang::CXXRecordDecl::hasNonTrivialMoveConstructor(), HasNoThrowOperator(), clang::CXXRecordDecl::hasTrivialCopyAssignment(), clang::CXXRecordDecl::hasTrivialCopyConstructor(), clang::CXXRecordDecl::hasTrivialDefaultConstructor(), clang::CXXRecordDecl::hasTrivialDestructor(), clang::CXXRecordDecl::hasTrivialMoveAssignment(), clang::CXXRecordDecl::hasTrivialMoveConstructor(), clang::CXXRecordDecl::isAbstract(), clang::Type::isAggregateType(), clang::Type::isAnyComplexType(), clang::Type::isAnyPointerType(), clang::Type::isArithmeticType(), clang::Type::isArrayType(), clang::Type::isClassType(), clang::Type::isCompoundType(), clang::CXXMethodDecl::isCopyAssignmentOperator(), clang::Type::isDependentType(), clang::CXXRecordDecl::isEmpty(), clang::Type::isEnumeralType(), clang::Type::isExtVectorType(), clang::Type::isFloatingType(), clang::Type::isFunctionType(), clang::Type::isFundamentalType(), clang::Type::isIncompleteArrayType(), clang::Type::isIncompleteType(), clang::Type::isIntegralType(), clang::Type::isInterfaceType(), clang::Type::isLiteralType(), clang::Type::isLValueReferenceType(), clang::Type::isMemberDataPointerType(), clang::Type::isMemberFunctionPointerType(), clang::Type::isMemberPointerType(), clang::CXXMethodDecl::isMoveAssignmentOperator(), clang::FunctionProtoType::isNothrow(), clang::Type::isNullPtrType(), clang::Type::isObjCLifetimeType(), clang::Type::isObjectType(), clang::CXXRecordDecl::isPolymorphic(), clang::Type::isReferenceType(), clang::Type::isRValueReferenceType(), clang::Type::isScalarType(), clang::Type::isScopedEnumeralType(), clang::Type::isSignedIntegerType(), clang::Type::isStandardLayoutType(), clang::Type::isStructureType(), clang::TagDecl::isUnion(), clang::Type::isUnionType(), clang::Type::isUnsignedIntegerType(), clang::Type::isVectorType(), clang::Type::isVoidType(), clang::Qualifiers::OCL_Autoreleasing, clang::Qualifiers::OCL_ExplicitNone, clang::Qualifiers::OCL_None, clang::Qualifiers::OCL_Strong, clang::Qualifiers::OCL_Weak, clang::Self, and clang::T.

Referenced by EvaluateBooleanTypeTrait().

◆ FindConditionalOverload()

static bool FindConditionalOverload ( Sema Self,
ExprResult LHS,
ExprResult RHS,
SourceLocation  QuestionLoc 
)
static

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 6505 of file SemaExprCXX.cpp.

References clang::Sema::AA_Converting, clang::OverloadCandidateSet::BestViableFunction(), 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().

◆ GetReturnType()

static TypeTraitReturnType GetReturnType ( TypeTrait  Kind)
static

Definition at line 5822 of file SemaExprCXX.cpp.

◆ getUnambiguousPublicSubobjects()

static void getUnambiguousPublicSubobjects ( CXXRecordDecl RD,
llvm::SmallVectorImpl< CXXRecordDecl * > &  Objects 
)
static

Definition at line 969 of file SemaExprCXX.cpp.

References collectPublicBases().

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

◆ getUuidAttrOfType()

static void getUuidAttrOfType ( Sema SemaRef,
QualType  QT,
llvm::SmallSetVector< const UuidAttr *, 1 > &  UuidAttrs 
)
static

◆ hasNewExtendedAlignment()

static bool hasNewExtendedAlignment ( Sema S,
QualType  AllocType 
)
static

Determine whether a type has new-extended alignment.

This may be called when the type is incomplete (for a delete-expression with an incomplete pointee type), in which case it will conservatively return false if the alignment is not known.

Definition at line 1843 of file SemaExprCXX.cpp.

References clang::Sema::getASTContext(), clang::Sema::getLangOpts(), clang::TargetInfo::getNewAlign(), clang::ASTContext::getTargetInfo(), and clang::ASTContext::getTypeAlignIfKnown().

Referenced by clang::Sema::ActOnCXXDelete(), doesUsualArrayDeleteWantSize(), clang::Sema::FindAllocationFunctions(), clang::Sema::FindDeallocationFunction(), and clang::Sema::FindDeallocationFunctionForDestructor().

◆ HasNoThrowOperator()

static bool HasNoThrowOperator ( const RecordType RT,
OverloadedOperatorKind  Op,
Sema Self,
SourceLocation  KeyLoc,
ASTContext C,
bool(CXXRecordDecl::*)() const  HasTrivial,
bool(CXXRecordDecl::*)() const  HasNonTrivial,
bool(CXXMethodDecl::*)() const  IsDesiredOp 
)
static

◆ isLegalArrayNewInitializer()

static bool isLegalArrayNewInitializer ( CXXNewInitializationStyle  Style,
Expr Init,
bool  IsCPlusPlus20 
)
static

Definition at line 2009 of file SemaExprCXX.cpp.

References clang::Braces, and clang::Init.

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

◆ isNonPlacementDeallocationFunction()

static bool isNonPlacementDeallocationFunction ( Sema S,
FunctionDecl FD 
)
static

◆ isValidSizelessVectorForConditionalCondition()

static bool isValidSizelessVectorForConditionalCondition ( ASTContext Ctx,
QualType  CondTy 
)
static

◆ isValidVectorForConditionalCondition()

static bool isValidVectorForConditionalCondition ( ASTContext Ctx,
QualType  CondTy 
)
static

◆ MaybeDecrementCount()

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

◆ noteOperatorArrows()

static void noteOperatorArrows ( Sema S,
ArrayRef< FunctionDecl * >  OperatorArrows 
)
static

Note a set of 'operator->' functions that were used for a member access.

Definition at line 7801 of file SemaExprCXX.cpp.

References clang::SemaBase::Diag().

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

◆ resolveAllocationOverload()

static bool resolveAllocationOverload ( Sema S,
LookupResult R,
SourceRange  Range,
SmallVectorImpl< Expr * > &  Args,
bool PassAlignment,
FunctionDecl *&  Operator,
OverloadCandidateSet AlignedCandidates,
Expr AlignArg,
bool  Diagnose 
)
static

◆ resolveBuiltinNewDeleteOverload()

static bool resolveBuiltinNewDeleteOverload ( Sema S,
CallExpr TheCall,
bool  IsDelete,
FunctionDecl *&  Operator 
)
static

◆ resolveDeallocationOverload()

static UsualDeallocFnInfo resolveDeallocationOverload ( Sema S,
LookupResult R,
bool  WantSize,
bool  WantAlign,
llvm::SmallVectorImpl< UsualDeallocFnInfo > *  BestFns = nullptr 
)
static

Select the correct "usual" deallocation function to use from a selection of deallocation functions (either global or class-scope).

Definition at line 1851 of file SemaExprCXX.cpp.

References clang::LookupResult::begin(), clang::SemaCUDA::CFP_Never, clang::LookupResult::end(), and isNonPlacementDeallocationFunction().

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

◆ TryClassUnification()

static bool TryClassUnification ( Sema Self,
Expr From,
Expr To,
SourceLocation  QuestionLoc,
bool HaveConversion,
QualType ToType 
)
static

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 6415 of file SemaExprCXX.cpp.

References clang::InitializationKind::CreateCopy(), clang::InitializationSequence::Diagnose(), clang::InitializationSequence::Failed(), clang::Type::getAs(), 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()

static bool VariableCanNeverBeAConstantExpression ( VarDecl Var,
ASTContext Context 
)
inlinestatic