]> granicus.if.org Git - clang/commitdiff
PR4794: Make instantiating friend class decls not crash.
authorEli Friedman <eli.friedman@gmail.com>
Thu, 27 Aug 2009 18:38:56 +0000 (18:38 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 27 Aug 2009 18:38:56 +0000 (18:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80272 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-friend-class.cpp [new file with mode: 0644]

index 045c12aab5485a3f237bcdf7d61b80eb83bd8680..1e1b6e8b3e912a0f9a2078c993c616f229064418 100644 (file)
@@ -4311,7 +4311,10 @@ CreateNewDecl:
   New->setLexicalDeclContext(CurContext);
 
   // Set the access specifier.
-  if (!Invalid && TUK != TUK_Friend)
+  // FIXME: This used to be skipped for friend tag decls, but it led to an
+  // assertion in Decl::CheckAccessDeclContext(); once various issues with
+  // friend class decls are sorted out, this should be revisited.
+  if (!Invalid)
     SetMemberAccessSpecifier(New, PrevDecl, AS);
 
   if (TUK == TUK_Definition)
index 42fc1f8165d580d929a41ce0895e7a7b8f287f56..a79742b5b1775e061e0d8781479a5b5fc66d1bfe 100644 (file)
@@ -265,6 +265,8 @@ Decl *TemplateDeclInstantiator::VisitFriendClassDecl(FriendClassDecl *D) {
   FriendClassDecl *NewD =
     FriendClassDecl::Create(SemaRef.Context, DC, D->getLocation(), T,
                             D->getFriendLoc());
+  NewD->setLexicalDeclContext(Owner);
+
   Owner->addDecl(NewD);
   return NewD;
 }
diff --git a/test/SemaTemplate/instantiate-friend-class.cpp b/test/SemaTemplate/instantiate-friend-class.cpp
new file mode 100644 (file)
index 0000000..004bf1b
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+template <class T> class X
+{
+  friend class Y;
+};
+X<int> y;
+