clang API Documentation

Classes | Functions
SemaDecl.cpp File Reference
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/CXXFieldCollector.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "TypeLocBuilder.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/EvaluatedExprVisitor.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/CharUnits.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Parse/ParseDiagnostic.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Sema/DelayedDiagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/ModuleLoader.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Triple.h"
#include <algorithm>
#include <cstring>
#include <functional>
Include dependency graph for SemaDecl.cpp:

Go to the source code of this file.

Classes

struct  FindOverriddenMethodData
 Data used with FindOverriddenMethod. More...

Functions

static bool isResultTypeOrTemplate (LookupResult &R, const Token &NextToken)
 Determine whether the given result set contains either a type name or.
static bool AllowOverloadingOfFunction (LookupResult &Previous, ASTContext &Context)
 Determine whether we allow overloading of the function PrevDecl with another declaration.
static bool isOutOfScopePreviousDeclaration (NamedDecl *PrevDecl, DeclContext *DC, ASTContext &Context)
 Determines whether the given declaration is an out-of-scope previous declaration.
static bool isUsingDecl (NamedDecl *D)
static void RemoveUsingDecls (LookupResult &R)
 Removes using shadow declarations from the lookup results.
static bool IsDisallowedCopyOrAssign (const CXXMethodDecl *D)
 Check for this common pattern:
static bool ShouldDiagnoseUnusedDecl (const NamedDecl *D)
static void GenerateFixForUnusedDecl (const NamedDecl *D, ASTContext &Ctx, FixItHint &Hint)
static void CheckPoppedLabel (LabelDecl *L, Sema &S)
static bool DeclHasAttr (const Decl *D, const Attr *A)
static void mergeParamDeclAttributes (ParmVarDecl *newDecl, const ParmVarDecl *oldDecl, ASTContext &C)
static bool canRedefineFunction (const FunctionDecl *FD, const LangOptions &LangOpts)
static bool CheckAnonMemberRedeclaration (Sema &SemaRef, Scope *S, DeclContext *Owner, DeclarationName Name, SourceLocation NameLoc, unsigned diagnostic)
static bool InjectAnonymousStructOrUnionMembers (Sema &SemaRef, Scope *S, DeclContext *Owner, RecordDecl *AnonRecord, AccessSpecifier AS, SmallVector< NamedDecl *, 2 > &Chaining, bool MSAnonStruct)
static StorageClass StorageClassSpecToVarDeclStorageClass (DeclSpec::SCS StorageClassSpec)
static StorageClass StorageClassSpecToFunctionDeclStorageClass (DeclSpec::SCS StorageClassSpec)
static QualType getCoreType (QualType Ty)
static bool hasSimilarParameters (ASTContext &Context, FunctionDecl *Declaration, FunctionDecl *Definition, llvm::SmallVectorImpl< unsigned > &Params)
static bool RebuildDeclaratorInCurrentInstantiation (Sema &S, Declarator &D, DeclarationName Name)
static QualType TryToFixInvalidVariablyModifiedType (QualType T, ASTContext &Context, bool &SizeIsNegative, llvm::APSInt &Oversized)
static void SetNestedNameSpecifier (DeclaratorDecl *DD, Declarator &D)
static bool FindOverriddenMethod (const CXXBaseSpecifier *Specifier, CXXBasePath &Path, void *UserData)
 Member lookup function that determines whether a given C++ method overrides a method in a base class, to be used with CXXRecordDecl::lookupInBases().
static NamedDeclDiagnoseInvalidRedeclaration (Sema &SemaRef, LookupResult &Previous, FunctionDecl *NewFD, ActOnFDArgs &ExtraArgs)
 Generate diagnostics for an invalid function redeclaration.
static FunctionDecl::StorageClass getFunctionStorageClass (Sema &SemaRef, Declarator &D)
static FunctionDeclCreateNewFunctionDecl (Sema &SemaRef, Declarator &D, DeclContext *DC, QualType &R, TypeSourceInfo *TInfo, FunctionDecl::StorageClass SC, bool &IsVirtualOkay)
static bool ShouldWarnAboutMissingPrototype (const FunctionDecl *FD)
static ObjCIvarDecl::AccessControl TranslateIvarVisibility (tok::ObjCKeywordKind ivarVisibility)
static bool isRepresentableIntegerValue (ASTContext &Context, llvm::APSInt &Value, QualType T)
 Determine whether the given integral value is representable within the given type T.
static QualType getNextLargerIntegralType (ASTContext &Context, QualType T)

Function Documentation

static bool AllowOverloadingOfFunction ( LookupResult Previous,
ASTContext Context 
) [static]

Determine whether we allow overloading of the function PrevDecl with another declaration.

This routine determines whether overloading is possible, not whether some new function is actually an overload. It will return true in C++ (where we can always provide overloads) or, as an extension, in C when the previous function is already an overloaded function declaration or has the "overloadable" attribute.

Definition at line 896 of file SemaDecl.cpp.

References clang::LookupResult::Found, clang::LookupResult::FoundOverloaded, clang::LookupResult::getFoundDecl(), clang::ASTContext::getLangOptions(), clang::LookupResult::getResultKind(), and clang::Decl::hasAttr().

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

static bool canRedefineFunction ( const FunctionDecl FD,
const LangOptions LangOpts 
) [static]

canRedefineFunction - checks if a function can be redefined. Currently, only extern inline functions can be redefined, and even then only in GNU89 mode.

Definition at line 1695 of file SemaDecl.cpp.

References clang::FunctionDecl::getStorageClass(), clang::Decl::hasAttr(), clang::FunctionDecl::isInlineSpecified(), and clang::SC_Extern.

Referenced by clang::Sema::CheckForFunctionRedefinition(), and clang::Sema::MergeFunctionDecl().

static bool CheckAnonMemberRedeclaration ( Sema SemaRef,
Scope S,
DeclContext Owner,
DeclarationName  Name,
SourceLocation  NameLoc,
unsigned  diagnostic 
) [static]

We are trying to inject an anonymous member into the given scope; check if there's an existing declaration that can't be overloaded.

Returns:
true if this is a forbidden redeclaration

Definition at line 2535 of file SemaDecl.cpp.

References clang::Sema::Diag(), clang::Sema::ForRedeclaration, clang::LookupResult::getAsSingle(), clang::Decl::getLocation(), clang::LookupResult::getRepresentativeDecl(), clang::NamedDecl::getUnderlyingDecl(), clang::Sema::isDeclInScope(), clang::Sema::LookupMemberName, and clang::Sema::LookupName().

Referenced by InjectAnonymousStructOrUnionMembers().

static void CheckPoppedLabel ( LabelDecl L,
Sema S 
) [static]
static FunctionDecl* CreateNewFunctionDecl ( Sema SemaRef,
Declarator D,
DeclContext DC,
QualType R,
TypeSourceInfo TInfo,
FunctionDecl::StorageClass  SC,
bool &  IsVirtualOkay 
) [static]

Definition at line 4630 of file SemaDecl.cpp.

References clang::Sema::AbstractReturnType, clang::Sema::AdjustDestructorExceptionSpec(), clang::Sema::CheckConstructorDeclarator(), clang::Sema::CheckConversionDeclarator(), clang::Sema::CheckDestructorDeclarator(), clang::Sema::Context, clang::CXXMethodDecl::Create(), clang::FunctionDecl::Create(), clang::CXXConstructorDecl::Create(), clang::CXXDestructorDecl::Create(), clang::CXXConversionDecl::Create(), clang::Sema::CurContext, clang::DeclarationName::CXXConstructorName, clang::DeclarationName::CXXConversionFunctionName, clang::DeclarationName::CXXDestructorName, clang::Sema::Diag(), clang::EST_None, clang::DeclarationName::getAsIdentifierInfo(), clang::SourceRange::getBegin(), clang::DeclarationName::getCXXOverloadedOperator(), clang::Declarator::getDeclSpec(), clang::CXXRecordDecl::getDefinition(), clang::Declarator::getFunctionTypeInfo(), clang::Declarator::getIdentifierLoc(), clang::Sema::getLangOptions(), clang::DeclarationNameInfo::getName(), clang::Sema::GetNameForDeclarator(), clang::DeclarationName::getNameKind(), clang::Declarator::getSourceRange(), clang::DeclSpec::getStorageClassSpecAsWritten(), clang::QualType::getTypePtr(), clang::DeclSpec::getTypeSpecTypeLoc(), clang::DeclaratorChunk::FunctionTypeInfo::hasPrototype, clang::TagDecl::isBeingDefined(), clang::DeclSpec::isConstexprSpecified(), clang::TagDecl::isDependentType(), clang::DeclSpec::isExplicitSpecified(), clang::Declarator::isFunctionDeclarator(), clang::DeclSpec::isInlineSpecified(), clang::Declarator::isInvalidType(), clang::DeclContext::isRecord(), clang::Sema::RequireNonAbstractType(), clang::SC_Static, clang::Decl::setInvalidDecl(), clang::Declarator::setInvalidType(), clang::Decl::setLexicalDeclContext(), and StorageClassSpecToFunctionDeclStorageClass().

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

static bool DeclHasAttr ( const Decl D,
const Attr A 
) [static]

DeclhasAttr - returns true if decl Declaration already has the target attribute.

Definition at line 1577 of file SemaDecl.cpp.

References clang::Decl::attr_begin(), clang::Decl::attr_end(), and clang::Attr::getKind().

Referenced by clang::Sema::mergeDeclAttributes(), and mergeParamDeclAttributes().

static NamedDecl* DiagnoseInvalidRedeclaration ( Sema SemaRef,
LookupResult Previous,
FunctionDecl NewFD,
ActOnFDArgs &  ExtraArgs 
) [static]

Generate diagnostics for an invalid function redeclaration.

This routine handles generating the diagnostic messages for an invalid function redeclaration, including finding possible similar declarations or performing typo correction if there are no previous declarations with the same name.

Returns a NamedDecl iff typo correction was performed and substituting in the new declaration name does not cause new errors.

Definition at line 4468 of file SemaDecl.cpp.

References clang::Sema::ActOnFunctionDeclarator(), clang::LookupResult::addDecl(), clang::TypoCorrection::begin(), clang::LookupResult::begin(), clang::LookupResult::clear(), clang::Qualifiers::Const, clang::Sema::Context, clang::Sema::CorrectTypo(), clang::FixItHint::CreateReplacement(), clang::Sema::Diag(), clang::TypoCorrection::end(), clang::LookupResult::end(), clang::Sema::ForRedeclaration, clang::DeclarationName::getAsIdentifierInfo(), clang::TypoCorrection::getAsString(), clang::TypoCorrection::getCorrection(), clang::TypoCorrection::getCorrectionAsIdentifierInfo(), clang::Decl::getDeclContext(), clang::NamedDecl::getDeclName(), clang::SourceRange::getEnd(), clang::Sema::getLangOptions(), clang::Decl::getLocation(), clang::FunctionDecl::getParamDecl(), clang::TypoCorrection::getQuoted(), clang::FunctionDecl::getSourceRange(), clang::ValueDecl::getType(), clang::DeclaratorDecl::getTypeSourceInfo(), clang::DeclaratorDecl::getTypeSpecStartLoc(), clang::Sema::SFINAETrap::hasErrorOccurred(), hasSimilarParameters(), clang::Sema::LookupOrdinaryName, clang::Sema::LookupQualifiedName(), NULL, clang::Decl::setInvalidDecl(), and clang::LookupResult::setLookupName().

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

static bool FindOverriddenMethod ( const CXXBaseSpecifier Specifier,
CXXBasePath Path,
void *  UserData 
) [static]
static void GenerateFixForUnusedDecl ( const NamedDecl D,
ASTContext Ctx,
FixItHint Hint 
) [static]
static QualType getCoreType ( QualType  Ty) [static]

Definition at line 3074 of file SemaDecl.cpp.

References clang::QualType::withoutLocalFastQualifiers().

Referenced by hasSimilarParameters().

static FunctionDecl::StorageClass getFunctionStorageClass ( Sema SemaRef,
Declarator D 
) [static]
static QualType getNextLargerIntegralType ( ASTContext Context,
QualType  T 
) [static]
static bool hasSimilarParameters ( ASTContext Context,
FunctionDecl Declaration,
FunctionDecl Definition,
llvm::SmallVectorImpl< unsigned > &  Params 
) [static]

hasSimilarParameters - Determine whether the C++ functions Declaration and Definition have "nearly" matching parameters. This heuristic is used to improve diagnostics in the case where an out-of-line function definition doesn't match any declaration within the class or namespace. Also sets Params to the list of indices to the parameters that differ between the declaration and the definition. If hasSimilarParameters returns true and Params is empty, then all of the parameters match.

Definition at line 3092 of file SemaDecl.cpp.

References clang::QualType::getBaseTypeIdentifier(), getCoreType(), clang::FunctionDecl::getParamDecl(), clang::ValueDecl::getType(), clang::ASTContext::hasSameType(), clang::ASTContext::hasSameUnqualifiedType(), and clang::FunctionDecl::param_size().

Referenced by DiagnoseInvalidRedeclaration().

static bool InjectAnonymousStructOrUnionMembers ( Sema SemaRef,
Scope S,
DeclContext Owner,
RecordDecl AnonRecord,
AccessSpecifier  AS,
SmallVector< NamedDecl *, 2 > &  Chaining,
bool  MSAnonStruct 
) [static]

InjectAnonymousStructOrUnionMembers - Inject the members of the anonymous struct or union AnonRecord into the owning context Owner and scope S. This routine will be invoked just after we realize that an unnamed union or struct is actually an anonymous union or struct, e.g.,

 union {
   int i;
   float f;
 }; // InjectAnonymousStructOrUnionMembers called here to inject i and
    // f into the surrounding scope.x

This routine is recursive, injecting the names of nested anonymous structs/unions into the owning context and scope as well.

Definition at line 2577 of file SemaDecl.cpp.

References clang::AS_none, CheckAnonMemberRedeclaration(), clang::Sema::Context, clang::IndirectFieldDecl::Create(), clang::DeclContext::decls_begin(), clang::DeclContext::decls_end(), clang::NamedDecl::getDeclName(), clang::NamedDecl::getIdentifier(), clang::Decl::getLocation(), clang::ValueDecl::getType(), clang::TagDecl::isUnion(), clang::Sema::PushOnScopeChains(), clang::Decl::setAccess(), and clang::Decl::setImplicit().

Referenced by clang::Sema::BuildAnonymousStructOrUnion(), and clang::Sema::BuildMicrosoftCAnonymousStruct().

static bool IsDisallowedCopyOrAssign ( const CXXMethodDecl D) [static]

Check for this common pattern:

 class S {
   S(const S&); // DO NOT IMPLEMENT
   void operator=(const S&); // DO NOT IMPLEMENT
 };

Definition at line 1042 of file SemaDecl.cpp.

References clang::FunctionDecl::doesThisDeclarationHaveABody().

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

static bool isOutOfScopePreviousDeclaration ( NamedDecl PrevDecl,
DeclContext DC,
ASTContext Context 
) [static]

Determines whether the given declaration is an out-of-scope previous declaration.

This routine should be invoked when name lookup has found a previous declaration (PrevDecl) that is not in the scope where a new declaration by the same name is being introduced. If the new declaration occurs in a local scope, previous declarations with linkage may still be considered previous declarations (C99 6.2.2p4-5, C++ [basic.link]p6).

Parameters:
PrevDeclthe previous declaration found by name lookup
DCthe context in which the new declaration is being declared.
Returns:
true if PrevDecl is an out-of-scope previous declaration for a new delcaration with the same name.

Definition at line 3759 of file SemaDecl.cpp.

References clang::DeclContext::Equals(), clang::Decl::getDeclContext(), clang::DeclContext::getEnclosingNamespaceContext(), clang::ASTContext::getLangOptions(), clang::DeclContext::getRedeclContext(), clang::NamedDecl::hasLinkage(), clang::DeclContext::isFunctionOrMethod(), and clang::DeclContext::isRecord().

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

static bool isRepresentableIntegerValue ( ASTContext Context,
llvm::APSInt &  Value,
QualType  T 
) [static]

Determine whether the given integral value is representable within the given type T.

Definition at line 9526 of file SemaDecl.cpp.

References clang::ASTContext::getIntWidth().

Referenced by clang::Sema::ActOnEnumBody(), and clang::Sema::CheckEnumConstant().

static bool isResultTypeOrTemplate ( LookupResult R,
const Token NextToken 
) [static]

Determine whether the given result set contains either a type name or.

Definition at line 458 of file SemaDecl.cpp.

References clang::LookupResult::begin(), clang::LookupResult::end(), clang::Sema::getLangOptions(), clang::LookupResult::getSema(), and clang::Token::is().

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

static bool isUsingDecl ( NamedDecl D) [static]

Definition at line 1019 of file SemaDecl.cpp.

Referenced by RemoveUsingDecls().

static void mergeParamDeclAttributes ( ParmVarDecl newDecl,
const ParmVarDecl oldDecl,
ASTContext C 
) [static]
static bool RebuildDeclaratorInCurrentInstantiation ( Sema S,
Declarator D,
DeclarationName  Name 
) [static]

NeedsRebuildingInCurrentInstantiation - Checks whether the given declarator needs to be rebuilt in the current instantiation. Any bits of declarator which appear before the name are valid for consideration here. That's specifically the type in the decl spec and the base type in any member-pointer chunks.

Definition at line 3127 of file SemaDecl.cpp.

References clang::Sema::Context, clang::Sema::CreateParsedType(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Declarator::getIdentifierLoc(), clang::Declarator::getMutableDeclSpec(), clang::Declarator::getNumTypeObjects(), clang::DeclSpec::getRepAsExpr(), clang::DeclSpec::getRepAsType(), clang::ASTContext::getTrivialTypeSourceInfo(), clang::TypeSourceInfo::getType(), clang::Sema::GetTypeFromParser(), clang::Declarator::getTypeObject(), clang::DeclSpec::getTypeSpecType(), clang::DeclSpec::getTypeSpecTypeLoc(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), clang::QualType::isNull(), clang::DeclaratorChunk::Kind, clang::DeclaratorChunk::Mem, clang::DeclaratorChunk::MemberPointer, clang::Sema::RebuildExprInCurrentInstantiation(), clang::Sema::RebuildNestedNameSpecifierInCurrentInstantiation(), clang::Sema::RebuildTypeInCurrentInstantiation(), clang::DeclSpec::TST_atomic, clang::DeclSpec::TST_decltype, clang::DeclSpec::TST_typename, clang::DeclSpec::TST_typeofExpr, clang::DeclSpec::TST_typeofType, clang::DeclSpec::TST_underlyingType, clang::DeclSpec::UpdateExprRep(), and clang::DeclSpec::UpdateTypeRep().

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

static void RemoveUsingDecls ( LookupResult R) [static]
static void SetNestedNameSpecifier ( DeclaratorDecl DD,
Declarator D 
) [static]
static bool ShouldDiagnoseUnusedDecl ( const NamedDecl D) [static]
static bool ShouldWarnAboutMissingPrototype ( const FunctionDecl FD) [static]
static StorageClass StorageClassSpecToFunctionDeclStorageClass ( DeclSpec::SCS  StorageClassSpec) [static]

StorageClassSpecToFunctionDeclStorageClass - Maps a DeclSpec::SCS to a StorageClass. Any error reporting is up to the caller: illegal input values are mapped to SC_None.

Definition at line 2666 of file SemaDecl.cpp.

References clang::SC_Extern, clang::SC_None, clang::SC_PrivateExtern, clang::SC_Static, clang::DeclSpec::SCS_auto, clang::DeclSpec::SCS_extern, clang::DeclSpec::SCS_mutable, clang::DeclSpec::SCS_private_extern, clang::DeclSpec::SCS_register, clang::DeclSpec::SCS_static, clang::DeclSpec::SCS_typedef, and clang::DeclSpec::SCS_unspecified.

Referenced by CreateNewFunctionDecl().

static StorageClass StorageClassSpecToVarDeclStorageClass ( DeclSpec::SCS  StorageClassSpec) [static]
static ObjCIvarDecl::AccessControl TranslateIvarVisibility ( tok::ObjCKeywordKind  ivarVisibility) [static]

TranslateIvarVisibility - Translate visibility from a token ID to an AST enum value.

Definition at line 9006 of file SemaDecl.cpp.

References clang::ObjCIvarDecl::Package, clang::ObjCIvarDecl::Private, clang::ObjCIvarDecl::Protected, and clang::ObjCIvarDecl::Public.

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

static QualType TryToFixInvalidVariablyModifiedType ( QualType  T,
ASTContext Context,
bool &  SizeIsNegative,
llvm::APSInt &  Oversized 
) [static]