[cfe-commits] r86659 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/FixIt/fixit.cpp
Anders Carlsson
andersca at mac.com
Mon Nov 9 19:24:45 PST 2009
Author: andersca
Date: Mon Nov 9 21:24:44 2009
New Revision: 86659
URL: http://llvm.org/viewvc/llvm-project?rev=86659&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/FixIt/fixit.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=86659&r1=86658&r2=86659&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Nov 9 21:24:44 2009
@@ -264,9 +264,18 @@
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.
Modified: cfe/trunk/test/FixIt/fixit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=86659&r1=86658&r2=86659&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit.cpp (original)
+++ cfe/trunk/test/FixIt/fixit.cpp Mon Nov 9 21:24:44 2009
@@ -27,3 +27,12 @@
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) { }
+}
More information about the cfe-commits
mailing list