diff options
| author | James Molloy <james.molloy@arm.com> | 2012-03-13 08:55:35 +0000 |
|---|---|---|
| committer | James Molloy <james.molloy@arm.com> | 2012-03-13 08:55:35 +0000 |
| commit | e943003c097db4216d787ba07cec853994fd5620 (patch) | |
| tree | 7dc43b5fdbb9ef438532fe3275d9c2e5e1966924 /clang/lib/Sema/SemaDeclCXX.cpp | |
| parent | 5262ad2afa9ee73e2554128f3bfa5f29c5907907 (diff) | |
| download | bcm5719-llvm-e943003c097db4216d787ba07cec853994fd5620.tar.gz bcm5719-llvm-e943003c097db4216d787ba07cec853994fd5620.zip | |
Ensure that default arguments are handled correctly in sub scopes. For example:
void f () {
int g (int a, int b=4);
{
int g(int a, int b=5);
}
}
should compile.
llvm-svn: 152621
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index b6866d04e4a..79a5d4c98c5 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -372,7 +372,8 @@ void Sema::CheckExtraCXXDefaultArguments(Declarator &D) { // function, once we already know that they have the same // type. Subroutine of MergeFunctionDecl. Returns true if there was an // error, false otherwise. -bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old) { +bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, + Scope *S) { bool Invalid = false; // C++ [dcl.fct.default]p4: @@ -397,7 +398,16 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old) { ParmVarDecl *OldParam = Old->getParamDecl(p); ParmVarDecl *NewParam = New->getParamDecl(p); - if (OldParam->hasDefaultArg() && NewParam->hasDefaultArg()) { + bool OldParamHasDfl = OldParam->hasDefaultArg(); + bool NewParamHasDfl = NewParam->hasDefaultArg(); + + NamedDecl *ND = Old; + if (S && !isDeclInScope(ND, New->getDeclContext(), S)) + // Ignore default parameters of old decl if they are not in + // the same scope. + OldParamHasDfl = false; + + if (OldParamHasDfl && NewParamHasDfl) { unsigned DiagDefaultParamID = diag::err_param_default_argument_redefinition; @@ -443,7 +453,7 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old) { Diag(OldParam->getLocation(), diag::note_previous_definition) << OldParam->getDefaultArgRange(); - } else if (OldParam->hasDefaultArg()) { + } else if (OldParamHasDfl) { // Merge the old default argument into the new parameter. // It's important to use getInit() here; getDefaultArg() // strips off any top-level ExprWithCleanups. @@ -453,7 +463,7 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old) { OldParam->getUninstantiatedDefaultArg()); else NewParam->setDefaultArg(OldParam->getInit()); - } else if (NewParam->hasDefaultArg()) { + } else if (NewParamHasDfl) { if (New->getDescribedFunctionTemplate()) { // Paragraph 4, quoted above, only applies to non-template functions. Diag(NewParam->getLocation(), |

