]> granicus.if.org Git - clang/commitdiff
If a function with a default argument is redefined and the new function also has...
authorAnders Carlsson <andersca@mac.com>
Tue, 10 Nov 2009 03:24:44 +0000 (03:24 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 10 Nov 2009 03:24:44 +0000 (03:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86659 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/FixIt/fixit.cpp

index dd1af0b64c6a571ec1815cdddc212e037a31b550..01fc0e9616e48474215d893382a414c372288cf9 100644 (file)
@@ -264,9 +264,18 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old) {
     ParmVarDecl *NewParam = New->getParamDecl(p);
 
     if (OldParam->hasDefaultArg() && NewParam->hasDefaultArg()) {
+      // FIXME: If the parameter doesn't have an identifier then the location
+      // points to the '=' which means that the fixit hint won't remove any
+      // extra spaces between the type and the '='.
+      SourceLocation Begin = NewParam->getLocation();
+      if (IdentifierInfo *II = NewParam->getIdentifier())
+        Begin = Begin.getFileLocWithOffset(II->getLength());
+        
       Diag(NewParam->getLocation(),
            diag::err_param_default_argument_redefinition)
-        << NewParam->getDefaultArgRange();
+        << NewParam->getDefaultArgRange()
+        << CodeModificationHint::CreateRemoval(SourceRange(Begin,
+                                                        NewParam->getLocEnd()));
       
       // Look for the function declaration where the default argument was
       // actually written, which may be a declaration prior to Old.
index ccddd959452b264348aa8e9c36590942ef24411e..9190297dc05fd4e6cf4e4b0f92b6ee3a52c59cbe 100644 (file)
@@ -27,3 +27,12 @@ public:
 struct CT<0> { }; // expected-error{{'template<>'}}
 
 template<> class CT<1> { }; // expected-error{{tag type}}
+
+// PR5444
+namespace PR5444 {
+  void foo(int x, int y = 0);
+  void foo(int x, int y = 0) { }
+
+  void foo(int  = 0);
+  void foo(int  = 0) { }
+}