Consolidate single void paramter checking

Also correct argument/parameter terminology.

No change in functionality.

llvm-svn: 208498
This commit is contained in:
Alp Toker 2014-05-11 16:05:55 +00:00
parent 53156af57c
commit 4284c6e7a4
5 changed files with 17 additions and 19 deletions

View File

@ -25,6 +25,18 @@ inline PartialDiagnostic Sema::PDiag(unsigned DiagID) {
return PartialDiagnostic(DiagID, Context.getDiagAllocator());
}
inline bool
FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI) {
return FTI.NumParams == 1 && !FTI.isVariadic && FTI.Params[0].Ident == 0 &&
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.

View File

@ -2658,7 +2658,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
New->setType(NewQType);
New->setHasInheritedPrototype();
// Synthesize a parameter for each argument type.
// Synthesize parameters with the same types.
SmallVector<ParmVarDecl*, 16> Params;
for (const auto &ParamType : OldProto->param_types()) {
ParmVarDecl *Param = ParmVarDecl::Create(Context, New, SourceLocation(),
@ -6992,11 +6992,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
// single void argument.
// We let through "const void" here because Sema::GetTypeForDeclarator
// already checks for that case.
if (FTI.NumParams == 1 && !FTI.isVariadic && FTI.Params[0].Ident == 0 &&
FTI.Params[0].Param &&
cast<ParmVarDecl>(FTI.Params[0].Param)->getType()->isVoidType()) {
// Empty arg list, don't push any params.
} else if (FTI.NumParams > 0 && FTI.Params[0].Param != 0) {
if (FTIHasNonVoidParameters(FTI) && FTI.Params[0].Param) {
for (unsigned i = 0, e = FTI.NumParams; i != e; ++i) {
ParmVarDecl *Param = cast<ParmVarDecl>(FTI.Params[i].Param);
assert(Param->getDeclContext() != NewFD && "Was set before ?");

View File

@ -6252,13 +6252,6 @@ bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) {
return false;
}
static inline bool
FTIHasSingleVoidArgument(DeclaratorChunk::FunctionTypeInfo &FTI) {
return (FTI.NumParams == 1 && !FTI.isVariadic && FTI.Params[0].Ident == 0 &&
FTI.Params[0].Param &&
cast<ParmVarDecl>(FTI.Params[0].Param)->getType()->isVoidType());
}
/// CheckDestructorDeclarator - Called by ActOnDeclarator to check
/// the well-formednes of the destructor declarator @p D with type @p
/// R. If there are any errors in the declarator, this routine will
@ -6337,7 +6330,7 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D, QualType R,
}
// Make sure we don't have any parameters.
if (FTI.NumParams > 0 && !FTIHasSingleVoidArgument(FTI)) {
if (FTIHasNonVoidParameters(FTI)) {
Diag(D.getIdentifierLoc(), diag::err_destructor_with_params);
// Delete the parameters.

View File

@ -898,10 +898,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
ExplicitResultType = FTI.hasTrailingReturnType();
if (FTI.NumParams == 1 && !FTI.isVariadic && FTI.Params[0].Ident == 0 &&
cast<ParmVarDecl>(FTI.Params[0].Param)->getType()->isVoidType()) {
// Empty arg list, don't push any params.
} else {
if (FTIHasNonVoidParameters(FTI)) {
Params.reserve(FTI.NumParams);
for (unsigned i = 0, e = FTI.NumParams; i != e; ++i)
Params.push_back(cast<ParmVarDecl>(FTI.Params[i].Param));

View File

@ -2330,7 +2330,7 @@ static void checkQualifiedFunction(Sema &S, QualType T,
<< getFunctionQualifiersAsString(T->castAs<FunctionProtoType>());
}
/// Produce an approprioate diagnostic for an ambiguity between a function
/// Produce an appropriate diagnostic for an ambiguity between a function
/// declarator and a C++ direct-initializer.
static void warnAboutAmbiguousFunction(Sema &S, Declarator &D,
DeclaratorChunk &DeclType, QualType RT) {