[cfe-commits] r101119 - in /cfe/trunk/lib: Parse/ParseDecl.cpp Sema/SemaDecl.cpp

John McCall rjmccall at apple.com
Mon Apr 12 23:39:49 PDT 2010


Author: rjmccall
Date: Tue Apr 13 01:39:49 2010
New Revision: 101119

URL: http://llvm.org/viewvc/llvm-project?rev=101119&view=rev
Log:
Parse constructor names in friend declarations.  Part of the fix for
PR6207.


Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=101119&r1=101118&r2=101119&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Apr 13 01:39:49 2010
@@ -904,7 +904,9 @@
         // reinforced by the NAD status of core issue 635. 
         TemplateIdAnnotation *TemplateId
           = static_cast<TemplateIdAnnotation *>(Next.getAnnotationValue());
-        if (DSContext == DSC_top_level && TemplateId->Name &&
+        if ((DSContext == DSC_top_level ||
+             (DSContext == DSC_class && DS.isFriendSpecified())) &&
+            TemplateId->Name &&
             Actions.isCurrentClassName(*TemplateId->Name, CurScope, &SS)) {
           if (isConstructorDeclarator()) {
             // The user meant this to be an out-of-line constructor
@@ -949,7 +951,8 @@
 
       // If we're in a context where the identifier could be a class name,
       // check whether this is a constructor declaration.
-      if (DSContext == DSC_top_level &&
+      if ((DSContext == DSC_top_level ||
+           (DSContext == DSC_class && DS.isFriendSpecified())) &&
           Actions.isCurrentClassName(*Next.getIdentifierInfo(), CurScope, 
                                      &SS)) {
         if (isConstructorDeclarator())
@@ -2599,12 +2602,17 @@
         Tok.is(tok::annot_template_id) || Tok.is(tok::tilde)) {
       // We found something that indicates the start of an unqualified-id.
       // Parse that unqualified-id.
-      bool AllowConstructorName
-        = ((D.getCXXScopeSpec().isSet() && 
-            D.getContext() == Declarator::FileContext) ||
-           (!D.getCXXScopeSpec().isSet() &&
-            D.getContext() == Declarator::MemberContext)) &&
-        !D.getDeclSpec().hasTypeSpecifier();
+      bool AllowConstructorName;
+      if (D.getDeclSpec().hasTypeSpecifier())
+        AllowConstructorName = false;
+      else if (D.getCXXScopeSpec().isSet())
+        AllowConstructorName =
+          (D.getContext() == Declarator::FileContext ||
+           (D.getContext() == Declarator::MemberContext &&
+            D.getDeclSpec().isFriendSpecified()));
+      else
+        AllowConstructorName = (D.getContext() == Declarator::MemberContext);
+
       if (ParseUnqualifiedId(D.getCXXScopeSpec(), 
                              /*EnteringContext=*/true, 
                              /*AllowDestructorName=*/true, 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=101119&r1=101118&r2=101119&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Apr 13 01:39:49 2010
@@ -3188,6 +3188,10 @@
     if (CheckMemberSpecialization(NewFD, Previous))
       NewFD->setInvalidDecl();
   }
+
+  // Make sure this is set before checking the function declaration.
+  // We'll override the visibility type later.
+  if (isFriend) NewFD->setObjectOfFriendDecl(false);
     
   // Perform semantic checking on the function declaration.
   bool OverloadableAttrRequired = false; // FIXME: HACK!
@@ -3199,7 +3203,10 @@
          "previous declaration set still overloaded");
 
   if (isFriend && Redeclaration) {
-    AccessSpecifier Access = NewFD->getPreviousDeclaration()->getAccess();
+    AccessSpecifier Access = AS_public;
+    if (!NewFD->isInvalidDecl())
+      Access = NewFD->getPreviousDeclaration()->getAccess();
+
     if (FunctionTemplate) {
       FunctionTemplate->setObjectOfFriendDecl(true);
       FunctionTemplate->setAccess(Access);





More information about the cfe-commits mailing list