]> granicus.if.org Git - clang/commitdiff
Refactor 129240 to merge the old default argument into the new parameter.
authorFrancois Pichet <pichet2000@gmail.com>
Sun, 10 Apr 2011 04:58:30 +0000 (04:58 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Sun, 10 Apr 2011 04:58:30 +0000 (04:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129242 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp

index 9dbca64639fe789ddc42dc8fc9bbde7032b97d5f..01ce75192a38a8b9b18415483608f691a2776305 100644 (file)
@@ -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<CXXMethodDecl>(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);