[cfe-commits] r76796 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseCXXInlineMethods.cpp lib/Parse/ParseDeclCXX.cpp test/SemaCXX/default2.cpp

Eli Friedman eli.friedman at gmail.com
Wed Jul 22 14:45:50 PDT 2009


Author: efriedma
Date: Wed Jul 22 16:45:50 2009
New Revision: 76796

URL: http://llvm.org/viewvc/llvm-project?rev=76796&view=rev
Log:
Fix the parsing of default arguments for inline member function 
definitions.

I'm not very familiar with this code, so please review.


Modified:
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/SemaCXX/default2.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=76796&r1=76795&r2=76796&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Jul 22 16:45:50 2009
@@ -1147,6 +1147,8 @@
   void ParseCXXClassMemberDeclaration(AccessSpecifier AS);
   void ParseConstructorInitializer(DeclPtrTy ConstructorDecl);
   MemInitResult ParseMemInitializer(DeclPtrTy ConstructorDecl);
+  void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo,
+                                       DeclPtrTy ThisDecl);
 
   //===--------------------------------------------------------------------===//
   // C++ 10: Derived classes [class.derived]

Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=76796&r1=76795&r2=76796&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Wed Jul 22 16:45:50 2009
@@ -29,6 +29,8 @@
 
   DeclPtrTy FnD = Actions.ActOnCXXMemberDeclarator(CurScope, AS, D, 0, 0);
 
+  HandleMemberFunctionDefaultArgs(D, FnD);
+
   // Consume the tokens and store them for later parsing.
 
   getCurrentClass().MethodDefs.push_back(LexedMethod(FnD));

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=76796&r1=76795&r2=76796&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Jul 22 16:45:50 2009
@@ -852,6 +852,39 @@
   }
 }
 
+void Parser::HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo,
+                                             DeclPtrTy ThisDecl) {
+  // We just declared a member function. If this member function
+  // has any default arguments, we'll need to parse them later.
+  LateParsedMethodDeclaration *LateMethod = 0;
+  DeclaratorChunk::FunctionTypeInfo &FTI 
+    = DeclaratorInfo.getTypeObject(0).Fun;
+  for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) {
+    if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) {
+      if (!LateMethod) {
+        // Push this method onto the stack of late-parsed method
+        // declarations.
+        getCurrentClass().MethodDecls.push_back(
+                                LateParsedMethodDeclaration(ThisDecl));
+        LateMethod = &getCurrentClass().MethodDecls.back();
+
+        // Add all of the parameters prior to this one (they don't
+        // have default arguments).
+        LateMethod->DefaultArgs.reserve(FTI.NumArgs);
+        for (unsigned I = 0; I < ParamIdx; ++I)
+          LateMethod->DefaultArgs.push_back(
+                    LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param));
+      }
+
+      // Add this parameter to the list of parameters (it or may
+      // not have a default argument).
+      LateMethod->DefaultArgs.push_back(
+        LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param,
+                                  FTI.ArgInfo[ParamIdx].DefaultArgTokens));
+    }
+  }
+}
+
 /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration.
 ///
 ///       member-declaration:
@@ -1047,35 +1080,7 @@
     if (DeclaratorInfo.isFunctionDeclarator() &&
         DeclaratorInfo.getDeclSpec().getStorageClassSpec() 
           != DeclSpec::SCS_typedef) {
-      // We just declared a member function. If this member function
-      // has any default arguments, we'll need to parse them later.
-      LateParsedMethodDeclaration *LateMethod = 0;
-      DeclaratorChunk::FunctionTypeInfo &FTI 
-        = DeclaratorInfo.getTypeObject(0).Fun;
-      for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) {
-        if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) {
-          if (!LateMethod) {
-            // Push this method onto the stack of late-parsed method
-            // declarations.
-            getCurrentClass().MethodDecls.push_back(
-                                   LateParsedMethodDeclaration(ThisDecl));
-            LateMethod = &getCurrentClass().MethodDecls.back();
-
-            // Add all of the parameters prior to this one (they don't
-            // have default arguments).
-            LateMethod->DefaultArgs.reserve(FTI.NumArgs);
-            for (unsigned I = 0; I < ParamIdx; ++I)
-              LateMethod->DefaultArgs.push_back(
-                        LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param));
-          }
-
-          // Add this parameter to the list of parameters (it or may
-          // not have a default argument).
-          LateMethod->DefaultArgs.push_back(
-            LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param,
-                                      FTI.ArgInfo[ParamIdx].DefaultArgTokens));
-        }
-      }
+      HandleMemberFunctionDefaultArgs(DeclaratorInfo, ThisDecl);
     }
 
     // If we don't have a comma, it is either the end of the list (a ';')

Modified: cfe/trunk/test/SemaCXX/default2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/default2.cpp?rev=76796&r1=76795&r2=76796&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/default2.cpp (original)
+++ cfe/trunk/test/SemaCXX/default2.cpp Wed Jul 22 16:45:50 2009
@@ -127,3 +127,9 @@
   static void g(int = f()); // expected-error{{use of default argument to function 'f' that is declared later in class 'C2'}}
   static int f(int = 10); // expected-note{{default argument declared here}}
 };
+
+// Make sure we actually parse the default argument for an inline definition
+class XX {
+  void A(int length = -1 ) {  } 
+  void B() { A(); }
+};





More information about the cfe-commits mailing list