clang API Documentation

Defines | Enumerations | Functions
SemaDeclCXX.cpp File Reference
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/CXXFieldCollector.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTMutationListener.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeOrdering.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/STLExtras.h"
#include <map>
#include <set>
#include "clang/AST/TypeLocNodes.def"
#include "clang/Basic/OperatorKinds.def"
Include dependency graph for SemaDeclCXX.cpp:

Go to the source code of this file.

Defines

#define ABSTRACT_TYPELOC(CLASS, PARENT)
#define TYPELOC(CLASS, PARENT)   case TypeLoc::CLASS: Check(cast<CLASS##TypeLoc>(TL), Sel); break;
#define CheckPolymorphic(Type)
#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly)   , { Unary, Binary, MemberOnly }

Enumerations

enum  ImplicitInitializerKind { IIK_Default, IIK_Copy, IIK_Move }

Functions

static bool CheckConstexprParameterTypes (Sema &SemaRef, const FunctionDecl *FD, Sema::CheckConstexprKind CCK)
static bool CheckConstexprDeclStmt (Sema &SemaRef, const FunctionDecl *Dcl, DeclStmt *DS)
static void CheckConstexprCtorInitializer (Sema &SemaRef, const FunctionDecl *Dcl, FieldDecl *Field, llvm::SmallSet< Decl *, 16 > &Inits, bool &Diagnosed)
static CXXRecordDeclGetClassForType (QualType T)
static bool FindBaseInitializer (Sema &SemaRef, CXXRecordDecl *ClassDecl, QualType BaseType, const CXXBaseSpecifier *&DirectBaseSpec, const CXXBaseSpecifier *&VirtualBaseSpec)
 Find the direct and/or virtual base specifiers that correspond to the given base type, for use in base initialization within a constructor.
static void CheckForDanglingReferenceOrPointer (Sema &S, ValueDecl *Member, Expr *Init, SourceLocation IdLoc)
static bool InitExprContainsUninitializedFields (const Stmt *S, const ValueDecl *LhsField, SourceLocation *L)
static ExprCastForMoving (Sema &SemaRef, Expr *E)
static bool BuildImplicitBaseInitializer (Sema &SemaRef, CXXConstructorDecl *Constructor, ImplicitInitializerKind ImplicitInitKind, CXXBaseSpecifier *BaseSpec, bool IsInheritedVirtualBase, CXXCtorInitializer *&CXXBaseInit)
static bool RefersToRValueRef (Expr *MemRef)
static bool BuildImplicitMemberInitializer (Sema &SemaRef, CXXConstructorDecl *Constructor, ImplicitInitializerKind ImplicitInitKind, FieldDecl *Field, IndirectFieldDecl *Indirect, CXXCtorInitializer *&CXXMemberInit)
static bool isWithinAnonymousUnion (IndirectFieldDecl *F)
 Determine whether the given indirect field declaration is somewhere within an anonymous union.
static bool isIncompleteOrZeroLengthArrayType (ASTContext &Context, QualType T)
 Determine whether the given type is an incomplete or zero-lenfgth array type.
static bool CollectFieldInitializer (Sema &SemaRef, BaseAndFieldInfo &Info, FieldDecl *Field, IndirectFieldDecl *Indirect=0)
static void * GetKeyForTopLevelField (FieldDecl *Field)
static void * GetKeyForBase (ASTContext &Context, QualType BaseType)
static void * GetKeyForMember (ASTContext &Context, CXXCtorInitializer *Member)
static void DiagnoseBaseOrMemInitializerOrder (Sema &SemaRef, const CXXConstructorDecl *Constructor, CXXCtorInitializer **Inits, unsigned NumInits)
static void CheckAbstractClassUsage (AbstractUsageInfo &Info, CXXMethodDecl *MD)
 Check for invalid uses of an abstract type in a method declaration.
static void CheckAbstractClassUsage (AbstractUsageInfo &Info, CXXRecordDecl *RD)
 Check for invalid uses of an abstract type within a class definition.
static bool FindHiddenVirtualMethod (const CXXBaseSpecifier *Specifier, CXXBasePath &Path, void *UserData)
 Member lookup function that determines whether a given C++ method overloads virtual methods in a base class without overriding any, to be used with CXXRecordDecl::lookupInBases().
static bool FTIHasSingleVoidArgument (DeclaratorChunk::FunctionTypeInfo &FTI)
static NamespaceDeclgetNamespaceDecl (NamedDecl *D)
static ClassTemplateDeclLookupStdInitializerList (Sema &S, SourceLocation Loc)
static bool IsUsingDirectiveInToplevelContext (DeclContext *CurContext)
 Determine whether a using statement is in a context where it will be apply in all contexts.
static bool TryNamespaceTypoCorrection (Sema &S, LookupResult &R, Scope *Sc, CXXScopeSpec &SS, SourceLocation IdentLoc, IdentifierInfo *Ident)
static bool IsEquivalentForUsingDecl (ASTContext &Context, NamedDecl *D1, NamedDecl *D2, bool &SuppressRedeclaration)
 Determine whether a using declaration considers the given declarations as "equivalent", e.g., if they are redeclarations of the same entity or are both typedefs of the same type.
static CXXConstructorDeclgetDefaultedDefaultConstructorUnsafe (Sema &Self, CXXRecordDecl *D)
static StmtResult BuildSingleCopyAssign (Sema &S, SourceLocation Loc, QualType T, Expr *To, Expr *From, bool CopyingBaseSubobject, bool Copying, unsigned Depth=0)
 Builds a statement that copies/moves the given entity from From to To.
static bool CheckOperatorNewDeleteDeclarationScope (Sema &SemaRef, const FunctionDecl *FnDecl)
static bool CheckOperatorNewDeleteTypes (Sema &SemaRef, const FunctionDecl *FnDecl, CanQualType ExpectedResultType, CanQualType ExpectedFirstParamType, unsigned DependentParamTypeDiag, unsigned InvalidParamTypeDiag)
static bool CheckOperatorNewDeclaration (Sema &SemaRef, const FunctionDecl *FnDecl)
static bool CheckOperatorDeleteDeclaration (Sema &SemaRef, const FunctionDecl *FnDecl)
static void SearchForReturnInStmt (Sema &Self, Stmt *S)
static void DelegatingCycleHelper (CXXConstructorDecl *Ctor, llvm::SmallSet< CXXConstructorDecl *, 4 > &Valid, llvm::SmallSet< CXXConstructorDecl *, 4 > &Invalid, llvm::SmallSet< CXXConstructorDecl *, 4 > &Current, Sema &S)

Define Documentation

#define ABSTRACT_TYPELOC (   CLASS,
  PARENT 
)
#define CheckPolymorphic (   Type)
Value:
void Check(Type TL, Sema::AbstractDiagSelID Sel) { \
    Visit(TL.getNextTypeLoc(), Sema::AbstractNone); \
  }

Definition at line 3518 of file SemaDeclCXX.cpp.

#define OVERLOADED_OPERATOR (   Name,
  Spelling,
  Token,
  Unary,
  Binary,
  MemberOnly 
)    , { Unary, Binary, MemberOnly }
#define TYPELOC (   CLASS,
  PARENT 
)    case TypeLoc::CLASS: Check(cast<CLASS##TypeLoc>(TL), Sel); break;

Enumeration Type Documentation

ImplicitInitializerKind - How an implicit base or member initializer should initialize its base or member.

Enumerator:
IIK_Default 
IIK_Copy 
IIK_Move 

Definition at line 2363 of file SemaDeclCXX.cpp.


Function Documentation

static bool BuildImplicitBaseInitializer ( Sema SemaRef,
CXXConstructorDecl Constructor,
ImplicitInitializerKind  ImplicitInitKind,
CXXBaseSpecifier BaseSpec,
bool  IsInheritedVirtualBase,
CXXCtorInitializer *&  CXXBaseInit 
) [static]
static bool BuildImplicitMemberInitializer ( Sema SemaRef,
CXXConstructorDecl Constructor,
ImplicitInitializerKind  ImplicitInitKind,
FieldDecl Field,
IndirectFieldDecl Indirect,
CXXCtorInitializer *&  CXXMemberInit 
) [static]

Definition at line 2455 of file SemaDeclCXX.cpp.

References clang::LookupResult::addDecl(), clang::AS_public, clang::Sema::BuildDeclRefExpr(), clang::Sema::BuildMemberReferenceExpr(), CastForMoving(), clang::Sema::Context, clang::VarDecl::Create(), clang::DeclRefExpr::Create(), clang::CXXCtorInitializer::Create(), clang::Sema::CreateBuiltinArraySubscriptExpr(), clang::InitializationKind::CreateDefault(), clang::InitializationKind::CreateDirect(), clang::Sema::CurContext, clang::Sema::DefaultLvalueConversion(), clang::Sema::Diag(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::IdentifierTable::get(), clang::ASTContext::getAsConstantArrayType(), clang::ASTContext::getBaseElementType(), clang::FieldDecl::getBitWidthValue(), clang::NamedDecl::getDeclName(), clang::Sema::getLangOptions(), clang::Decl::getLocation(), clang::QualType::getNonReferenceType(), clang::QualType::getObjCLifetime(), clang::FunctionDecl::getParamDecl(), clang::CXXMethodDecl::getParent(), clang::FieldDecl::getParent(), clang::ASTContext::getSizeType(), clang::ASTContext::getTagDeclType(), clang::ASTContext::getTrivialTypeSourceInfo(), clang::ValueDecl::getType(), clang::ASTContext::Idents, IIK_Copy, IIK_Default, IIK_Move, clang::InitializedEntity::InitializeElement(), clang::InitializedEntity::InitializeMember(), clang::FieldDecl::isBitField(), clang::QualType::isConstQualified(), clang::Decl::isImplicit(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), clang::Decl::isInvalidDecl(), clang::TagDecl::isUnion(), clang::Sema::LookupMemberName, clang::Sema::MarkDeclRefReferenced(), clang::Sema::MaybeCreateExprWithCleanups(), clang::Qualifiers::OCL_ExplicitNone, clang::Qualifiers::OCL_None, Param, clang::InitializationSequence::Perform(), RefersToRValueRef(), clang::SC_None, clang::ActionResult< PtrTy, CompressInvalid >::take(), clang::ActionResult< PtrTy, CompressInvalid >::takeAs(), and clang::VK_LValue.

Referenced by CollectFieldInitializer().

static StmtResult BuildSingleCopyAssign ( Sema S,
SourceLocation  Loc,
QualType  T,
Expr To,
Expr From,
bool  CopyingBaseSubobject,
bool  Copying,
unsigned  Depth = 0 
) [static]

Builds a statement that copies/moves the given entity from From to To.

This routine is used to copy/move the members of a class with an implicitly-declared copy/move assignment operator. When the entities being copied are arrays, this routine builds for loops to copy them.

Parameters:
SThe Sema object used for type-checking.
LocThe location where the implicit copy/move is being generated.
TThe type of the expressions being copied/moved. Both expressions must have this type.
ToThe expression we are copying/moving to.
FromThe expression we are copying/moving from.
CopyingBaseSubobjectWhether we're copying/moving a base subobject. Otherwise, it's a non-static member subobject.
CopyingWhether we're copying or moving.
DepthInternal parameter recording the depth of the recursion.
Returns:
A statement or a loop that copies the expressions.

Definition at line 7542 of file SemaDeclCXX.cpp.

References clang::Sema::ActOnForStmt(), clang::AS_protected, clang::AS_public, clang::AssertSuccess(), clang::prec::Assignment, clang::LookupResult::begin(), clang::BO_Assign, clang::BO_NE, clang::ASTContext::BoolTy, clang::Sema::BuildCallToMemberFunction(), clang::Sema::BuildDeclRefExpr(), clang::Sema::BuildMemberReferenceExpr(), CastForMoving(), clang::Sema::Context, clang::NestedNameSpecifier::Create(), clang::VarDecl::Create(), clang::IntegerLiteral::Create(), clang::Sema::CreateBuiltinArraySubscriptExpr(), clang::Sema::CreateBuiltinBinOp(), clang::Sema::CurContext, clang::ASTContext::DeclarationNames, clang::Sema::DefaultLvalueConversion(), clang::LookupResult::Filter::done(), clang::LookupResult::end(), clang::LookupResult::Filter::erase(), clang::IdentifierTable::get(), clang::ASTContext::getAsConstantArrayType(), clang::ASTContext::getCanonicalType(), clang::DeclarationNameTable::getCXXOperatorName(), clang::ArrayType::getElementType(), clang::ConstantArrayType::getSize(), clang::ASTContext::getSizeType(), clang::ASTContext::getTrivialTypeSourceInfo(), clang::QualType::getTypePtr(), clang::ASTContext::getTypeSize(), clang::LookupResult::Filter::hasNext(), clang::ASTContext::Idents, clang::CXXMethodDecl::isCopyAssignmentOperator(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), clang::CXXMethodDecl::isMoveAssignmentOperator(), clang::Sema::LookupOrdinaryName, clang::Sema::LookupQualifiedName(), clang::LookupResult::makeFilter(), clang::Sema::MakeFullExpr(), clang::CXXScopeSpec::MakeTrivial(), clang::LookupResult::Filter::next(), clang::OK_Ordinary, clang::Sema::Owned(), clang::SC_None, clang::VarDecl::setInit(), clang::StmtError(), clang::ActionResult< PtrTy, CompressInvalid >::take(), clang::ActionResult< PtrTy, CompressInvalid >::takeAs(), clang::UO_PreInc, clang::VK_LValue, and clang::VK_RValue.

Referenced by clang::Sema::DefineImplicitCopyAssignment(), and clang::Sema::DefineImplicitMoveAssignment().

static Expr* CastForMoving ( Sema SemaRef,
Expr E 
) [static]
static void CheckAbstractClassUsage ( AbstractUsageInfo &  Info,
CXXMethodDecl MD 
) [static]
static void CheckAbstractClassUsage ( AbstractUsageInfo &  Info,
CXXRecordDecl RD 
) [static]
static void CheckConstexprCtorInitializer ( Sema SemaRef,
const FunctionDecl Dcl,
FieldDecl Field,
llvm::SmallSet< Decl *, 16 > &  Inits,
bool &  Diagnosed 
) [static]

Check that the given field is initialized within a constexpr constructor.

Parameters:
DclThe constexpr constructor being checked.
FieldThe field being checked. This may be a member of an anonymous struct or union nested within the class being checked.
InitsAll declarations, including anonymous struct/union members and indirect members, for which any initialization was provided.
DiagnosedSet to true if an error is produced.

Definition at line 811 of file SemaDeclCXX.cpp.

References clang::Sema::Diag(), clang::RecordDecl::field_begin(), clang::RecordDecl::field_end(), clang::Decl::getLocation(), clang::ValueDecl::getType(), clang::FieldDecl::isAnonymousStructOrUnion(), clang::TagDecl::isUnion(), and clang::FieldDecl::isUnnamedBitfield().

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

static bool CheckConstexprDeclStmt ( Sema SemaRef,
const FunctionDecl Dcl,
DeclStmt DS 
) [static]
static bool CheckConstexprParameterTypes ( Sema SemaRef,
const FunctionDecl FD,
Sema::CheckConstexprKind  CCK 
) [static]
static void CheckForDanglingReferenceOrPointer ( Sema S,
ValueDecl Member,
Expr Init,
SourceLocation  IdLoc 
) [static]

Checks a member initializer expression for cases where reference (or pointer) members are bound to by-value parameters (or their addresses).

Definition at line 1963 of file SemaDeclCXX.cpp.

References clang::Sema::Diag(), clang::DeclRefExpr::getDecl(), clang::Expr::getExprLoc(), clang::Decl::getLocation(), clang::Stmt::getSourceRange(), clang::ValueDecl::getType(), clang::Expr::IgnoreParenImpCasts(), clang::Expr::IgnoreParens(), and clang::UO_AddrOf.

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

static bool CheckOperatorDeleteDeclaration ( Sema SemaRef,
const FunctionDecl FnDecl 
) [static]
static bool CheckOperatorNewDeclaration ( Sema SemaRef,
const FunctionDecl FnDecl 
) [static]
static bool CheckOperatorNewDeleteDeclarationScope ( Sema SemaRef,
const FunctionDecl FnDecl 
) [inline, static]
static bool CheckOperatorNewDeleteTypes ( Sema SemaRef,
const FunctionDecl FnDecl,
CanQualType  ExpectedResultType,
CanQualType  ExpectedFirstParamType,
unsigned  DependentParamTypeDiag,
unsigned  InvalidParamTypeDiag 
) [inline, static]
static bool CollectFieldInitializer ( Sema SemaRef,
BaseAndFieldInfo &  Info,
FieldDecl Field,
IndirectFieldDecl Indirect = 0 
) [static]
static void DelegatingCycleHelper ( CXXConstructorDecl Ctor,
llvm::SmallSet< CXXConstructorDecl *, 4 > &  Valid,
llvm::SmallSet< CXXConstructorDecl *, 4 > &  Invalid,
llvm::SmallSet< CXXConstructorDecl *, 4 > &  Current,
Sema S 
) [static]
static void DiagnoseBaseOrMemInitializerOrder ( Sema SemaRef,
const CXXConstructorDecl Constructor,
CXXCtorInitializer **  Inits,
unsigned  NumInits 
) [static]
static bool FindBaseInitializer ( Sema SemaRef,
CXXRecordDecl ClassDecl,
QualType  BaseType,
const CXXBaseSpecifier *&  DirectBaseSpec,
const CXXBaseSpecifier *&  VirtualBaseSpec 
) [static]
static bool FindHiddenVirtualMethod ( const CXXBaseSpecifier Specifier,
CXXBasePath Path,
void *  UserData 
) [static]

Member lookup function that determines whether a given C++ method overloads virtual methods in a base class without overriding any, to be used with CXXRecordDecl::lookupInBases().

Definition at line 4934 of file SemaDeclCXX.cpp.

References clang::CXXBasePath::Decls, clang::DeclarationName::getNameKind(), clang::CXXBaseSpecifier::getType(), clang::DeclarationName::Identifier, and clang::DeclContext::lookup().

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

static bool FTIHasSingleVoidArgument ( DeclaratorChunk::FunctionTypeInfo FTI) [inline, static]
static CXXRecordDecl* GetClassForType ( QualType  T) [static]

Definition at line 1208 of file SemaDeclCXX.cpp.

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

static CXXConstructorDecl* getDefaultedDefaultConstructorUnsafe ( Sema Self,
CXXRecordDecl D 
) [static]
static void* GetKeyForBase ( ASTContext Context,
QualType  BaseType 
) [static]
static void* GetKeyForMember ( ASTContext Context,
CXXCtorInitializer Member 
) [static]
static void* GetKeyForTopLevelField ( FieldDecl Field) [static]

Definition at line 2970 of file SemaDeclCXX.cpp.

References clang::ValueDecl::getType().

Referenced by DiagnoseBaseOrMemInitializerOrder().

static NamespaceDecl* getNamespaceDecl ( NamedDecl D) [inline, static]

getNamespaceDecl - Returns the namespace a decl represents. If the decl is a namespace alias, returns the namespace it points to.

Definition at line 5759 of file SemaDeclCXX.cpp.

Referenced by clang::Sema::ActOnNamespaceAliasDef(), and clang::Sema::ActOnUsingDirective().

static bool InitExprContainsUninitializedFields ( const Stmt S,
const ValueDecl LhsField,
SourceLocation L 
) [static]

Checks an initializer expression for use of uninitialized fields, such as containing the field that is being initialized. Returns true if there is an uninitialized field was used an updates the SourceLocation parameter; false otherwise.

Definition at line 2020 of file SemaDeclCXX.cpp.

References clang::Stmt::children(), clang::Expr::IgnoreParenCasts(), NULL, and clang::UO_AddrOf.

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

static bool IsEquivalentForUsingDecl ( ASTContext Context,
NamedDecl D1,
NamedDecl D2,
bool &  SuppressRedeclaration 
) [static]

Determine whether a using declaration considers the given declarations as "equivalent", e.g., if they are redeclarations of the same entity or are both typedefs of the same type.

Definition at line 6157 of file SemaDeclCXX.cpp.

References clang::Decl::getCanonicalDecl(), and clang::ASTContext::hasSameType().

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

static bool isIncompleteOrZeroLengthArrayType ( ASTContext Context,
QualType  T 
) [static]

Determine whether the given type is an incomplete or zero-lenfgth array type.

Definition at line 2730 of file SemaDeclCXX.cpp.

References clang::ASTContext::getAsConstantArrayType().

Referenced by CollectFieldInitializer(), and clang::Sema::MarkBaseAndMemberDestructorsReferenced().

static bool IsUsingDirectiveInToplevelContext ( DeclContext CurContext) [static]

Determine whether a using statement is in a context where it will be apply in all contexts.

Definition at line 5931 of file SemaDeclCXX.cpp.

References clang::DeclContext::getDeclKind(), and clang::DeclContext::getParent().

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

static bool isWithinAnonymousUnion ( IndirectFieldDecl F) [static]

Determine whether the given indirect field declaration is somewhere within an anonymous union.

Definition at line 2717 of file SemaDeclCXX.cpp.

References clang::IndirectFieldDecl::chain_begin(), and clang::IndirectFieldDecl::chain_end().

Referenced by CollectFieldInitializer().

static ClassTemplateDecl* LookupStdInitializerList ( Sema S,
SourceLocation  Loc 
) [static]
static bool RefersToRValueRef ( Expr MemRef) [static]

Definition at line 2449 of file SemaDeclCXX.cpp.

References clang::ValueDecl::getType().

Referenced by BuildImplicitMemberInitializer().

static void SearchForReturnInStmt ( Sema Self,
Stmt S 
) [static]
static bool TryNamespaceTypoCorrection ( Sema S,
LookupResult R,
Scope Sc,
CXXScopeSpec SS,
SourceLocation  IdentLoc,
IdentifierInfo Ident 
) [static]