diff options
author | Anders Carlsson <andersca@mac.com> | 2009-11-10 03:24:44 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-11-10 03:24:44 +0000 |
commit | ad26b7376b6fd71d14b9b893eaa1ba79e029c830 (patch) | |
tree | 8e7485756f2b9e070e2a7cd760cfe78b0ae2966b | |
parent | 8ac5a40ce52be72b3ad2a7aec689a0ee89b7fbcc (diff) |
If a function with a default argument is redefined and the new function also has a defualt argument then add a fixit hint that removes the default argument. Fixes PR5444.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86659 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 11 | ||||
-rw-r--r-- | test/FixIt/fixit.cpp | 9 |
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index dd1af0b64c..01fc0e9616 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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. diff --git a/test/FixIt/fixit.cpp b/test/FixIt/fixit.cpp index ccddd95945..9190297dc0 100644 --- a/test/FixIt/fixit.cpp +++ b/test/FixIt/fixit.cpp @@ -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) { } +} |