diff options
Diffstat (limited to 'include/clang/Sema/SemaInternal.h')
-rw-r--r-- | include/clang/Sema/SemaInternal.h | 98 |
1 files changed, 61 insertions, 37 deletions
diff --git a/include/clang/Sema/SemaInternal.h b/include/clang/Sema/SemaInternal.h index 01d4cc9679ef..9199b0fba2a5 100644 --- a/include/clang/Sema/SemaInternal.h +++ b/include/clang/Sema/SemaInternal.h @@ -24,44 +24,68 @@ namespace clang { inline PartialDiagnostic Sema::PDiag(unsigned DiagID) { return PartialDiagnostic(DiagID, Context.getDiagAllocator()); } -
-
-// This requires the variable to be non-dependent and the initializer
-// to not be value dependent.
-inline bool IsVariableAConstantExpression(VarDecl *Var, ASTContext &Context) {
- const VarDecl *DefVD = 0;
- return !isa<ParmVarDecl>(Var) &&
- Var->isUsableInConstantExpressions(Context) &&
- Var->getAnyInitializer(DefVD) && DefVD->checkInitIsICE();
-}
-
-// Directly mark a variable odr-used. Given a choice, prefer to use
-// MarkVariableReferenced since it does additional checks and then
-// calls MarkVarDeclODRUsed.
-// If the variable must be captured:
-// - if FunctionScopeIndexToStopAt is null, capture it in the CurContext
-// - else capture it in the DeclContext that maps to the
-// *FunctionScopeIndexToStopAt on the FunctionScopeInfo stack.
-inline void MarkVarDeclODRUsed(VarDecl *Var,
- SourceLocation Loc, Sema &SemaRef,
- const unsigned *const FunctionScopeIndexToStopAt) {
- // Keep track of used but undefined variables.
- // FIXME: We shouldn't suppress this warning for static data members.
- if (Var->hasDefinition(SemaRef.Context) == VarDecl::DeclarationOnly &&
- !Var->isExternallyVisible() &&
- !(Var->isStaticDataMember() && Var->hasInit())) {
- SourceLocation &old = SemaRef.UndefinedButUsed[Var->getCanonicalDecl()];
- if (old.isInvalid()) old = Loc;
- }
- QualType CaptureType, DeclRefType;
- SemaRef.tryCaptureVariable(Var, Loc, Sema::TryCapture_Implicit,
- /*EllipsisLoc*/ SourceLocation(),
- /*BuildAndDiagnose*/ true,
- CaptureType, DeclRefType,
- FunctionScopeIndexToStopAt);
-
- Var->markUsed(SemaRef.Context);
+ +inline bool +FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI) { + return FTI.NumParams == 1 && !FTI.isVariadic && + FTI.Params[0].Ident == nullptr && FTI.Params[0].Param && + cast<ParmVarDecl>(FTI.Params[0].Param)->getType()->isVoidType(); +} + +inline bool +FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI) { + // Assume FTI is well-formed. + return FTI.NumParams && !FTIHasSingleVoidParameter(FTI); } + +// This requires the variable to be non-dependent and the initializer +// to not be value dependent. +inline bool IsVariableAConstantExpression(VarDecl *Var, ASTContext &Context) { + const VarDecl *DefVD = nullptr; + return !isa<ParmVarDecl>(Var) && + Var->isUsableInConstantExpressions(Context) && + Var->getAnyInitializer(DefVD) && DefVD->checkInitIsICE(); +} + +// Directly mark a variable odr-used. Given a choice, prefer to use +// MarkVariableReferenced since it does additional checks and then +// calls MarkVarDeclODRUsed. +// If the variable must be captured: +// - if FunctionScopeIndexToStopAt is null, capture it in the CurContext +// - else capture it in the DeclContext that maps to the +// *FunctionScopeIndexToStopAt on the FunctionScopeInfo stack. +inline void MarkVarDeclODRUsed(VarDecl *Var, + SourceLocation Loc, Sema &SemaRef, + const unsigned *const FunctionScopeIndexToStopAt) { + // Keep track of used but undefined variables. + // FIXME: We shouldn't suppress this warning for static data members. + if (Var->hasDefinition(SemaRef.Context) == VarDecl::DeclarationOnly && + !Var->isExternallyVisible() && + !(Var->isStaticDataMember() && Var->hasInit())) { + SourceLocation &old = SemaRef.UndefinedButUsed[Var->getCanonicalDecl()]; + if (old.isInvalid()) old = Loc; + } + QualType CaptureType, DeclRefType; + SemaRef.tryCaptureVariable(Var, Loc, Sema::TryCapture_Implicit, + /*EllipsisLoc*/ SourceLocation(), + /*BuildAndDiagnose*/ true, + CaptureType, DeclRefType, + FunctionScopeIndexToStopAt); + + Var->markUsed(SemaRef.Context); +} + +/// Return a DLL attribute from the declaration. +inline InheritableAttr *getDLLAttr(Decl *D) { + assert(!(D->hasAttr<DLLImportAttr>() && D->hasAttr<DLLExportAttr>()) && + "A declaration cannot be both dllimport and dllexport."); + if (auto *Import = D->getAttr<DLLImportAttr>()) + return Import; + if (auto *Export = D->getAttr<DLLExportAttr>()) + return Export; + return nullptr; +} + } #endif |