r208498 - Consolidate single void paramter checking
Alp Toker
alp at nuanti.com
Sun May 11 09:05:56 PDT 2014
Author: alp
Date: Sun May 11 11:05:55 2014
New Revision: 208498
URL: http://llvm.org/viewvc/llvm-project?rev=208498&view=rev
Log:
Consolidate single void paramter checking
Also correct argument/parameter terminology.
No change in functionality.
Modified:
cfe/trunk/include/clang/Sema/SemaInternal.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/include/clang/Sema/SemaInternal.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/SemaInternal.h?rev=208498&r1=208497&r2=208498&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/SemaInternal.h (original)
+++ cfe/trunk/include/clang/Sema/SemaInternal.h Sun May 11 11:05:55 2014
@@ -25,6 +25,18 @@ inline PartialDiagnostic Sema::PDiag(uns
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.
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=208498&r1=208497&r2=208498&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun May 11 11:05:55 2014
@@ -2658,7 +2658,7 @@ bool Sema::MergeFunctionDecl(FunctionDec
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,
// 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 ?");
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=208498&r1=208497&r2=208498&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun May 11 11:05:55 2014
@@ -6252,13 +6252,6 @@ bool Sema::CheckDestructor(CXXDestructor
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
}
// 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.
Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=208498&r1=208497&r2=208498&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Sun May 11 11:05:55 2014
@@ -898,10 +898,7 @@ void Sema::ActOnStartOfLambdaDefinition(
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));
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=208498&r1=208497&r2=208498&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sun May 11 11:05:55 2014
@@ -2330,7 +2330,7 @@ static void checkQualifiedFunction(Sema
<< 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) {
More information about the cfe-commits
mailing list