From: Francois Pichet Date: Sun, 10 Apr 2011 04:58:30 +0000 (+0000) Subject: Refactor 129240 to merge the old default argument into the new parameter. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8cf9049185c72dc453ebb946d39420f3f78dec76;p=clang Refactor 129240 to merge the old default argument into the new parameter. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129242 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 9dbca64639..01ce75192a 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -288,11 +288,7 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old) { ParmVarDecl *NewParam = New->getParamDecl(p); if (OldParam->hasDefaultArg() && NewParam->hasDefaultArg()) { - // FIXME: If we knew where the '=' was, we could easily provide a fix-it - // hint here. Alternatively, we could walk the type-source information - // for NewParam to find the last source location in the type... but it - // isn't worth the effort right now. This is the kind of test case that - // is hard to get right: + unsigned DiagDefaultParamID = diag::err_param_default_argument_redefinition; @@ -302,11 +298,23 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old) { if (getLangOptions().Microsoft) { CXXMethodDecl* MD = dyn_cast(New); if (MD && MD->getParent()->getDescribedClassTemplate()) { + // Merge the old default argument into the new parameter. + NewParam->setHasInheritedDefaultArg(); + if (OldParam->hasUninstantiatedDefaultArg()) + NewParam->setUninstantiatedDefaultArg( + OldParam->getUninstantiatedDefaultArg()); + else + NewParam->setDefaultArg(OldParam->getInit()); DiagDefaultParamID = diag::war_param_default_argument_redefinition; Invalid = false; } } + // FIXME: If we knew where the '=' was, we could easily provide a fix-it + // hint here. Alternatively, we could walk the type-source information + // for NewParam to find the last source location in the type... but it + // isn't worth the effort right now. This is the kind of test case that + // is hard to get right: // int f(int); // void g(int (*fp)(int) = f); // void g(int (*fp)(int) = &f);