Index: test/SemaCXX/default1.cpp
===================================================================
--- test/SemaCXX/default1.cpp	(revision 152320)
+++ test/SemaCXX/default1.cpp	(working copy)
@@ -32,3 +32,13 @@
 
 void kk(Y = 17); // expected-error{{no viable conversion}} \
 // expected-note{{passing argument to parameter here}}
+
+int l () {
+  int m(int i, int j, int k = 3);
+  if (1)
+  {
+    int m(int i, int j = 2, int k = 4);
+    g(8);
+  }
+  return 0;
+}
Index: include/clang/Sema/Sema.h
===================================================================
--- include/clang/Sema/Sema.h	(revision 152320)
+++ include/clang/Sema/Sema.h	(working copy)
@@ -1392,13 +1392,15 @@
   bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
   void mergeDeclAttributes(Decl *New, Decl *Old, bool MergeDeprecation = true);
   void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls);
-  bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
-  bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
+  bool MergeFunctionDecl(FunctionDecl *New, Decl *Old, bool IsInSameCXXScope);
+  bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
+                                    bool IsInSameCXXScope);
   void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old);
   void MergeVarDecl(VarDecl *New, LookupResult &OldDecls);
   void MergeVarDeclTypes(VarDecl *New, VarDecl *Old);
   void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
-  bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
+  bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old,
+                            bool IsInSameCXXScope);
 
   // AssignmentAction - This is used by all the assignment diagnostic functions
   // to represent what is actually causing the operation
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp	(revision 152320)
+++ lib/Sema/SemaDeclCXX.cpp	(working copy)
@@ -372,7 +372,8 @@
 // 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,
+                                bool IsInSameCXXScope) {
   bool Invalid = false;
 
   // C++ [dcl.fct.default]p4:
@@ -397,8 +398,16 @@
     ParmVarDecl *OldParam = Old->getParamDecl(p);
     ParmVarDecl *NewParam = New->getParamDecl(p);
 
-    if (OldParam->hasDefaultArg() && NewParam->hasDefaultArg()) {
+    bool OldParamHasDfl = OldParam->hasDefaultArg();
+    bool NewParamHasDfl = NewParam->hasDefaultArg();
+    
+    if (!IsInSameCXXScope)
+      // 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 +452,7 @@
       
       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 +462,7 @@
                                       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(),
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp	(revision 152320)
+++ lib/Sema/SemaDecl.cpp	(working copy)
@@ -1720,7 +1720,7 @@
 /// merged with.
 ///
 /// Returns true if there was an error, false otherwise.
-bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) {
+bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD, bool IsInSameCXXScope) {
   // Verify the old decl was also a function.
   FunctionDecl *Old = 0;
   if (FunctionTemplateDecl *OldFunctionTemplate
@@ -1950,7 +1950,7 @@
     }
 
     if (OldQTypeForComparison == NewQType)
-      return MergeCompatibleFunctionDecls(New, Old);
+      return MergeCompatibleFunctionDecls(New, Old, IsInSameCXXScope);
 
     // Fall through for conflicting redeclarations and redefinitions.
   }
@@ -1995,7 +1995,7 @@
       New->setParams(Params);
     }
 
-    return MergeCompatibleFunctionDecls(New, Old);
+    return MergeCompatibleFunctionDecls(New, Old, IsInSameCXXScope);
   }
 
   // GNU C permits a K&R definition to follow a prototype declaration
@@ -2056,7 +2056,7 @@
       New->setType(Context.getFunctionType(MergedReturn, &ArgTypes[0],
                                            ArgTypes.size(),
                                            OldProto->getExtProtoInfo()));
-      return MergeCompatibleFunctionDecls(New, Old);
+      return MergeCompatibleFunctionDecls(New, Old, IsInSameCXXScope);
     }
 
     // Fall through to diagnose conflicting types.
@@ -2097,7 +2097,8 @@
 /// redeclaration of Old.
 ///
 /// \returns false
-bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old) {
+bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
+                                        bool IsInSameCXXScope) {
   // Merge the attributes
   mergeDeclAttributes(New, Old);
 
@@ -2118,7 +2119,7 @@
                                Context);
 
   if (getLangOptions().CPlusPlus)
-    return MergeCXXFunctionDecl(New, Old);
+    return MergeCXXFunctionDecl(New, Old, IsInSameCXXScope);
 
   return false;
 }
@@ -5694,7 +5695,11 @@
     if (Redeclaration) {
       // NewFD and OldDecl represent declarations that need to be
       // merged.
-      if (MergeFunctionDecl(NewFD, OldDecl)) {
+      bool IsInSameCXXScope = true;
+      if (getLangOptions().CPlusPlus && S)
+        IsInSameCXXScope = isDeclInScope(OldDecl, NewFD->getDeclContext(), S);
+
+      if (MergeFunctionDecl(NewFD, OldDecl, IsInSameCXXScope)) {
         NewFD->setInvalidDecl();
         return Redeclaration;
       }
