Richard,
in working on 18432 I've another cleanup patch.
1) code in Parser::ParseLexedMethodDeclaration uses 'LM.DefaultArgs[I].Param' a
lot (and my fix for 18432 will add more). It seemed better to break that out
into a local var. It's probably very hard for the compiler to do that
localization itself, as it'd have to prove that LM.DefaultArgs[I].Param was not
mutated by any function call -- I'd put it in the 'impossible for practical
purposes' category.
2) Code in Sema::MergeCXXFunctionDecl looks to find the defining default arg in
order to issue a duplicate default diagnostic. However the current loop probes
backwards until it finds a param without a default -- and then uses the one just
previously found. However, it seems simpler to just check
hasInheritedDefaultArg and stop on the first param without that.
tested on x86-linux, ok?
nathan
Index: src/tools/clang/lib/Parse/ParseCXXInlineMethods.cpp
===================================================================
--- src/tools/clang/lib/Parse/ParseCXXInlineMethods.cpp (revision 227312)
+++ src/tools/clang/lib/Parse/ParseCXXInlineMethods.cpp (working copy)
@@ -306,9 +306,9 @@ void Parser::ParseLexedMethodDeclaration
ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope |
Scope::FunctionDeclarationScope | Scope::DeclScope);
for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) {
+ auto Param = LM.DefaultArgs[I].Param;
// Introduce the parameter into scope.
- Actions.ActOnDelayedCXXMethodParameter(getCurScope(),
- LM.DefaultArgs[I].Param);
+ Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param);
if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) {
// Mark the end of the default argument so that we know when to stop when
// we parse it later on.
@@ -318,7 +318,7 @@ void Parser::ParseLexedMethodDeclaration
DefArgEnd.setKind(tok::eof);
DefArgEnd.setLocation(LastDefaultArgToken.getLocation().getLocWithOffset(
LastDefaultArgToken.getLength()));
- DefArgEnd.setEofData(LM.DefaultArgs[I].Param);
+ DefArgEnd.setEofData(Param);
Toks->push_back(DefArgEnd);
// Parse the default argument from its saved token stream.
@@ -336,7 +336,7 @@ void Parser::ParseLexedMethodDeclaration
// used.
EnterExpressionEvaluationContext Eval(Actions,
Sema::PotentiallyEvaluatedIfUsed,
- LM.DefaultArgs[I].Param);
+ Param);
ExprResult DefArgResult;
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
@@ -346,11 +346,9 @@ void Parser::ParseLexedMethodDeclaration
DefArgResult = ParseAssignmentExpression();
DefArgResult = Actions.CorrectDelayedTyposInExpr(DefArgResult);
if (DefArgResult.isInvalid()) {
- Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param,
- EqualLoc);
+ Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
} else {
- if (Tok.isNot(tok::eof) ||
- Tok.getEofData() != LM.DefaultArgs[I].Param) {
+ if (Tok.isNot(tok::eof) || Tok.getEofData() != Param) {
// The last two tokens are the terminator and the saved value of
// Tok; the last token in the default argument is the one before
// those.
@@ -359,7 +357,7 @@ void Parser::ParseLexedMethodDeclaration
<< SourceRange(Tok.getLocation(),
(*Toks)[Toks->size() - 3].getLocation());
}
- Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc,
+ Actions.ActOnParamDefaultArgument(Param, EqualLoc,
DefArgResult.get());
}
@@ -368,7 +366,7 @@ void Parser::ParseLexedMethodDeclaration
while (Tok.isNot(tok::eof))
ConsumeAnyToken();
- if (Tok.is(tok::eof) && Tok.getEofData() == LM.DefaultArgs[I].Param)
+ if (Tok.is(tok::eof) && Tok.getEofData() == Param)
ConsumeAnyToken();
delete Toks;
Index: src/tools/clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- src/tools/clang/lib/Sema/SemaDeclCXX.cpp (revision 227312)
+++ src/tools/clang/lib/Sema/SemaDeclCXX.cpp (working copy)
@@ -509,14 +509,11 @@ bool Sema::MergeCXXFunctionDecl(Function
// Look for the function declaration where the default argument was
// actually written, which may be a declaration prior to Old.
- for (FunctionDecl *Older = Old->getPreviousDecl();
- Older; Older = Older->getPreviousDecl()) {
- if (!Older->getParamDecl(p)->hasDefaultArg())
- break;
-
+ while (OldParam->hasInheritedDefaultArg()) {
+ FunctionDecl *Older = Old->getPreviousDecl();
OldParam = Older->getParamDecl(p);
- }
-
+ }
+
Diag(OldParam->getLocation(), diag::note_previous_definition)
<< OldParam->getDefaultArgRange();
} else if (OldParamHasDfl) {
# svn diff src/tools/clang/tools/extra
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits