]> granicus.if.org Git - clang/commitdiff
Egregious, disgusting workaround for PR5866. We need to rework how we
authorDouglas Gregor <dgregor@apple.com>
Thu, 24 Dec 2009 20:56:24 +0000 (20:56 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 24 Dec 2009 20:56:24 +0000 (20:56 +0000)
keep track of friends within templates, which will provide a real for
PR5866. For now, this makes sure we don't do something entirely stupid
with friends of specializations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92143 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclCXX.h
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp

index c1975505372b88ef1ee4387b07e313d26c0da5c2..02581c1241a4c4790959436ebc564569d60322f6 100644 (file)
@@ -1338,11 +1338,16 @@ private:
   // Location of the 'friend' specifier.
   SourceLocation FriendLoc;
 
+  // FIXME: Hack to keep track of whether this was a friend function
+  // template specialization.
+  bool WasSpecialization;
+
   FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend,
              SourceLocation FriendL)
     : Decl(Decl::Friend, DC, L),
       Friend(Friend),
-      FriendLoc(FriendL) {
+      FriendLoc(FriendL),
+      WasSpecialization(false) {
   }
 
 public:
@@ -1369,6 +1374,9 @@ public:
     return FriendLoc;
   }
 
+  bool wasSpecialization() const { return WasSpecialization; }
+  void setSpecialization(bool WS) { WasSpecialization = WS; }
+
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) {
     return D->getKind() == Decl::Friend;
index 2e4ee63ebdb5f0d1a9fb233f92f30e13d8550137..b70b0dccb75eeff546174c24805154b50f6b2c89 100644 (file)
@@ -5380,6 +5380,9 @@ Sema::ActOnFriendFunctionDecl(Scope *S,
   FrD->setAccess(AS_public);
   CurContext->addDecl(FrD);
 
+  if (D.getName().getKind() == UnqualifiedId::IK_TemplateId)
+    FrD->setSpecialization(true);
+
   return DeclPtrTy::make(ND);
 }
 
index 18a73250a529d0f768edf44052201eb34826c4cc..1ec91bd55ec36bcd017e9444db546d6e624b6a82 100644 (file)
@@ -401,7 +401,10 @@ Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) {
     // Hack to make this work almost well pending a rewrite.
     if (ND->getDeclContext()->isRecord())
       NewND = SemaRef.FindInstantiatedDecl(ND, TemplateArgs);
-    else
+    else if (D->wasSpecialization()) {
+      // Totally egregious hack to work around PR5866
+      return 0;
+    } else
       NewND = Visit(ND);
     if (!NewND) return 0;
 
@@ -687,7 +690,7 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
 ///   1) instantiating function templates
 ///   2) substituting friend declarations
 /// FIXME: preserve function definitions in case #2
-  Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D,
+Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D,
                                        TemplateParameterList *TemplateParams) {
   // Check whether there is already a function template specialization for
   // this declaration.