r227577 - Code cleanup

Nathan Sidwell nathan at acm.org
Fri Jan 30 06:22:11 PST 2015


Author: nathan
Date: Fri Jan 30 08:21:35 2015
New Revision: 227577

URL: http://llvm.org/viewvc/llvm-project?rev=227577&view=rev
Log:
Code cleanup
Parser::ParseLexedMethodDeclaration: Use local var for Param
Sema::MergeCXXFunctionDecls: Use hasInheritedDefaultArg

Modified:
    cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp

Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=227577&r1=227576&r2=227577&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Fri Jan 30 08:21:35 2015
@@ -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;

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=227577&r1=227576&r2=227577&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Jan 30 08:21:35 2015
@@ -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;
-        
+      for (auto Older = Old; OldParam->hasInheritedDefaultArg();) {
+        Older = Older->getPreviousDecl();
         OldParam = Older->getParamDecl(p);
-      }        
-      
+      }
+
       Diag(OldParam->getLocation(), diag::note_previous_definition)
         << OldParam->getDefaultArgRange();
     } else if (OldParamHasDfl) {

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp?rev=227577&r1=227576&r2=227577&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp Fri Jan 30 08:21:35 2015
@@ -6,6 +6,7 @@ void f0(int i, int j = 2, int k);
 void f0(int i, int j, int k);
 void f0(int i = 1, // expected-note{{previous definition}}
         int j, int k);
+void f0(int i, int j, int k);   // want 2 decls before next default arg
 void f0(int i, int j, int k);
 
 namespace N0 {





More information about the cfe-commits mailing list