From d5e3416e8ef9c11dac11bfd4dc8dcab656782aed Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Wed, 28 Mar 2012 14:29:58 -0700 Subject: [PATCH] Fix bug in default argument handling introduced in 540fc6c2f3 --- decl.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/decl.cpp b/decl.cpp index c54abdb9..1a67e387 100644 --- a/decl.cpp +++ b/decl.cpp @@ -486,16 +486,18 @@ Declarator::GetType(const Type *base, DeclSpecs *ds) const { if (d->declarators.size()) { // Try to find an initializer expression. Declarator *decl = d->declarators[0]; - while (decl->child != NULL) { + while (decl != NULL) { if (decl->initExpr != NULL) { decl->initExpr = TypeCheck(decl->initExpr); decl->initExpr = Optimize(decl->initExpr); - if (decl->initExpr != NULL && - ((init = dynamic_cast(decl->initExpr)) == NULL) && - ((init = dynamic_cast(decl->initExpr)) == NULL)) { - Error(decl->initExpr->pos, "Default value for parameter " - "\"%s\" must be a compile-time constant.", - sym->name.c_str()); + if (decl->initExpr != NULL) { + init = dynamic_cast(decl->initExpr); + if (init == NULL) + init = dynamic_cast(decl->initExpr); + if (init == NULL) + Error(decl->initExpr->pos, "Default value for parameter " + "\"%s\" must be a compile-time constant.", + sym->name.c_str()); } break; } @@ -511,6 +513,7 @@ Declarator::GetType(const Type *base, DeclSpecs *ds) const { Error(pos, "No return type provided in function declaration."); return NULL; } + if (dynamic_cast(returnType) != NULL) { Error(pos, "Illegal to return function type from function."); return NULL;