Add support for C++ default arguments, and rework Parse-Sema
interaction for function parameters, fixing PR2046.
Patch by Doug Gregor!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49369 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index cd99fc0..7e41bcc 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -509,6 +509,10 @@
// We know that the top-level of this declarator is a function.
DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun;
+ // Enter function-declaration scope, limiting any declarators to the
+ // function prototype scope, including parameter declarators.
+ EnterScope(Scope::DeclScope);
+
// Read all the argument declarations.
while (isDeclarationSpecifier()) {
SourceLocation DSStart = Tok.getLocation();
@@ -555,10 +559,10 @@
AttrList = ParseAttributes();
// Ask the actions module to compute the type for this declarator.
- Action::TypeResult TR =
- Actions.ActOnParamDeclaratorType(CurScope, ParmDeclarator);
+ Action::DeclTy *Param =
+ Actions.ActOnParamDeclarator(CurScope, ParmDeclarator);
- if (!TR.isInvalid &&
+ if (Param &&
// A missing identifier has already been diagnosed.
ParmDeclarator.getIdentifier()) {
@@ -575,12 +579,12 @@
if (FTI.ArgInfo[i].Ident == ParmDeclarator.getIdentifier()) {
// Reject redefinitions of parameters.
- if (FTI.ArgInfo[i].TypeInfo) {
+ if (FTI.ArgInfo[i].Param) {
Diag(ParmDeclarator.getIdentifierLoc(),
diag::err_param_redefinition,
ParmDeclarator.getIdentifier()->getName());
} else {
- FTI.ArgInfo[i].TypeInfo = TR.Val;
+ FTI.ArgInfo[i].Param = Param;
}
break;
}
@@ -611,6 +615,9 @@
}
}
+ // Leave prototype scope.
+ ExitScope();
+
// The actions module must verify that all arguments were declared.
}