[cfe-commits] r92143 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp

Douglas Gregor dgregor at apple.com
Thu Dec 24 12:56:25 PST 2009


Author: dgregor
Date: Thu Dec 24 14:56:24 2009
New Revision: 92143

URL: http://llvm.org/viewvc/llvm-project?rev=92143&view=rev
Log:
Egregious, disgusting workaround for PR5866. We need to rework how we
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.

Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=92143&r1=92142&r2=92143&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Dec 24 14:56:24 2009
@@ -1338,11 +1338,16 @@
   // 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 @@
     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;

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=92143&r1=92142&r2=92143&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Dec 24 14:56:24 2009
@@ -5380,6 +5380,9 @@
   FrD->setAccess(AS_public);
   CurContext->addDecl(FrD);
 
+  if (D.getName().getKind() == UnqualifiedId::IK_TemplateId)
+    FrD->setSpecialization(true);
+
   return DeclPtrTy::make(ND);
 }
 

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=92143&r1=92142&r2=92143&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Dec 24 14:56:24 2009
@@ -401,7 +401,10 @@
     // 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 @@
 ///   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.





More information about the cfe-commits mailing list