diff --git a/clang/include/clang/Sema/SemaInternal.h b/clang/include/clang/Sema/SemaInternal.h index 563cc1998330..4ee10478e487 100644 --- a/clang/include/clang/Sema/SemaInternal.h +++ b/clang/include/clang/Sema/SemaInternal.h @@ -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(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. diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 0ffce40e1ea2..b7c681f08e2e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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 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(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(FTI.Params[i].Param); assert(Param->getDeclContext() != NewFD && "Was set before ?"); diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 217588a9c099..ef4f8dd4e6a7 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -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(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. diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index 7c4f60e51171..e6c714eb9111 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -898,10 +898,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, ExplicitResultType = FTI.hasTrailingReturnType(); - if (FTI.NumParams == 1 && !FTI.isVariadic && FTI.Params[0].Ident == 0 && - cast(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(FTI.Params[i].Param)); diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 0afbe01586d7..448c89071604 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2330,7 +2330,7 @@ static void checkQualifiedFunction(Sema &S, QualType T, << getFunctionQualifiersAsString(T->castAs()); } -/// 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) {